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); }
public void Run_RetryStrategyProvidesNegativeTimeSpan_ThrowsException() { // Arrange var retry = new RetryImpl((() => Throws())); retry.Using(new ReturnNegativeTimeSpanRetryStrategy()); // Act retry.Run(); // Assert // Expected exception }
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); } }
public void Run_TryThrowsBehaviorReturnsRethrow_ExceptionIsRethrown() { // Arrange var retry = new RetryImpl(() => { Throws(); }); retry.OnException(new RethrowAllExceptionBehavior()); // Act retry.Run(); // Assert // Expected exception }
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); }
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); }