Skip to content

Commit

Permalink
Use existing httpclienthelper
Browse files Browse the repository at this point in the history
  • Loading branch information
florelis committed Feb 27, 2024
1 parent 17264b7 commit 8a11d7c
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 67 deletions.
14 changes: 7 additions & 7 deletions src/AppInstallerCLITests/CustomHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ TEST_CASE("RestClient_CustomHeader", "[RestSource][CustomHeader]")
std::optional<std::string> customHeader = "Testing custom header";
auto header = std::make_pair<>(CustomHeaderName, JSON::GetUtilityString(customHeader.value()));
HttpClientHelper helper{ GetHeaderVerificationHandler(web::http::status_codes::OK, sample, header) };
RestClient client = RestClient::Create(utility::conversions::to_utf8string("https://restsource.com/api"), customHeader, {}, {}, std::move(helper));
RestClient client = RestClient::Create(utility::conversions::to_utf8string("https://restsource.com/api"), customHeader, {}, std::move(helper), {});
REQUIRE(client.GetSourceIdentifier() == "Source123");
}

Expand All @@ -66,7 +66,7 @@ TEST_CASE("RestSourceSearch_CustomHeader", "[RestSource][CustomHeader]")
std::unordered_map<utility::string_t, utility::string_t> headers;
headers.emplace(CustomHeaderName, customHeader);

V1_1::Interface v1_1{ "https://restsource.com/api", {}, headers, std::move(helper) };
V1_1::Interface v1_1{ "https://restsource.com/api", std::move(helper) , {}, headers};
Schema::IRestClient::SearchResult searchResponse = v1_1.Search({});
REQUIRE(searchResponse.Matches.size() == 1);
Schema::IRestClient::Package package = searchResponse.Matches.at(0);
Expand All @@ -80,7 +80,7 @@ TEST_CASE("RestSourceSearch_WhitespaceCustomHeader", "[RestSource][CustomHeader]
std::unordered_map<utility::string_t, utility::string_t> headers;
headers.emplace(CustomHeaderName, customHeader);

V1_1::Interface v1_1{ "https://restsource.com/api", {}, headers, std::move(helper) };
V1_1::Interface v1_1{ "https://restsource.com/api", std::move(helper), {}, headers };
Schema::IRestClient::SearchResult searchResponse = v1_1.Search({});
REQUIRE(searchResponse.Matches.size() == 1);
}
Expand All @@ -93,7 +93,7 @@ TEST_CASE("RestSourceSearch_NoCustomHeader", "[RestSource][CustomHeader]")
std::unordered_map<utility::string_t, utility::string_t> headers;
headers.emplace(CustomHeaderName, customHeader);

V1_1::Interface v1_1{ "https://restsource.com/api", {}, {}, std::move(helper) };
V1_1::Interface v1_1{ "https://restsource.com/api", std::move(helper), {}, {} };
REQUIRE_THROWS_HR(v1_1.Search({}), APPINSTALLER_CLI_ERROR_RESTSOURCE_INTERNAL_ERROR);
}

Expand All @@ -103,7 +103,7 @@ TEST_CASE("RestSourceSearch_CustomHeaderExceedingSize", "[RestSource][CustomHead
auto header = std::make_pair<>(CustomHeaderName, JSON::GetUtilityString(customHeader));
HttpClientHelper helper{ GetHeaderVerificationHandler(web::http::status_codes::OK, sampleSearchResponse, header) };

REQUIRE_THROWS_HR(RestClient::Create(utility::conversions::to_utf8string("https://restsource.com/api"), customHeader, {}, {}, std::move(helper)),
REQUIRE_THROWS_HR(RestClient::Create(utility::conversions::to_utf8string("https://restsource.com/api"), customHeader, {}, std::move(helper), {}),
APPINSTALLER_CLI_ERROR_CUSTOMHEADER_EXCEEDS_MAXLENGTH);
}

Expand All @@ -121,7 +121,7 @@ TEST_CASE("RestClient_CustomUserAgentHeader", "[RestSource][CustomHeader]")
std::string testCaller = "TestCaller";
auto header = std::make_pair<>(web::http::header_names::user_agent, JSON::GetUtilityString(Runtime::GetUserAgent(testCaller)));
HttpClientHelper helper{ GetHeaderVerificationHandler(web::http::status_codes::OK, sample, header) };
RestClient client = RestClient::Create(utility::conversions::to_utf8string("https://restsource.com/api"), {}, testCaller, {}, std::move(helper));
RestClient client = RestClient::Create(utility::conversions::to_utf8string("https://restsource.com/api"), {}, testCaller, std::move(helper), {});
REQUIRE(client.GetSourceIdentifier() == "Source123");
}

Expand All @@ -138,6 +138,6 @@ TEST_CASE("RestClient_DefaultUserAgentHeader", "[RestSource][CustomHeader]")

auto header = std::make_pair<>(web::http::header_names::user_agent, JSON::GetUtilityString(Runtime::GetDefaultUserAgent()));
HttpClientHelper helper{ GetHeaderVerificationHandler(web::http::status_codes::OK, sample, header) };
RestClient client = RestClient::Create(utility::conversions::to_utf8string("https://restsource.com/api"), {}, {}, {}, std::move(helper));
RestClient client = RestClient::Create(utility::conversions::to_utf8string("https://restsource.com/api"), {}, {}, std::move(helper), {});
REQUIRE(client.GetSourceIdentifier() == "Source123");
}
20 changes: 10 additions & 10 deletions src/AppInstallerCLITests/RestClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ TEST_CASE("GetSupportedInterface", "[RestSource]")
IRestClient::Information info{ "TestId", { "1.0.0" } };

Version version{ "1.0.0" };
REQUIRE(RestClient::GetSupportedInterface(TestRestUri, {}, info, {}, version)->GetVersion() == version);
REQUIRE(RestClient::GetSupportedInterface(TestRestUri, {}, info, {}, version, {})->GetVersion() == version);

// Update this test to next version so that we don't forget to add to supported versions before rest e2e tests are available.
Version invalid{ "1.8.0" };
REQUIRE_THROWS_HR(RestClient::GetSupportedInterface(TestRestUri, {}, info, {}, invalid), APPINSTALLER_CLI_ERROR_RESTSOURCE_INVALID_VERSION);
REQUIRE_THROWS_HR(RestClient::GetSupportedInterface(TestRestUri, {}, info, {}, invalid, {}), APPINSTALLER_CLI_ERROR_RESTSOURCE_INVALID_VERSION);

Authentication::AuthenticationArguments authArgs;
authArgs.Mode = Authentication::AuthenticationMode::Silent;
Expand All @@ -60,12 +60,12 @@ TEST_CASE("GetSupportedInterface", "[RestSource]")
// GetSupportedInterface throws on unknown authentication type.
IRestClient::Information infoWithUnknownAuthenticationType{ "TestId", { "1.7.0" } };
infoWithUnknownAuthenticationType.Authentication.Type = Authentication::AuthenticationType::Unknown;
REQUIRE_THROWS_HR(RestClient::GetSupportedInterface(TestRestUri, {}, infoWithUnknownAuthenticationType, authArgs, version_1_7), APPINSTALLER_CLI_ERROR_AUTHENTICATION_TYPE_NOT_SUPPORTED);
REQUIRE_THROWS_HR(RestClient::GetSupportedInterface(TestRestUri, {}, infoWithUnknownAuthenticationType, authArgs, version_1_7, {}), APPINSTALLER_CLI_ERROR_AUTHENTICATION_TYPE_NOT_SUPPORTED);

// GetSupportedInterface throws on invalid authentication info.
IRestClient::Information infoWithInvalidAuthenticationInfo{ "TestId", { "1.7.0" } };
infoWithInvalidAuthenticationInfo.Authentication.Type = Authentication::AuthenticationType::MicrosoftEntraId;
REQUIRE_THROWS_HR(RestClient::GetSupportedInterface(TestRestUri, {}, infoWithInvalidAuthenticationInfo, authArgs, version_1_7), APPINSTALLER_CLI_ERROR_INVALID_AUTHENTICATION_INFO);
REQUIRE_THROWS_HR(RestClient::GetSupportedInterface(TestRestUri, {}, infoWithInvalidAuthenticationInfo, authArgs, version_1_7, {}), APPINSTALLER_CLI_ERROR_INVALID_AUTHENTICATION_INFO);
}

TEST_CASE("GetInformation_Success", "[RestSource]")
Expand Down Expand Up @@ -277,7 +277,7 @@ TEST_CASE("RestClientCreate_UnsupportedVersion", "[RestSource]")
}})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, sample) };
REQUIRE_THROWS_HR(RestClient::Create("https://restsource.com/api", {}, {}, {}, std::move(helper)), APPINSTALLER_CLI_ERROR_UNSUPPORTED_RESTSOURCE);
REQUIRE_THROWS_HR(RestClient::Create("https://restsource.com/api", {}, {}, std::move(helper)), APPINSTALLER_CLI_ERROR_UNSUPPORTED_RESTSOURCE);
}

TEST_CASE("RestClientCreate_UnsupportedAuthenticationMethod", "[RestSource]")
Expand All @@ -297,7 +297,7 @@ TEST_CASE("RestClientCreate_UnsupportedAuthenticationMethod", "[RestSource]")
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, sample) };
Authentication::AuthenticationArguments authArgs;
authArgs.Mode = Authentication::AuthenticationMode::Silent;
REQUIRE_THROWS_HR(RestClient::Create("https://restsource.com/api", {}, {}, std::move(authArgs), std::move(helper)), APPINSTALLER_CLI_ERROR_AUTHENTICATION_TYPE_NOT_SUPPORTED);
REQUIRE_THROWS_HR(RestClient::Create("https://restsource.com/api", {}, {}, std::move(helper), std::move(authArgs)), APPINSTALLER_CLI_ERROR_AUTHENTICATION_TYPE_NOT_SUPPORTED);
}

TEST_CASE("RestClientCreate_InvalidAuthenticationArguments", "[RestSource]")
Expand All @@ -320,7 +320,7 @@ TEST_CASE("RestClientCreate_InvalidAuthenticationArguments", "[RestSource]")
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, sample) };
Authentication::AuthenticationArguments authArgs;
authArgs.Mode = Authentication::AuthenticationMode::Unknown;
REQUIRE_THROWS_HR(RestClient::Create("https://restsource.com/api", {}, {}, std::move(authArgs), std::move(helper)), E_UNEXPECTED);
REQUIRE_THROWS_HR(RestClient::Create("https://restsource.com/api", {}, {}, std::move(helper), std::move(authArgs)), E_UNEXPECTED);
}

TEST_CASE("RestClientCreate_1.0_Success", "[RestSource]")
Expand All @@ -335,7 +335,7 @@ TEST_CASE("RestClientCreate_1.0_Success", "[RestSource]")
}})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, sample) };
RestClient client = RestClient::Create(TestRestUri, {}, {}, {}, std::move(helper));
RestClient client = RestClient::Create(TestRestUri, {}, {}, std::move(helper), {});
REQUIRE(client.GetSourceIdentifier() == "Source123");
}

Expand Down Expand Up @@ -372,7 +372,7 @@ TEST_CASE("RestClientCreate_1.1_Success", "[RestSource]")
}})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, sample) };
RestClient client = RestClient::Create(TestRestUri, {}, {}, {}, std::move(helper));
RestClient client = RestClient::Create(TestRestUri, {}, {}, std::move(helper));
REQUIRE(client.GetSourceIdentifier() == "Source123");
auto information = client.GetSourceInformation();
REQUIRE(information.SourceAgreementsIdentifier == "agreementV1");
Expand Down Expand Up @@ -438,7 +438,7 @@ TEST_CASE("RestClientCreate_1.7_Success", "[RestSource]")
Authentication::AuthenticationArguments authArgs;
authArgs.Mode = Authentication::AuthenticationMode::Silent;
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, sample) };
RestClient client = RestClient::Create(TestRestUri, {}, {}, std::move(authArgs), std::move(helper));
RestClient client = RestClient::Create(TestRestUri, {}, {}, std::move(helper), std::move(authArgs));
REQUIRE(client.GetSourceIdentifier() == "Source123");
auto information = client.GetSourceInformation();
REQUIRE(information.SourceAgreementsIdentifier == "agreementV1");
Expand Down
20 changes: 10 additions & 10 deletions src/AppInstallerCLITests/RestInterface_1_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ TEST_CASE("Search_BadResponse_UnsupportedPackageMatchFields", "[RestSource][Inte
})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_1{ TestRestUriString, GetTestSourceInformation(), {}, std::move(helper) };
Interface v1_1{ TestRestUriString, std::move(helper), GetTestSourceInformation(), {} };
AppInstaller::Repository::SearchRequest request;
PackageMatchFilter filter{ PackageMatchField::Name, MatchType::Exact, "Foo" };
request.Filters.emplace_back(std::move(filter));
Expand All @@ -326,7 +326,7 @@ TEST_CASE("Search_BadResponse_RequiredPackageMatchFields", "[RestSource][Interfa
})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_1{ TestRestUriString, GetTestSourceInformation(), {}, std::move(helper) };
Interface v1_1{ TestRestUriString, std::move(helper), GetTestSourceInformation(), {} };
AppInstaller::Repository::SearchRequest request;
PackageMatchFilter filter{ PackageMatchField::Name, MatchType::Exact, "Foo" };
request.Filters.emplace_back(std::move(filter));
Expand All @@ -342,7 +342,7 @@ TEST_CASE("GetManifests_BadResponse_UnsupportedQueryParameters", "[RestSource][I
})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_1{ TestRestUriString, GetTestSourceInformation(), {}, std::move(helper) };
Interface v1_1{ TestRestUriString, std::move(helper), GetTestSourceInformation(), {} };
REQUIRE_THROWS_HR(v1_1.GetManifests("Foo"), APPINSTALLER_CLI_ERROR_UNSUPPORTED_SOURCE_REQUEST);
}

Expand All @@ -355,7 +355,7 @@ TEST_CASE("GetManifests_BadResponse_RequiredQueryParameters", "[RestSource][Inte
})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_1{ TestRestUriString, GetTestSourceInformation(), {}, std::move(helper) };
Interface v1_1{ TestRestUriString, std::move(helper), GetTestSourceInformation(), {} };
REQUIRE_THROWS_HR(v1_1.GetManifests("Foo"), APPINSTALLER_CLI_ERROR_UNSUPPORTED_SOURCE_REQUEST);
}

Expand All @@ -375,7 +375,7 @@ TEST_CASE("Search_BadRequest_UnsupportedPackageMatchFields", "[RestSource][Inter
})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_1{ TestRestUriString, GetTestSourceInformation(), {}, std::move(helper) };
Interface v1_1{ TestRestUriString, std::move(helper), GetTestSourceInformation(), {} };
AppInstaller::Repository::SearchRequest request;
PackageMatchFilter filter{ PackageMatchField::Moniker, MatchType::Exact, "Foo" };
request.Filters.emplace_back(std::move(filter));
Expand All @@ -398,7 +398,7 @@ TEST_CASE("Search_GoodRequest_OnlyMarketRequired", "[RestSource][Interface_1_1]"
})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_1{ TestRestUriString, GetTestSourceInformation(), {}, std::move(helper) };
Interface v1_1{ TestRestUriString, std::move(helper), GetTestSourceInformation(), {} };
AppInstaller::Repository::SearchRequest request;
PackageMatchFilter filter{ PackageMatchField::Name, MatchType::Exact, "Foo" };
request.Filters.emplace_back(std::move(filter));
Expand Down Expand Up @@ -443,7 +443,7 @@ TEST_CASE("GetManifests_BadRequest_UnsupportedQueryParameters", "[RestSource][In
})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_1{ TestRestUriString, GetTestSourceInformation(), {}, std::move(helper) };
Interface v1_1{ TestRestUriString, std::move(helper), GetTestSourceInformation(), {} };
REQUIRE_THROWS_HR(v1_1.GetManifestByVersion("Foo", "1.0", "beta"), APPINSTALLER_CLI_ERROR_UNSUPPORTED_SOURCE_REQUEST);
}

Expand Down Expand Up @@ -479,7 +479,7 @@ TEST_CASE("GetManifests_GoodRequest_OnlyMarketRequired", "[RestSource][Interface
IRestClient::Information info = GetTestSourceInformation();
info.UnsupportedQueryParameters.clear();
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_1{ TestRestUriString, info, {}, std::move(helper) };
Interface v1_1{ TestRestUriString, std::move(helper), info, {} };
auto manifestResult = v1_1.GetManifestByVersion("Foo", "5.0.0", "");
REQUIRE(manifestResult.has_value());
const Manifest& manifest = manifestResult.value();
Expand Down Expand Up @@ -526,7 +526,7 @@ TEST_CASE("GetManifests_GoodResponse_MSStoreType", "[RestSource][Interface_1_1]"
})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(msstoreInstallerResponse)) };
Interface v1_1{ TestRestUriString, GetTestSourceInformation(), {}, std::move(helper) };
Interface v1_1{ TestRestUriString, std::move(helper), GetTestSourceInformation(), {} };
std::vector<Manifest> manifests = v1_1.GetManifests("Foo.Bar");
REQUIRE(manifests.size() == 1);

Expand All @@ -542,7 +542,7 @@ TEST_CASE("GetManifests_GoodResponse_V1_1", "[RestSource][Interface_1_1]")
GoodManifest_AllFields sampleManifest;
utility::string_t sample = sampleManifest.GetSampleManifest_AllFields();
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_1{ TestRestUriString, {}, {}, std::move(helper) };
Interface v1_1{ TestRestUriString, std::move(helper), {} };
std::vector<Manifest> manifests = v1_1.GetManifests("Foo.Bar");
REQUIRE(manifests.size() == 1);

Expand Down
4 changes: 2 additions & 2 deletions src/AppInstallerCLITests/RestInterface_1_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ TEST_CASE("GetManifests_GoodResponse_V1_4", "[RestSource][Interface_1_4]")
GoodManifest_AllFields sampleManifest;
utility::string_t sample = sampleManifest.GetSampleManifest_AllFields();
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_4{ TestRestUriString, {}, {}, std::move(helper) };
Interface v1_4{ TestRestUriString, std::move(helper), {} };
std::vector<Manifest> manifests = v1_4.GetManifests("Foo.Bar");
REQUIRE(manifests.size() == 1);

Expand Down Expand Up @@ -404,7 +404,7 @@ TEST_CASE("Search_GoodResponse_V1_4", "[RestSource][Interface_1_4]")
})delimiter");

HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_4{ TestRestUriString, {}, {}, std::move(helper) };
Interface v1_4{ TestRestUriString, std::move(helper), {} };
Schema::IRestClient::SearchResult searchResponse = v1_4.Search({});
REQUIRE(searchResponse.Matches.size() == 1);
Schema::IRestClient::Package package = searchResponse.Matches.at(0);
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLITests/RestInterface_1_5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ TEST_CASE("GetManifests_GoodResponse_V1_5", "[RestSource][Interface_1_5]")
GoodManifest_AllFields sampleManifest;
utility::string_t sample = sampleManifest.GetSampleManifest_AllFields();
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_5{ TestRestUriString, {}, {}, std::move(helper) };
Interface v1_5{ TestRestUriString, std::move(helper), {} };
std::vector<Manifest> manifests = v1_5.GetManifests("Foo.Bar");
REQUIRE(manifests.size() == 1);

Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLITests/RestInterface_1_6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ TEST_CASE("GetManifests_GoodResponse_V1_6", "[RestSource][Interface_1_6]")
GoodManifest_AllFields sampleManifest;
utility::string_t sample = sampleManifest.GetSampleManifest_AllFields();
HttpClientHelper helper{ GetTestRestRequestHandler(web::http::status_codes::OK, std::move(sample)) };
Interface v1_6{ TestRestUriString, {}, {}, std::move(helper) };
Interface v1_6{ TestRestUriString, std::move(helper), {} };
std::vector<Manifest> manifests = v1_6.GetManifests("Foo.Bar");
REQUIRE(manifests.size() == 1);

Expand Down
Loading

0 comments on commit 8a11d7c

Please sign in to comment.