protected virtual void EnsureEveryRequestHasCorrectHeaders() { server.ShouldHaveMadeACall() .WithHeader("User-Agent", PinataClient.UserAgent) .WithHeader(PinataApiKey) .WithHeader(PinataSecretApiKey); }
public async void PostAsync_MakesCorrectRequest() { var mockTokenGenerator = Substitute.For <IJwtTokenGenerator>(); mockTokenGenerator.GetToken(Scope.PatientWrite).Returns("token"); var mockRequestBody = "{\"hello\" : \"hello\"}"; _httpTest.RespondWith("{\"aha!\" : \"aha!\"}"); var sut = new AddAppointmentHttpClientWrapper(mockTokenGenerator); var result = await sut.PostAsync(mockRequestBody); foreach (var call in this._httpTest.CallLog) { _output.WriteLine(call.ToString()); } _httpTest.ShouldHaveMadeACall(); _httpTest.ShouldHaveCalled(_expectedUri) .WithRequestBody("{\"hello\" : \"hello\"}") .WithHeader("Ssp-TraceID", "09a01679-2564-0fb4-5129-aecc81ea2706") .WithHeader("Ssp-From", "200000000359") .WithHeader("Ssp-To", "918999198993") .WithHeader("Ssp-InteractionID", "urn:nhs:names:services:gpconnect:fhir:rest:create:appointment-1") .WithHeader("Content-Type", "application/fhir+json") .WithHeader("accept", "application/fhir+json") .WithOAuthBearerToken("token") .Times(1); result.Should().BeEquivalentTo("{\"aha!\" : \"aha!\"}"); }
public async void PrtgMonitoring_SendStringSuccessGetRequest_SendExpectedData() { // Fixture setup const string expectedUri = "http://mscmonitor01:5050/qp.articlescheduler.mscdev02?Content=%0D%0A%3Cprtg%3E%0D%0A%20%20%20%20%3Ctext%3Etest%20success%20message%3C%2Ftext%3E%0D%0A%20%20%20%20%3Cresult%3E%3Cchannel%3EMyChannel%3C%2Fchannel%3E%3Cvalue%3E17%3C%2Fvalue%3E%3C%2Fresult%3E%0D%0A%20%20%20%20%3Cresult%3E%3Cchannel%3EAnotherChannel%3C%2Fchannel%3E%3Cvalue%3E31%3C%2Fvalue%3E%3C%2Fresult%3E%0D%0A%3C%2Fprtg%3E"; var sut = _fixture.Create <PrtgMonitoringService>(); // Exercise system await sut.SendStringGetRequest(SuccessRequestData); // Verify outcome _httpTest .ShouldHaveMadeACall() .WithVerb(HttpMethod.Get) .WithQueryParamValue("Content", SuccessRequestData) .With(ctx => string.Equals(ctx.Request.RequestUri.AbsoluteUri, expectedUri)); }
void EnsureEveryRequestHasCorrectHeaders() { server.ShouldHaveMadeACall() .WithHeader(HeaderNames.Version, CommerceApi.ApiVersionDate) .WithHeader(HeaderNames.ApiKey, apiKey) .WithHeader("User-Agent", CommerceApi.UserAgent); }
public async Task can_setup_multiple_responses() { HttpTest .RespondWith("one") .RespondWith("two") .RespondWith("three"); HttpTest.ShouldNotHaveMadeACall(); await "http://www.api.com/1".GetAsync(); await "http://www.api.com/2".GetAsync(); await "http://www.api.com/3".GetAsync(); var calls = HttpTest.CallLog; Assert.AreEqual(3, calls.Count); Assert.AreEqual("one", await calls[0].Response.GetStringAsync()); Assert.AreEqual("two", await calls[1].Response.GetStringAsync()); Assert.AreEqual("three", await calls[2].Response.GetStringAsync()); HttpTest.ShouldHaveMadeACall(); HttpTest.ShouldHaveCalled("http://www.api.com/*").WithVerb(HttpMethod.Get).Times(3); HttpTest.ShouldNotHaveCalled("http://www.otherapi.com/*"); // #323 make sure it's a full string match and not a "contains" Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveCalled("http://www.api.com/")); HttpTest.ShouldNotHaveCalled("http://www.api.com/"); }
[Test] // #331 public async Task can_fake_content_headers() { HttpTest.RespondWith("<xml></xml>", 200, new { Content_Type = "text/xml" }); await "http://api.com".GetAsync(); HttpTest.ShouldHaveMadeACall().With(call => call.Response.Headers.Contains(("Content-Type", "text/xml"))); HttpTest.ShouldHaveMadeACall().With(call => call.HttpResponseMessage.Content.Headers.ContentType.MediaType == "text/xml"); }
public async Task GET_taxinfo_by_cuit_with_a_valid_CUIT_should_return_200_OK_when_JWT_token_is_a_valid_Doppler_PROD_one(string host, string expectedUserName, string expectedPassword) { // Arrange var cuit = "20-31111111-7"; var expectedUrl = $"http://{host}:33333/api/TaxInfo?ID=20311111117+CardData=Y"; _httpTest.RespondWithJson(DemoResult); using var appFactory = _factory.WithDisabledLifeTimeValidation() .AddConfiguration(new Dictionary <string, string>() { ["TaxInfoProvider:UseDummyData"] = "false", ["TaxInfoProvider:Host"] = host, ["TaxInfoProvider:UserName"] = expectedUserName, ["TaxInfoProvider:Password"] = expectedPassword }); appFactory.Server.PreserveExecutionContext = true; var client = appFactory.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, $"https://custom.domain.com/taxinfo/by-cuit/{cuit}"); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOjg4NDY5LCJ1bmlxdWVfbmFtZSI6ImFtb3NjaGluaUBtYWtpbmdzZW5zZS5jb20iLCJpc1N1IjpmYWxzZSwic3ViIjoiYW1vc2NoaW5pQG1ha2luZ3NlbnNlLmNvbSIsImN1c3RvbWVySWQiOiIxMzY3IiwiY2RoX2N1c3RvbWVySWQiOiIxMzY3Iiwicm9sZSI6IlVTRVIiLCJpYXQiOjE1OTQxNTUwMjYsImV4cCI6MTU5NDE1NjgyNn0.bv-ZHKulKMhBjcftiS-G_xa6MqPd8vmTJLCkitkSzz_lH6OblXnlLSjGAtoViT0yQun_IVqUggdfgY-Qv6cS_YeiYT-EqVLI1KFsFoWtZ7E1Yp5LZuVW70GskwZ7YbV7qlPrOOVBUbt6bD4LtwxudJmIenNBIgIVV-dCTl6vQNXRY65af7Ak1BG8IJxBaPhiFPniMIfNi_6my7NiHtL7Db2eeYgIxXf5_R-8BZFQ0CxWzNDTpdfaB48SnC7n6aEg9FQdOxcu8XX4qPBjGfnvCui2J9s8XgLfRtVQ27WwletL9XnGq79Dyp2PdNUsCcR2d4CMRxvzK1rO2jXSJ9Rf7w"); // Act var response = await client.SendAsync(request); // Assert var httpCallAssertion = _httpTest.ShouldHaveMadeACall(); httpCallAssertion.WithVerb(HttpMethod.Get); httpCallAssertion.WithUrlPattern(expectedUrl); httpCallAssertion.WithHeader("UserName", expectedUserName); httpCallAssertion.WithHeader("Password", expectedPassword); Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public async Task can_assert_headers() { await "http://api.com" .WithHeaders(new { h1 = "val1", h2 = "val2" }) .WithHeader("User-Agent", "two words") // #307 .WithHeader("x", "dos words") // crazier than #307 .WithHeader("y", "hi; there") // crazier still .GetAsync(); HttpTest.ShouldHaveMadeACall().WithHeader("h1"); HttpTest.ShouldHaveMadeACall().WithHeader("h2", "val2"); HttpTest.ShouldHaveMadeACall().WithHeader("h1", "val*"); HttpTest.ShouldHaveMadeACall().WithHeader("User-Agent", "two words"); HttpTest.ShouldHaveMadeACall().WithHeader("x", "dos words"); HttpTest.ShouldHaveMadeACall().WithHeader("y", "hi; there"); HttpTest.ShouldHaveMadeACall().WithoutHeader("h3"); HttpTest.ShouldHaveMadeACall().WithoutHeader("h2", "val1"); HttpTest.ShouldHaveMadeACall().WithoutHeader("h1", "foo*"); Assert.Throws <HttpCallAssertException>(() => HttpTest.ShouldHaveMadeACall().WithHeader("h3")); Assert.Throws <HttpCallAssertException>(() => HttpTest.ShouldHaveMadeACall().WithoutHeader("h1")); }
public async Task GetOneAsync_AllOk() { //arrange var httpTest = new HttpTest(); httpTest.RespondWith("soem content"); var apiCallResult = _fixture.Create <RoverResultModel>(); foreach (var photo in apiCallResult.photos) { photo.img_src = "http://path.com/" + photo.img_src; //so the "lastIndexOf" works } _proxy.Setup(p => p.GetPicturesAsync(It.IsAny <string>(), It.IsAny <DateTime>())).ReturnsAsync(apiCallResult); //good api call _file.Setup(f => f.Exists(It.IsAny <string>())).Returns(false); //file does not exist //act var result = await _service.GetOneAsync(); //assert Assert.NotNull(result); //we called the api _proxy.Verify(s => s.GetPicturesAsync(It.IsAny <string>(), It.IsAny <DateTime>()), Times.Once()); //we checked if the file exists var part = result.Url.Split('/', StringSplitOptions.None).Last(); _file.Verify(f => f.Exists(It.Is <string>(s => s.EndsWith(part))), Times.Once); //and since it did not, we download it httpTest.ShouldHaveMadeACall(); //since is random, check we picked one of the possibles Assert.Contains(apiCallResult.photos, s => s.img_src.Contains(part)); }
public async Task GetOneAsync_AllOk_CacheWorks() { //arrange var httpTest = new HttpTest(); httpTest.RespondWith("some content"); var apiCallResult = _fixture.Create <RoverResultModel>(); foreach (var photo in apiCallResult.photos) { photo.img_src = "http://path.com/" + photo.img_src; //so the "lastIndexOf" works } //{"opportunity", "curiosity", "spirit"}; var date = DateTime.Parse(_settings.Value.Dates[0]); _memoryCache.Set("opportunity-" + date, apiCallResult, TimeSpan.FromMinutes(5)); _memoryCache.Set("curiosity-" + date, apiCallResult, TimeSpan.FromMinutes(5)); _memoryCache.Set("spirit-" + date, apiCallResult, TimeSpan.FromMinutes(5)); _proxy.Setup(p => p.GetPicturesAsync(It.IsAny <string>(), It.IsAny <DateTime>())).ReturnsAsync(apiCallResult); //good api call _file.Setup(f => f.Exists(It.IsAny <string>())).Returns(false); //file does not exist //act var result = await _service.GetOneAsync(); //assert Assert.NotNull(result); //we never called the api (because it was cached) _proxy.Verify(s => s.GetPicturesAsync(It.IsAny <string>(), It.IsAny <DateTime>()), Times.Never); //we checked if the file exists _file.Verify(f => f.Exists(It.Is <string>(s => s.EndsWith(result.Url.Split('/', StringSplitOptions.None).Last()))), Times.Once); //and since it did not, we downlaod it httpTest.ShouldHaveMadeACall(); }
public async Task GET_taxinfo_by_cuit_with_a_valid_CUIT_should_return_200_OK_when_JWT_token_is_a_valid_Doppler_PROD_one(string host, string expectedUserName, string expectedPassword) { // Arrange var cuit = "20-31111111-7"; var expectedUrl = $"http://{host}:33333/api/TaxInfo?ID=20311111117+CardData=Y"; _httpTest.RespondWithJson(DemoResult); using var appFactory = _factory.WithDisabledLifeTimeValidation() .AddConfiguration(new Dictionary <string, string>() { ["TaxInfoProvider:UseDummyData"] = "false", ["TaxInfoProvider:Host"] = host, ["TaxInfoProvider:UserName"] = expectedUserName, ["TaxInfoProvider:Password"] = expectedPassword }); appFactory.Server.PreserveExecutionContext = true; var client = appFactory.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, $"https://custom.domain.com/taxinfo/by-cuit/{cuit}"); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOjg4NDY5LCJ1bmlxdWVfbmFtZSI6ImFtb3NjaGluaUBtYWtpbmdzZW5zZS5jb20iLCJpc1N1IjpmYWxzZSwic3ViIjoiYW1vc2NoaW5pQG1ha2luZ3NlbnNlLmNvbSIsImN1c3RvbWVySWQiOiIxMzY3IiwiY2RoX2N1c3RvbWVySWQiOiIxMzY3Iiwicm9sZSI6IlVTRVIiLCJpYXQiOjE1OTQxNTUwMjYsImV4cCI6MTU5NDE1NjgyNn0.a4eVqSBptPJk0y9V5Id1yXEzkSroX7j9712W6HOYzb-9irc3pVFQrdWboHcZPLlbpHUdsuoHmFOU-l14N_CjVF9mwjz0Qp9x88JP2KD1x8YtlxUl4BkIneX6ODQ5q_hDeQX-yIUGoU2-cIXzle-JzRssg-XIbaf34fXnUSiUGnQRAuWg3IkmpeLu9fVSbYrY-qW1os1gBSq4NEESz4T87hJblJv3HWNQFJxAtvhG4MLX2ITm8vYNtX39pwI5gdkLY7bNzWmJ1Uphz1hR-sdCdM2oUWKmRmL7txsoD04w5ca7YbdHQGwCI92We4muOs0-N7a4JHYjuDM9lL_TbJGw2w"); // Act var response = await client.SendAsync(request); // Assert var httpCallAssertion = _httpTest.ShouldHaveMadeACall(); httpCallAssertion.WithVerb(HttpMethod.Get); httpCallAssertion.WithUrlPattern(expectedUrl); httpCallAssertion.WithHeader("UserName", expectedUserName); httpCallAssertion.WithHeader("Password", expectedPassword); Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
[Test] // #313 public async Task can_setting_content_header_with_no_content() { await "http://api.com" .WithHeader("Content-Type", "application/json") .GetAsync(); HttpTest.ShouldHaveMadeACall().WithContentType("application/json"); }
public async Task can_assert_url_encoded_request() { var body = new { a = 1, b = 2, c = "hi there", d = new[] { 1, 2, 3 } }; await "http://some-api.com".PostUrlEncodedAsync(body); HttpTest.ShouldHaveMadeACall().WithRequestUrlEncoded(body); }
public async Task can_assert_json_request() { var body = new { a = 1, b = 2 }; await "http://some-api.com".PostJsonAsync(body); HttpTest.ShouldHaveMadeACall().WithRequestJson(body); }
public void File_Download_Was_Attempted() { HttpTest.ShouldHaveMadeACall().Times(1); HttpTest.ShouldHaveCalled(_expectedInputUrl.ToString()) .With(s => s.HttpStatus == HttpStatusCode.OK) .With(s => s.Request.Method == HttpMethod.Get) .Times(1); }
public async Task can_assert_oauth_token() { await "https://auth.com".WithOAuthBearerToken("foo").GetAsync(); HttpTest.ShouldHaveMadeACall().WithOAuthBearerToken(); HttpTest.ShouldHaveMadeACall().WithOAuthBearerToken("foo"); HttpTest.ShouldHaveMadeACall().WithOAuthBearerToken("*oo"); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithOAuthBearerToken("bar")); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithBasicAuth()); }
public async Task can_assert_verb() { await "http://www.api.com/1".PostStringAsync(""); await "http://www.api.com/2".PutStringAsync(""); await "http://www.api.com/3".PatchStringAsync(""); await "http://www.api.com/4".DeleteAsync(); HttpTest.ShouldHaveMadeACall().WithVerb(HttpMethod.Post).Times(1); HttpTest.ShouldHaveMadeACall().WithVerb("put", "PATCH").Times(2); HttpTest.ShouldHaveMadeACall().WithVerb("get", "delete").Times(1); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithVerb(HttpMethod.Get)); }
public async Task can_assert_basic_auth() { await "https://auth.com".WithBasicAuth("me", "letmein").GetAsync(); HttpTest.ShouldHaveMadeACall().WithBasicAuth(); HttpTest.ShouldHaveMadeACall().WithBasicAuth("me", "letmein"); HttpTest.ShouldHaveMadeACall().WithBasicAuth("me"); HttpTest.ShouldHaveMadeACall().WithBasicAuth("m*", "*in"); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithBasicAuth("me", "wrong")); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithBasicAuth("you")); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithBasicAuth("m*", "*out")); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithOAuthBearerToken()); }
public async Task can_assert_multiple_occurances_of_query_param() { await "http://www.api.com?x=1&x=2&x=3&y=4#abcd".GetAsync(); HttpTest.ShouldHaveMadeACall().WithQueryParam("x"); HttpTest.ShouldHaveMadeACall().WithQueryParamValue("x", new[] { 2, 1 }); // order shouldn't matter HttpTest.ShouldHaveMadeACall().WithQueryParamValues(new { x = new[] { 3, 2, 1 } }); // order shouldn't matter Assert.Throws <HttpCallAssertException>(() => HttpTest.ShouldHaveMadeACall().WithQueryParamValue("x", new[] { 1, 2, 4 })); Assert.Throws <HttpCallAssertException>(() => HttpTest.ShouldHaveMadeACall().WithQueryParamValues(new { x = new[] { 1, 2, 4 } })); }
public async Task TestFlurl() { using (var test = new HttpTest()) { var response = await _client.GetAsync("/WeatherForecast"); Assert.Equal <HttpStatusCode>(System.Net.HttpStatusCode.OK, response.StatusCode); // This fails ... // I want to test if the WeatherForecastController made a call to ishetalweekend.be. // This approach worked in our dotnet core 2.2 tests, but since converting to dotnet core 3.1 it no longer does. test.ShouldHaveMadeACall(); } }
public async Task Synchronize_InvalidImage_SaveThumbnailToCacheNotInvoked() { _thumbnailSynchronizer.Get <IPreferencesService>() .ThumbnailCachingStrategy .Returns(ThumbnailCachingStrategy.CacheAllThumbnailsWhenSynchronizing); _httpTest.RespondWith(string.Empty); await _thumbnailSynchronizer.ClassUnderTest.Synchronize(new Set { Images = new List <Image> { new Image { ThumbnailUrl = "http://www.url.com/thumbnails/thumbnail.jpg" } } }).ConfigureAwait(false); _httpTest.ShouldHaveMadeACall(); await _thumbnailSynchronizer.Get <IFileSystemService>() .DidNotReceiveWithAnyArgs() .SaveThumbnailToCache(null, null, null, null).ConfigureAwait(false); }
public async Task can_enable_auto_redirect_per_request(bool enabled) { HttpTest .RespondWith("original", 302, new { Location = "http://redir.com/foo" }) .RespondWith("redirected"); // whatever we want at the request level, set it the opposite at the client level var fc = new FlurlClient().WithAutoRedirect(!enabled); var result = await fc.Request("http://start.com").WithAutoRedirect(enabled).GetStringAsync(); Assert.AreEqual(enabled ? "redirected" : "original", result); HttpTest.ShouldHaveMadeACall().Times(enabled ? 2 : 1); }
public async Task can_provide_alternative_token() { // prove that auth credentials are no longer required like in earlier versions var cli = new OrderCloudClient(new OrderCloudClientConfig { ApiUrl = "https://fake.com", AuthUrl = "https://fake.com" }); using (var httpTest = new HttpTest()) { var products = await cli.Me.ListProductsAsync(accessToken : "some-other-token"); httpTest.ShouldHaveMadeACall().WithHeader("Authorization", "Bearer some-other-token"); } }
public async Task can_assert_url() { await "http://api.com" .AppendPathSegment("test") .GetAsync(); HttpTest.ShouldHaveMadeACall().WithUrlPattern("http://api.com/test"); HttpTest.ShouldHaveMadeACall().WithUrlPattern("http://api.com/TEST"); HttpTest.ShouldHaveMadeACall().WithUrlPattern("http://api.com/*"); Assert.Throws <HttpCallAssertException>(() => HttpTest.ShouldHaveMadeACall().WithUrlPattern("http://api.com")); Assert.Throws <HttpCallAssertException>(() => HttpTest.ShouldHaveMadeACall().WithUrlPattern("http://api.com/*/a")); }
public async Task PUT_with_Flurl_should_stringify_a_CuitNumber(string originalValue, string formattedValue) { // Arrange using var httpTest = new HttpTest(); var expectedJson = $"\"{formattedValue}\""; var cuitNumber = new CuitNumber(originalValue); // Act await "http://test.com/give_me_a_cuit".PostJsonAsync(cuitNumber); // Assert var httpCallAssertion = httpTest.ShouldHaveMadeACall(); httpCallAssertion.WithVerb(HttpMethod.Post); httpCallAssertion.WithRequestBody(expectedJson); }
public async Task cannot_inspect_RequestBody_with_uncaptured_content() { using (var httpTest = new HttpTest()) { // use StringContent instead of CapturedStringContent await "http://api.com".SendAsync(HttpMethod.Post, new StringContent("foo", null, "text/plain")); try { httpTest.ShouldHaveMadeACall().WithRequestBody("foo"); Assert.Fail("Asserting RequestBody with uncaptured content should have thrown FlurlHttpException."); } catch (FlurlHttpException ex) { // message should mention RequestBody and CapturedStringContent StringAssert.Contains("RequestBody", ex.Message); StringAssert.Contains("CapturedStringContent", ex.Message); } } }
public async Task InstallAllMyBricksSeedDatabase_ValidParameters_ResultIsTrue() { _assetManagementService.Get <IAssetUncompression>() .UncompressAsset(Arg.Any <Stream>(), Arg.Any <string>(), Arg.Any <bool>(), Arg.Any <string>()) .Returns(true); _assetManagementService.Get <IDirectory>() .Exists(Arg.Any <string>()) .Returns(true); var result = await _assetManagementService.ClassUnderTest.InstallAllMyBricksSeedDatabase("http://www.google.com/test.lzc", "C:\\").ConfigureAwait(false); Check.That(result).IsTrue(); _httpTest.ShouldHaveMadeACall(); _assetManagementService.Get <IAssetUncompression>() .ReceivedWithAnyArgs() .UncompressAsset(Arg.Any <Stream>(), Arg.Any <string>()); }
public async Task can_assert_headers() { await "http://api.com".WithHeaders(new { h1 = "val1", h2 = "val2" }).GetAsync(); HttpTest.ShouldHaveMadeACall().WithHeader("h1"); HttpTest.ShouldHaveMadeACall().WithHeader("h2", "val2"); HttpTest.ShouldHaveMadeACall().WithHeader("h1", "val*"); HttpTest.ShouldHaveMadeACall().WithoutHeader("h3"); HttpTest.ShouldHaveMadeACall().WithoutHeader("h2", "val1"); HttpTest.ShouldHaveMadeACall().WithoutHeader("h1", "foo*"); Assert.Throws <HttpCallAssertException>(() => HttpTest.ShouldHaveMadeACall().WithHeader("h3")); Assert.Throws <HttpCallAssertException>(() => HttpTest.ShouldHaveMadeACall().WithoutHeader("h1")); }
public async Task can_assert_multiple_occurances_of_query_param(bool buildFluently) { // #276 showed that this failed when the URL was built fluently (caused by #301) var url = buildFluently ? "http://www.api.com".SetQueryParam("x", new[] { 1, 2, 3 }).SetQueryParam("y", 4).SetFragment("abcd") : new Url("http://www.api.com?x=1&x=2&x=3&y=4#abcd"); await url.GetAsync(); HttpTest.ShouldHaveMadeACall().WithQueryParam("x"); HttpTest.ShouldHaveMadeACall().WithQueryParamValue("x", new[] { 2, 1 }); // order shouldn't matter HttpTest.ShouldHaveMadeACall().WithQueryParamValues(new { x = new[] { 3, 2, 1 } }); // order shouldn't matter Assert.Throws <HttpCallAssertException>(() => HttpTest.ShouldHaveMadeACall().WithQueryParamValue("x", new[] { 1, 2, 4 })); Assert.Throws <HttpCallAssertException>(() => HttpTest.ShouldHaveMadeACall().WithQueryParamValues(new { x = new[] { 1, 2, 4 } })); }
public async Task can_assert_query_params() { await "http://www.api.com?x=111&y=222&z=333#abcd".GetAsync(); HttpTest.ShouldHaveCalled("http://www.api.com*").WithQueryParams(); HttpTest.ShouldHaveMadeACall().WithQueryParam("x"); HttpTest.ShouldHaveCalled("http://www.api.com*").WithQueryParams("z", "y"); HttpTest.ShouldHaveMadeACall().WithQueryParam("y", 222); HttpTest.ShouldHaveCalled("http://www.api.com*").WithQueryParam("z", "*3"); HttpTest.ShouldHaveMadeACall().WithQueryParams(new { z = 333, y = 222 }); HttpTest.ShouldHaveMadeACall().WithQueryParams(new { z = "*", y = 222, x = "*" }); HttpTest.ShouldHaveMadeACall().WithAnyQueryParam("a", "z", "b"); // without HttpTest.ShouldHaveCalled("http://www.api.com*").WithoutQueryParam("w"); HttpTest.ShouldHaveMadeACall().WithoutQueryParams("t", "u", "v"); HttpTest.ShouldHaveCalled("http://www.api.com*").WithoutQueryParam("x", 112); HttpTest.ShouldHaveMadeACall().WithoutQueryParams(new { x = 112, y = 223, z = 666 }); HttpTest.ShouldHaveMadeACall().WithoutQueryParams(new { a = "*", b = "*" }); // failures Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithQueryParam("w")); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithQueryParam("y", 223)); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithQueryParam("z", "*4")); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithQueryParams(new { x = 111, y = 666 })); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithoutQueryParams()); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithoutQueryParam("x")); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithoutQueryParams("z", "y")); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithoutQueryParam("y", 222)); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithoutQueryParam("z", "*3")); Assert.Throws <HttpTestException>(() => HttpTest.ShouldHaveMadeACall().WithoutQueryParams(new { z = 333, y = 222 })); }