Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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);
        }