public async Task Retry_RetryUntilFailure() { FaultyClass faultyClass = new FaultyClass() { ExceptionToThrow = new ArgumentNullException(), TriesUntilSuccess = 12, }; await Assert.ThrowsAsync <AggregateException>(async() => await Retry.Run( task: () => faultyClass.FaultyTask(), retryExceptionHandler: (ex, ct) => faultyClass.ExceptionHandler(ex, ct))); }
public async Task Retry_NoRetryWhenTaskSucceeds() { FaultyClass faultyClass = new FaultyClass() { ExceptionToThrow = null, }; var result = await Retry.Run( task : () => faultyClass.FaultyTask(), retryExceptionHandler : (ex, ct) => faultyClass.ExceptionHandler(ex, ct)); Assert.Null(faultyClass.ExceptionReceived); Assert.Equal(1, faultyClass.CallCount); }
public async Task Retry_RetryThenSucceed() { FaultyClass faultyClass = new FaultyClass() { ExceptionToThrow = new ArgumentNullException(), TriesUntilSuccess = 3, }; var result = await Retry.Run( task : () => faultyClass.FaultyTask(), retryExceptionHandler : (ex, ct) => faultyClass.ExceptionHandler(ex, ct)); Assert.NotNull(faultyClass.ExceptionReceived); Assert.Equal(3, faultyClass.CallCount); }