public async Task ExecutionWithRetry() { RetryHandler retryHandler = new RetryHandler(5, 15, 7, true); retryHandler .IncludeForRetry <NullReferenceException>(); short retryCount = -1; short errorCount = 0; await retryHandler.ExecuteAsync(async() => { retryCount++; await Task.Delay(20); throw new NullReferenceException(); }, async (exception, retryIndex, retryLimit) => { errorCount++; await Task.Delay(10); Assert.NotNull(exception); Assert.Equal((ushort)retryCount, retryIndex); Assert.Equal(7, retryLimit); }); Assert.Equal(7, retryCount); Assert.Equal(8, errorCount); }
public void ExceptionInclusion() { RetryHandler retryHandler = new RetryHandler(5, 15, 7, true); retryHandler .IncludeForRetry <TimeoutException>() .IncludeForRetry <NullReferenceException>(); Assert.True(retryHandler.IsForRetry(new TimeoutException())); Assert.True(retryHandler.IsForRetry(new NullReferenceException())); Assert.False(retryHandler.IsForRetry(new ArgumentNullException())); }