public void TestTryUntilWithMaxTryCount() { var times = 5; var generator = new Generator(times); bool result = false; Expect(RetryHelperTest.CountTime(() => result = _target.Try(() => generator.Next()).WithMaxTryCount(times + 1).Until(t => t)), EqualTo(RetryHelperTest.Interval * times).Within(RetryHelperTest.Tolerance)); Expect(result, True); }
public void TestOnTimeoutShouldNotFire() { var times = 5; var generator = new Generator(times); var onTimeoutTriggered = false; _target.Try(() => generator.Next()) .OnTimeout(t => onTimeoutTriggered = true) .Until(t => t); Expect(onTimeoutTriggered, False); }
public void TestOnSuccessAfterFiveTimes() { var times = 5; var generator = new Generator(times); var onSuccessTriggered = false; _target.Try(() => generator.Next()) .OnSuccess(t => onSuccessTriggered = true) .Until(t => t); Expect(onSuccessTriggered, True); }
public void TestOnFailureShouldNotFireIfSucceedAtFirstTime() { var times = 0; var generator = new Generator(times); var onFailureTriggered = 0; _target.Try(() => generator.Next()) .OnFailure(t => onFailureTriggered++) .Until(t => t); Expect(onFailureTriggered, EqualTo(0)); }
public void TestTryUntilNoExceptionSuccessFirstTime() { var times = 0; var generator = new Generator(times); bool result = false; Expect(RetryHelperTest.CountTime(() => result = _target.Try(() => generator.Next()).Until(t => t)), EqualTo(RetryHelperTest.Interval * times).Within(RetryHelperTest.Tolerance)); Expect(generator.TriedTimes, EqualTo(times + 1)); Expect(result, True); }
public void TestTryUntilNoExceptionOfTypeHavingOtherException() { var times = 10; var generator = new Generator(times, true); generator.RandomExceptionType = true; bool result = false; Expect(() => result = _target.Try(() => generator.Next()).UntilNoException<ApplicationException>(), Throws.TypeOf<InvalidOperationException>()); Expect(result, False); }
public void TestTryUntilNoExceptionOfTypeAfterFiveTimes() { var times = 10; var generator = new Generator(times, true); bool result = false; Expect(RetryHelperTest.CountTime(() => result = _target.Try(() => generator.Next()).UntilNoException<ApplicationException>()), EqualTo(RetryHelperTest.Interval * times).Within(RetryHelperTest.Tolerance)); Expect(generator.TriedTimes, EqualTo(times + 1)); Expect(result, True); }
public void TestTryUntilWithMaxTryCountExceeded() { var times = 5; var generator = new Generator(times); bool result = false; Expect(RetryHelperTest.CountTime(() => Expect(() => result = _target.Try(() => generator.Next()).WithMaxTryCount(times).Until(t => t), Throws.TypeOf<TimeoutException>())), EqualTo(RetryHelperTest.Interval * (times - 1)).Within(RetryHelperTest.Tolerance)); Expect(result, False); }
public void TestOnSuccessShouldNotFire() { var times = 5; var generator = new Generator(times); var onSuccessTriggered = false; Expect(() => _target.Try(() => generator.Next()) .WithMaxTryCount(times - 1) .OnSuccess(t => onSuccessTriggered = true) .Until(t => t), Throws.TypeOf<TimeoutException>()); Expect(onSuccessTriggered, False); }
public void TestOnTimeoutAfterFiveTimes() { var times = 5; var generator = new Generator(times); var onTimeoutTriggered = false; Expect(() => _target.Try(() => generator.Next()) .WithMaxTryCount(times - 1) .OnTimeout(t => onTimeoutTriggered = true) .Until(t => t), Throws.TypeOf<TimeoutException>()); Expect(onTimeoutTriggered, True); }
public void TestOnSuccessWithTriedCount() { var times = 5; var generator = new Generator(times); var onSuccessTriggered = false; _target.Try(() => generator.Next()) .OnSuccess((t, count) => { Expect(count, EqualTo(times + 1)); onSuccessTriggered = true; }) .Until(t => t); Expect(onSuccessTriggered, True); }
public void TestOnFailureWithTryCount() { var times = 5; var generator = new Generator(times); var onFailureTriggered = 0; _target.Try(() => generator.Next()) .OnFailure((t, count) => { Expect(t, False); Expect(count, EqualTo(++onFailureTriggered)); }) .Until(t => t); Expect(onFailureTriggered, EqualTo(times)); }
public void TestOnFailureAfterFiveTimes() { var times = 5; var generator = new Generator(times); var onFailureTriggered = 0; _target.Try(() => generator.Next()) .OnFailure(t => { Expect(t, False); onFailureTriggered++; }) .Until(t => t); Expect(onFailureTriggered, EqualTo(times)); }
public void TestOnTimeoutWithTriedCount() { var times = 5; var generator = new Generator(times); var onTimeoutTriggered = false; var maxTryCount = times - 1; Expect(() => _target.Try(() => generator.Next()) .WithMaxTryCount(maxTryCount) .OnTimeout((t, count) => { Expect(count, EqualTo(maxTryCount)); onTimeoutTriggered = true; }) .Until(t => t), Throws.TypeOf<TimeoutException>()); Expect(onTimeoutTriggered, True); }