示例#1
0
        public void TestReturnValue1()
        {
            int             count    = 0;
            Func <int, int> Multiply = x => { count++; return(checked (x * x)); };
            Func <int, int> Test     = x => x + x;
            var             res      = ToleranceLibrary.Retry <OverflowException, int, int>(Multiply, Test, 1000000, 3);

            Assert.AreEqual(count, 3);
        }
示例#2
0
        public void ExceptIsCathing2()
        {
            int    count  = 15;
            Action Devide = () => { count = count / 0; };
            Action Fix    = () => { count = 5; };

            ToleranceLibrary.Retry <DivideByZeroException>(Devide, Fix, 5);
            Assert.AreEqual(count, 5);
        }
示例#3
0
        public void MethodIsRepeating()
        {
            int    count = 0;
            Action Add   = () => { count++;
                                   var zero = 0;
                                   var curr = 10 / zero; };
            Action Fix = () => { return; };

            ToleranceLibrary.Retry <DivideByZeroException>(Add, Fix, 5);
            Assert.AreEqual(count, 5);
        }
示例#4
0
        public void PlanBIsWorking()
        {
            bool   flag     = false;
            Action Writting = () =>
            {
                using (StreamReader r = new StreamReader("file.txt"))
                {
                    var data = r.ReadToEnd();
                };
            };

            Action Another = () => flag = true;

            ToleranceLibrary.Retry <IOException>(Writting, Another, 3);
            Assert.AreEqual(flag, true);
        }