示例#1
0
        public void Test_Retry_不指定过滤器()
        {
            TestRetryTask1 task = new TestRetryTask1();

            string text = Retry.Create(5, 10).Run(() => {
                return(task.Exec1());
            });

            Assert.AreEqual(TestRetryTask1.Result, text);
        }
示例#2
0
        public void Test_Retry_指定部分过滤器_将会出现异常2()
        {
            TestRetryTask1 task = new TestRetryTask1();

            string text = Retry.Create(5, 10)
                          .Filter <NotSupportedException>()
                          .Run(() => {
                return(task.Exec2());
            });

            Assert.AreEqual(TestRetryTask1.Result, text);
        }
示例#3
0
        public void Test_Retry_指定部分过滤器_将会出现异常()
        {
            TestRetryTask1 task = new TestRetryTask1();

            string text = Retry.Create(5, 10)
                          .Filter <NotSupportedException>()
                          .Filter <ArgumentOutOfRangeException>(ex => ex.ParamName == "name")
                          .Run(() => {
                return(task.Exec2());
            });

            Assert.AreEqual(TestRetryTask1.Result, text);
        }
示例#4
0
        public void Test_Retry_指定过滤器_指定回调方法()
        {
            int            count  = 0;
            int            count2 = 0;
            TestRetryTask1 task   = new TestRetryTask1();

            string text = Retry.Create(5, 10)
                          .Filter <NotSupportedException>()
                          .OnException((ex, n) => { count++; })
                          .OnException((ex, n) => { count2 += n; })
                          .Run(() => {
                return(task.Exec3());
            });

            Assert.AreEqual(TestRetryTask1.Result, text);
            Assert.AreEqual(3, count);
            Assert.AreEqual(6, count2);
        }