예제 #1
0
        public void RunAsync_ActionSucceedsThirdTime_TaskDelayCalledTwoTimes()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var taskDelayCallCount = 0;
                ShimTask.DelayTimeSpanCancellationToken = (t, c) =>
                {
                    taskDelayCallCount += 1;
                    return(Task.CompletedTask);
                };

                var callCount = 0;
                var retry     = new RetryImpl((() =>
                {
                    callCount += 1;
                    if (callCount == 3)
                    {
                        return; // success
                    }

                    Throws();
                }));

                // Act
                retry.RunAsync().Wait();

                // Assert
                Assert.AreEqual(2, taskDelayCallCount);
            }
        }
예제 #2
0
        public void RunAsync_RetryStrategyProvidesNegativeTimeSpan_ThrowsException()
        {
            // Arrange
            var retry = new RetryImpl((() => Throws()));

            retry.Using(new ReturnNegativeTimeSpanRetryStrategy());

            // Act
            retry.RunAsync().Wait();

            // Assert
            // Expected exception
        }
예제 #3
0
        public void RunAsync_TryThrows_BehaviorOnExceptionIsCalled()
        {
            // Arrange
            var mockedExceptionBehavior = new Mock <IExceptionBehavior>();

            var retry = new RetryImpl(() =>
            {
                Throws();
            }, mockedExceptionBehavior.Object, doNotWaitHandler);

            retry.MaximumNumberOfTries(1);

            // Act
            retry.RunAsync().Wait();

            // Assert
            mockedExceptionBehavior.Verify(behavior => behavior.OnException(It.IsAny <Exception>()), Times.Once);
        }
예제 #4
0
        public void RunAsync_ActionSucceedsThirdTime_TaskDelayCalledTwoTimes()
        {
            // Arrange
            var callCount = 0;
            var retry     = new RetryImpl(() =>
            {
                callCount += 1;
                if (callCount == 3)
                {
                    return; // success
                }

                Throws();
            }, new RetryAllExceptionBehavior(), doNotWaitHandler);

            // Act
            retry.RunAsync().Wait();

            // Assert
            Assert.AreEqual(2, doNotWaitHandler.SleepCount);
        }