Exemplo n.º 1
0
        public void TestSuccessfulProcedure()
        {
            var proc = new UnreliableProcedure(0);
            int failedAttempts;

            Procedure.Retry(() => proc.DoWork(), out failedAttempts, attempts: 5);
            Assert.AreEqual(0, failedAttempts);
        }
Exemplo n.º 2
0
        public void TestSuccessfulAsyncProcedure()
        {
            var proc = new UnreliableProcedure(3);

            Assert.DoesNotThrow(async() =>
            {
                await Procedure.RetryAsync(proc.DoWork, attempts: 5);
            });
        }
Exemplo n.º 3
0
        public void TestFailedAsyncProcedure()
        {
            var proc = new UnreliableProcedure(10);

            Assert.Throws(typeof(Exception), async() =>
            {
                await Procedure.RetryAsync(proc.DoWork, attempts: 5);
            });
        }
Exemplo n.º 4
0
        public void TestSuccessfulProcedureWithReturn()
        {
            var    proc = new UnreliableProcedure(0);
            string returned;
            int    failedAttempts;

            returned = Procedure.Retry <string>(() => proc.DoWorkAndReturn(), out failedAttempts, attempts: 5);
            Assert.AreEqual(0, failedAttempts);
            Assert.AreEqual("success", returned);
        }
Exemplo n.º 5
0
        public void TestSuccessAfterFailure()
        {
            var proc           = new UnreliableProcedure(3);
            int failedAttempts = -1;

            Assert.DoesNotThrow(() =>
            {
                Procedure.Retry(() => proc.DoWork(), out failedAttempts, attempts: 5);
            });
            Assert.AreEqual(3, failedAttempts);
        }
Exemplo n.º 6
0
        public void TestFailedProcedure()
        {
            var proc           = new UnreliableProcedure(10);
            int failedAttempts = -1;

            Assert.Throws(typeof(Exception), () =>
            {
                Procedure.Retry(() => proc.DoWork(), out failedAttempts, attempts: 5);
            });
            Assert.AreEqual(5, failedAttempts);
        }
Exemplo n.º 7
0
        public void TestSuccessAfterFailureWithReturn()
        {
            var    proc           = new UnreliableProcedure(3);
            int    failedAttempts = -1;
            string returned       = null;

            Assert.DoesNotThrow(() =>
            {
                returned = Procedure.Retry <string>(() => proc.DoWorkAndReturn(), out failedAttempts, attempts: 5);
            });
            Assert.AreEqual(3, failedAttempts);
            Assert.AreEqual("success", returned);
        }
Exemplo n.º 8
0
        public void TestFailedProcedureWithReturn()
        {
            var    proc           = new UnreliableProcedure(10);
            int    failedAttempts = -1;
            string returned       = null;

            Assert.Throws(typeof(Exception), () =>
            {
                returned = Procedure.Retry <string>(() => proc.DoWorkAndReturn(), out failedAttempts, attempts: 5);
            });
            Assert.AreEqual(5, failedAttempts);
            Assert.IsNull(returned);
        }
Exemplo n.º 9
0
        public void TestSuccessfulAsyncProcedureWithReturn()
        {
            var    proc     = new UnreliableProcedure(0);
            string returned = null;

            Assert.DoesNotThrow(() =>
            {
                returned = Task.Run <string>(async() =>
                {
                    return(await Procedure.RetryAsync <string>(() => proc.DoWorkAndReturn(), attempts: 5));
                }).Result;
            });

            Assert.AreEqual("success", returned);
        }
Exemplo n.º 10
0
        public void TestFailedProcedureWithTimeInBetween()
        {
            var proc               = new UnreliableProcedure(10);
            int failedAttempts     = -1;
            int milliSecondsToWait = 50;
            var startTime          = DateTime.Now;

            Assert.Throws(typeof(Exception), () =>
            {
                Procedure.Retry(() => proc.DoWork(), out failedAttempts, attempts: 5, wait: new TimeSpan(0, 0, 0, 0, milliSecondsToWait));
            });
            var endTime     = DateTime.Now;
            var elapsedTime = endTime - startTime;

            Assert.GreaterOrEqual(elapsedTime.Milliseconds, milliSecondsToWait * (failedAttempts - 1));
        }
Exemplo n.º 11
0
        public void TestFailedAsyncProcedureWithReturn()
        {
            var    proc     = new UnreliableProcedure(10);
            string returned = null;

            var exception = Assert.Throws <AggregateException>(() =>
            {
                returned = Task.Run <string>(async() =>
                {
                    return(await Procedure.RetryAsync <string>(() => proc.DoWorkAndReturn(), attempts: 5));
                }).Result;
            });

            Assert.AreEqual("Procedure failed", exception.InnerException.Message);
            Assert.IsNull(returned);
        }