Exemple #1
0
        public void RetryHandle_Retries_x_times(int times)
        {
            var retryAttempt = 0;
            var sut          = RetryHandler.Create(Options <RetryHandleOptions> .Create(options =>
            {
                options.MaximumAttempts = times;
                options.Timeout         = 500;
            }), typeof(TimeoutException));

            sut.Handle <string>(() => throw new TimeoutException(), ex => { retryAttempt++; });
            Assert.Equal(times, retryAttempt);
        }
Exemple #2
0
        public void RetryHandle_Retries_x_times_then_passes_on_last_attempt(int times, string passValue)
        {
            var retryAttempt = 0;
            var sut          = RetryHandler.Create(Options <RetryHandleOptions> .Create(options =>
            {
                options.MaximumAttempts = times;
                options.Timeout         = 500;
            }), typeof(TimeoutException));

            Assert.Equal(passValue,
                         sut.Handle <string>(() =>
            {
                if (retryAttempt == times - 1)
                {
                    return(passValue);
                }
                throw new TimeoutException();
            }, ex => { retryAttempt++; }));

            Assert.Equal(times - 1, retryAttempt);
        }