예제 #1
0
 public ManagementHttpClientTests()
 {
     _defaultClient = new ManagementHttpClient(
         httpClient,
         new DefaultResiliencePolicyProvider(Constants.DEFAULT_MAX_RETRIES),
         Constants.ENABLE_RESILIENCE_POLICY);
 }
예제 #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);
        }