forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestHelper.cpp
More file actions
38 lines (32 loc) · 1.87 KB
/
Copy pathRestHelper.cpp
File metadata and controls
38 lines (32 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "TestCommon.h"
#include "Rest/Schema/RestHelper.h"
#include "cpprest/json.h"
using namespace AppInstaller::Repository::Rest::Schema;
TEST_CASE("ValidateAndGetRestAPIBaseUri", "[RestSource]")
{
REQUIRE(RestHelper::GetRestAPIBaseUri("https://restsource.azurewebsites.net/api/ ") == L"https://restsource.azurewebsites.net/api");
REQUIRE(RestHelper::GetRestAPIBaseUri("http://rest_sourc e.azurewebsites.net/api") == L"http://rest_sourc%20e.azurewebsites.net/api");
REQUIRE(RestHelper::GetRestAPIBaseUri("http://restsource.azurewebsites.net/v1.0/%v1") == L"http://restsource.azurewebsites.net/v1.0/%25v1");
}
TEST_CASE("IsValidUri", "[RestSource]")
{
REQUIRE(RestHelper::IsValidUri(L"http://rest%20source.azurewebsites.net/api"));
REQUIRE(!RestHelper::IsValidUri(L"http://rest source.azurewebsites.net/api"));
}
TEST_CASE("AppendPathToUri", "[RestSource]")
{
REQUIRE(RestHelper::AppendPathToUri(L"http://restsource.azurewebsites.net/api/", L"/path") == L"http://restsource.azurewebsites.net/api/path");
REQUIRE(RestHelper::AppendPathToUri(L"http://restsource.azurewebsites.net/api/", L"/pat h") == L"http://restsource.azurewebsites.net/api/pat%20%20h");
REQUIRE(RestHelper::AppendPathToUri(L"http://restsource.azurewebsites.net/api/", L"/path+version") == L"http://restsource.azurewebsites.net/api/path%2Bversion");
}
TEST_CASE("AppendQueryParamsToUri", "[RestSource]")
{
utility::string_t url = L"http://restsource.azurewebsites.net/api";
std::map<std::string_view, std::string> queryParams;
queryParams.emplace("Version", "1.0 .0");
queryParams.emplace("Channel", "beta+");
REQUIRE(RestHelper::AppendQueryParamsToUri(url, queryParams) == L"http://restsource.azurewebsites.net/api?Channel=beta%2B&Version=1.0%20.0");
}