コード例 #1
0
 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);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 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));
 }
コード例 #5
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);
 }
コード例 #6
0
 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);
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 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);
 }
コード例 #9
0
 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);
 }
コード例 #10
0
 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);
 }
コード例 #11
0
 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);
 }
コード例 #12
0
 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));
 }
コード例 #13
0
 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));
 }
コード例 #14
0
 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);
 }