コード例 #1
0
 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));
     }
 }
コード例 #2
0
 public DummyRestClientFactory()
 {
     _restClient = new MultiplexedRestClient(new UsernamePasswordAuthenticationProvider("username", "password"),
                                             "dummy-UA",
                                             new[]
     {
         SoleUri
     });
 }
コード例 #3
0
        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"));
            }
        }
コード例 #4
0
        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"));
            }
        }
コード例 #5
0
        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);
            }
        }