示例#1
0
        public async Task SendAsync_SendsMessageOnSuccessReturnsResponse()
        {
            var successfulMessage  = new HttpRequestMessage();
            var successfulResponse = new HttpResponseMessage {
                StatusCode = System.Net.HttpStatusCode.OK
            };

            httpClient.SendAsync(successfulMessage).ReturnsForAnyArgs(successfulResponse);

            var response = await _defaultClient.SendAsync(messageCreator, endpointUrl, method);

            await httpClient.ReceivedWithAnyArgs().SendAsync(successfulMessage);

            Assert.Equal(successfulResponse, response);
        }
示例#2
0
        public async void Retries_WithCustomResilencePolicyAndPolicyDisabled_PolicyIgnored()
        {
            int retryAttempts = 2;

            var failfulMessage = new HttpRequestMessage();

            httpClient
            .SendAsync(failfulMessage)
            .ReturnsForAnyArgs((request) => new HttpResponseMessage(HttpStatusCode.RequestTimeout));

            var mockResilencePolicyProvider = Substitute.For <IResiliencePolicyProvider>();

            mockResilencePolicyProvider.Policy
            .Returns(Policy.HandleResult <HttpResponseMessage>(result => true).RetryAsync(retryAttempts));

            var customClient = new ManagementHttpClient(
                httpClient,
                mockResilencePolicyProvider,
                Constants.DISABLE_RESILIENCE_POLICY);

            httpClient.ClearReceivedCalls();
            await Assert.ThrowsAsync <ManagementException>(async() => { await customClient.SendAsync(messageCreator, endpointUrl, method); });

            var policy = mockResilencePolicyProvider.DidNotReceive().Policy;
        }
示例#3
0
        public async void Retries_EnableResilienceLogicDisabled_DoesNotRetry()
        {
            var failfulMessage = new HttpRequestMessage();

            httpClient
            .SendAsync(failfulMessage)
            .ReturnsForAnyArgs((request) => new HttpResponseMessage(HttpStatusCode.RequestTimeout));

            var customClient = new ManagementHttpClient(
                httpClient,
                new DefaultResiliencePolicyProvider(Constants.DEFAULT_MAX_RETRIES),
                Constants.DISABLE_RESILIENCE_POLICY);

            httpClient.ClearReceivedCalls();
            await Assert.ThrowsAsync <ManagementException>(async() => { await customClient.SendAsync(messageCreator, endpointUrl, method); });

            await httpClient.ReceivedWithAnyArgs(1).SendAsync(failfulMessage);
        }
示例#4
0
        public async void Retries_WithMaxRetrySet_SettingReflected()
        {
            int retryAttempts    = 3;
            int expectedAttempts = retryAttempts + 1;

            var failfulMessage = new HttpRequestMessage();

            httpClient
            .SendAsync(failfulMessage)
            .ReturnsForAnyArgs((request) => new HttpResponseMessage(HttpStatusCode.RequestTimeout));

            var customClient = new ManagementHttpClient(
                httpClient,
                new DefaultResiliencePolicyProvider(retryAttempts),
                Constants.ENABLE_RESILIENCE_POLICY);

            httpClient.ClearReceivedCalls();
            await Assert.ThrowsAsync <ManagementException>(async() => { await customClient.SendAsync(messageCreator, endpointUrl, method); });

            await httpClient.ReceivedWithAnyArgs(expectedAttempts).SendAsync(failfulMessage);
        }