public void TryMultipleExceptions_Failed_ThrowsException()
        {
            int    count  = 0;
            Action action = () =>
            {
                count++;
                if (count == 1)
                {
                    throw new NotImplementedException();
                }
                else if (count == 2)
                {
                    throw new ArithmeticException();
                }
                else
                {
                    throw new ArgumentException();
                }
            };

            var exceptions = new List <Type> {
                typeof(NotImplementedException), typeof(ArithmeticException), typeof(ArgumentException)
            };

            Assert.Throws <ArgumentException>(() => FaultTolerance.Try(exceptions, action, 3));
        }
Exemple #2
0
        public void Try_indexOutOfRangeEx_true()
        {
            Action action = () => throw new IndexOutOfRangeException();

            FaultTolerance faultTolerance = new FaultTolerance();

            Assert.ThrowsException <IndexOutOfRangeException>(() => faultTolerance.Try(action, 2));
        }
        public void Try_NotAllTypesDerivedFromException_ThrowsArgumentException()
        {
            Action action = () => { };

            var exceptions = new List <Type> {
                typeof(int), typeof(Exception)
            };

            Assert.Throws <ArgumentException>(() => FaultTolerance.Try(exceptions, action, -1));
        }
        public void Try_Succeed_NoExceptionThrown()
        {
            int    count  = 1;
            Action action = () =>
            {
                if (count < 3)
                {
                    count++;
                    throw new ArithmeticException();
                }
            };

            FaultTolerance.Try <ArithmeticException>(action, 3);
        }
Exemple #5
0
        public void Try_Square_true()
        {
            Random rand     = new Random();
            int    actual   = rand.Next(100);
            int    expected = actual * actual;
            Action action   = () =>
            {
                actual *= actual;
            };
            FaultTolerance faultTolerance = new FaultTolerance();

            faultTolerance.Try(action, 1);

            Assert.AreEqual(expected, actual);
        }
        public void TryCountTimes_ActionRunsCountTimes()
        {
            int actual = 0;

            Action action = () =>
            {
                actual++;
                if (actual < 3)
                {
                    throw new NotImplementedException();
                }
            };

            int expected = 3;

            FaultTolerance.Try <NotImplementedException>(action, 3);

            Assert.Equal(expected, actual);
        }
        public void TryMultipleExceptions_Succeed_NoExceptionThrown()
        {
            int    count  = 0;
            Action action = () =>
            {
                count++;
                if (count == 1)
                {
                    throw new NotImplementedException();
                }
                else if (count == 2)
                {
                    throw new ArithmeticException();
                }
            };

            var exceptions = new List <Type> {
                typeof(NotImplementedException), typeof(ArithmeticException)
            };

            FaultTolerance.Try(exceptions, action, 3);
        }
        public void Try_Failed_ThrowException()
        {
            Action action = () => throw new NotImplementedException();

            Assert.Throws <NotImplementedException>(() => FaultTolerance.Try <NotImplementedException>(action, 2));
        }
        public void Try_NonPositiveCount_ThrowsArgumentException()
        {
            Action action = () => { };

            Assert.Throws <ArgumentException>(() => FaultTolerance.Try <Exception>(action, -1));
        }