public async Task ShouldThrowOperationCanceledExceptionWhenCanceledWithCancellationToken() { using (var httpTest = new HttpTest()) { var ct = new CancellationToken(true); var client = new MultiplexedRestClient(_authenticator, "dummy", new[] { new Uri("https://dummy1"), new Uri("https://dummy2") }); await Assert.ThrowsAsync <OperationCanceledException>(async() => await client.InvokeAsync(HttpMethod.Get, "dummy", cancellationToken: ct)); } }
public DummyRestClientFactory() { _restClient = new MultiplexedRestClient(new UsernamePasswordAuthenticationProvider("username", "password"), "dummy-UA", new[] { SoleUri }); }
public async Task ShouldImmediatelyFailOnForbiddenError() { using (var httpTest = new HttpTest()) { // Only the first call should result in a 403 error httpTest.RespondWith("Forbidden", 403); var client = new MultiplexedRestClient(_authenticator, "dummy", new[] { new Uri("https://dummy1"), new Uri("https://dummy2") }); await Assert.ThrowsAsync <AuthorizationException>(async() => await client.InvokeAsync(HttpMethod.Get, "dummy")); } }
public async Task ShouldThrowServiceUnreachableExceptionWhenAllEndpointsTimeout() { using (var httpTest = new HttpTest()) { // Two subsequent calls should result in a server error 5xx httpTest.SimulateTimeout(); httpTest.SimulateTimeout(); var client = new MultiplexedRestClient(_authenticator, "dummy", new[] { new Uri("https://dummy1"), new Uri("https://dummy2") }); await Assert.ThrowsAsync <ServiceUnreachableException>(async() => await client.InvokeAsync(HttpMethod.Get, "dummy")); } }
public async Task ShouldSucceedWhenAtLeastOneEndpointDoesNotTimeout() { using (var httpTest = new HttpTest()) { // Only the first call should result in a server error 5xx httpTest.SimulateTimeout(); var client = new MultiplexedRestClient(_authenticator, "dummy", new[] { new Uri("https://dummy1"), new Uri("https://dummy2") }); var response = await client.InvokeAsync(HttpMethod.Get, "dummy"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }