Esempio n. 1
0
        public void Run_ActionSucceeds_ExecuteOnce()
        {
            // Arrange
            var callCount = 0;
            var retry     = new RetryImpl(() => callCount += 1, new RethrowAllExceptionBehavior(), doNotWaitHandler);

            // Act
            var result = retry.Run();

            // Assert
            Assert.AreEqual(1, callCount);
            Assert.AreEqual(CompletionState.Success, result);
        }
Esempio n. 2
0
        public void Run_RetryStrategyProvidesNegativeTimeSpan_ThrowsException()
        {
            // Arrange
            var retry = new RetryImpl((() => Throws()));

            retry.Using(new ReturnNegativeTimeSpanRetryStrategy());

            // Act
            retry.Run();

            // Assert
            // Expected exception
        }
Esempio n. 3
0
        public void Run_ActionSucceeds_ExecuteOnce()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                ShimThread.SleepInt32 = i => { };
                var callCount = 0;
                var retry     = new RetryImpl(() => callCount += 1);

                // Act
                retry.Run();

                // Assert
                Assert.AreEqual(1, callCount);
            }
        }
Esempio n. 4
0
        public void Run_TryThrowsBehaviorReturnsRethrow_ExceptionIsRethrown()
        {
            // Arrange
            var retry = new RetryImpl(() =>
            {
                Throws();
            });

            retry.OnException(new RethrowAllExceptionBehavior());

            // Act
            retry.Run();

            // Assert
            // Expected exception
        }
Esempio n. 5
0
        public void Run_TryThrows_BehaviorOnExceptionIsCalled()
        {
            // Arrange
            var mockedExceptionBehavior = new Mock <IExceptionBehavior>();

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

            retry.MaximumNumberOfTries(1);

            // Act
            retry.Run();

            // Assert
            mockedExceptionBehavior.Verify(behavior => behavior.OnException(It.IsAny <Exception>()), Times.Once);
        }
Esempio n. 6
0
        public void Run_TryThrowsBehaviorReturnsAbort_ShouldStopRetrying()
        {
            // Arrange
            var tryCount = 0;
            var mockedAbortExceptionBehavior = new Mock <IExceptionBehavior>();

            mockedAbortExceptionBehavior.Setup(behavior => behavior.OnException(It.IsAny <Exception>()))
            .Returns(AfterExceptionBehavior.Abort);

            var retry = new RetryImpl((() =>
            {
                tryCount += 1;
                Throws();
            }));

            retry.OnException(mockedAbortExceptionBehavior.Object);

            // Act
            var result = retry.Run();

            // Assert
            Assert.AreEqual(CompletionState.Aborted, result);
            Assert.AreEqual(1, tryCount);
        }