public async void Can_hit_endpoint() { var request = new FluentApi <ArtistSearch>() .WithParameter("q", "pink") .WithParameter("country", "GB"); var artist = await request.Please(); Assert.That(artist, Is.Not.Null); }
public async void Can_get_multiple_results_with_new_FluentApi_overload() { var request = new FluentApi <ArtistSearch>(new AppSettingsCredentials(), new ApiUri()) .ForShop(34) .WithQuery("pink") .WithPageNumber(1) .WithPageSize(20); var artistSearch = await request.Please(); Assert.That(artistSearch.Results.Count, Is.GreaterThan(1)); }
public async void SetUp() { var requestBuilder = A.Fake <IRequestBuilder>(); var httpClient = A.Fake <IHttpClient>(); var responseXml = File.ReadAllText("StubResponses/Playlists.xml"); var validPlaylistsResponse = new Response(HttpStatusCode.OK, responseXml); A.CallTo(() => httpClient.Send(null)).WithAnyArguments().Returns(Task.FromResult(validPlaylistsResponse)); var fluentApi = new FluentApi <UserPlaylists>(httpClient, requestBuilder); _userPlaylists = await fluentApi.Please(); }
public async void SetUp() { var requestBuilder = A.Fake<IRequestBuilder>(); var httpClient = A.Fake<IHttpClient>(); var responseParser = new ResponseParser(new ApiResponseDetector()); var responseXml = File.ReadAllText("StubResponses/Playlists.xml"); var validPlaylistsResponse = new Response(HttpStatusCode.OK, responseXml); A.CallTo(() => httpClient.Send(null)).WithAnyArguments().Returns(Task.FromResult(validPlaylistsResponse)); var fluentApi = new FluentApi<UserPlaylists>(httpClient, requestBuilder, responseParser); _userPlaylists = await fluentApi.Please(); }
public async void Should_use_custom_http_client() { var requestHandler = StubRequestBuilder(); var fakeHttpClient = new FakeHttpClient(_stubResponse); var api = new FluentApi <Status>(requestHandler).UsingClient(fakeHttpClient); Assert.That(fakeHttpClient.SendCount, Is.EqualTo(0)); await api.Please(); Assert.That(fakeHttpClient.SendCount, Is.EqualTo(1)); }
public void Should_not_write_to_cache_on_failure() { var requestHandler = StubRequestBuilder(); var httpClient = StubHttpClient(); var api = new FluentApi <Status>(httpClient, requestHandler); var cache = new FakeCache(); A.CallTo(() => httpClient.Send(A <Request> .Ignored)).Throws <WebException>(); api.UsingCache(cache); Assert.Throws <ApiWebException>(async() => await api.Please()); Assert.That(cache.SetCount, Is.EqualTo(0)); Assert.That(cache.CachedResponses.Count, Is.EqualTo(0)); }
public void Should_wrap_webexception_under_api_exception_to_know_the_URL() { const string url = "http://example.com/status"; var requestHandler = StubRequestBuilder(); var httpClient = StubHttpClient(); A.CallTo(() => httpClient.Send(A <Request> .Ignored)).Throws <WebException>(); var api = new FluentApi <Status>(httpClient, requestHandler); var ex = Assert.Throws <ApiWebException>(async() => await api.Please()); Assert.That(ex.InnerException, Is.Not.Null); Assert.That(ex.OriginalRequest.Url, Is.EqualTo(url)); Assert.That(ex.InnerException.GetType(), Is.EqualTo(typeof(WebException))); }
public void Should_not_write_to_cache_on_failure() { var requestHandler = StubRequestBuilder(); var httpClient = StubHttpClient(); var responseParser = StubResponseParser(); var api = new FluentApi<Status>(httpClient, requestHandler, responseParser); var cache = new FakeCache(); A.CallTo(() => httpClient.Send(A<Request>.Ignored)).Throws<WebException>(); api.UsingCache(cache); Assert.Throws<ApiWebException>(async () => await api.Please()); Assert.That(cache.SetCount, Is.EqualTo(0)); Assert.That(cache.CachedResponses.Count, Is.EqualTo(0)); }
public void Should_wrap_webexception_under_api_exception_to_know_the_url() { const string url = "http://example.com/status"; var requestHandler = StubRequestBuilder(); var httpClient = StubHttpClient(); var responseParser = StubResponseParser(); A.CallTo(() => httpClient.Send(A<Request>.Ignored)).Throws<WebException>(); var api = new FluentApi<Status>(httpClient, requestHandler, responseParser); var ex = Assert.Throws<ApiWebException>(async () => await api.Please()); Assert.That(ex.InnerException, Is.Not.Null); Assert.That(ex.OriginalRequest.Url, Is.EqualTo(url)); Assert.That(ex.InnerException.GetType(), Is.EqualTo(typeof(WebException))); }
public async void Should_use_custom_http_client() { var requestHandler = StubRequestBuilder(); var httpClient = StubHttpClient(); var responseParser = StubResponseParser(); var fakeHttpClient = new FakeHttpClient(_stubResponse); var api = new FluentApi<Status>(httpClient, requestHandler, responseParser).UsingClient(fakeHttpClient); Assert.That(fakeHttpClient.SendCount, Is.EqualTo(0)); await api.Please(); Assert.That(fakeHttpClient.SendCount, Is.EqualTo(1)); }
public void Should_not_write_to_cache_on_failure() { var requestCoordinator = A.Fake<IRequestCoordinator>(); var cache = new FakeCache(); A.CallTo(() => requestCoordinator.HitEndpoint(A<RequestData>.Ignored)).Throws<WebException>(); A.CallTo(() => requestCoordinator.ConstructEndpoint(A<RequestData>.Ignored)).Returns("http://foo.com/bar"); var api = new FluentApi<Status>(requestCoordinator).UsingCache(cache); Assert.Throws<ApiWebException>(() => api.Please()); Assert.That(cache.SetCount, Is.EqualTo(0)); Assert.That(cache.CachedResponses.Count, Is.EqualTo(0)); }