public void SyncVoid_SuccessOnFifthTry() { int i = 0; WaitAndRetry.Retry(10, 1, () => CalledVoidMethodSuccessOnFifthTry(1, ref i)); Assert.Equal(5, i); }
public void SyncVoid_FailedFourthTimes() { int i = 0; Action act = () => WaitAndRetry.Retry(4, 1, () => CalledVoidMethodSuccessOnFifthTry(1, ref i)); Assert.Throws <RetryException>(act); Assert.Equal(4, i); }
public void Sync_SuccessOnFifthTry() { int i = 0; var result = WaitAndRetry.Retry(10, 1, () => CalledMethodSuccessOnFifthTry(1, ref i)); Assert.Equal("1", result); Assert.Equal(5, i); }
public void SyncVoid_SuccessOnFifthTryWith_ExecutionTimeTest() { int i = 0; Stopwatch sw = new Stopwatch(); sw.Start(); WaitAndRetry.Retry(10, 100, () => CalledVoidMethodSuccessOnFifthTry(1, ref i)); sw.Stop(); Assert.InRange(sw.ElapsedMilliseconds, 400, 500); Assert.Equal(5, i); }
static async Task Main(string[] args) { Service service = new Service(); #region methods with return // synchronous call service.AttemptCount = 0; var result1 = WaitAndRetry.Retry <string>(10, 1, () => service.TestSuccess(1)); // async call (both options are correct) service.AttemptCount = 0; var result21 = await WaitAndRetry.RetryAsync <string>(10, 1, () => service.TestSuccessAsync(1)); service.AttemptCount = 0; var result23 = await WaitAndRetry.RetryAsync <string>(10, 1, async() => await service.TestSuccessAsync(1)); #endregion #region Void Methods // synchronous call service.AttemptCount = 0; WaitAndRetry.Retry(10, 1, () => service.TestVoidSuccess(1)); // async call (both options are correct) service.AttemptCount = 0; await WaitAndRetry.RetryAsync(10, 1, () => service.TestVoidSuccessAsync(1)); service.AttemptCount = 0; await WaitAndRetry.RetryAsync(10, 1, async() => await service.TestVoidSuccessAsync(1)); // This is wrong usage !!! service.AttemptCount = 0; await WaitAndRetry.Retry(10, 1, () => service.TestVoidSuccessAsync(1)); #endregion }
public void SyncVoid_FailOnFirstTry() { void Act() => WaitAndRetry.Retry(1, 1, () => CalledVoidMethodFail(1)); Assert.Throws <RetryException>(Act); }
public void SyncVoid_SuccessOnFirstTry() { WaitAndRetry.Retry(1, 1, () => CalledVoidMethodSuccess(1)); }
public void Sync_SuccessOnFirstTry() { var result = WaitAndRetry.Retry(1, 1, () => CalledMethodSuccess(1)); Assert.Equal("1", result); }