示例#1
0
        public async Task Retry_RetryUntilFailure()
        {
            FaultyClass faultyClass = new FaultyClass()
            {
                ExceptionToThrow  = new ArgumentNullException(),
                TriesUntilSuccess = 12
            };

            var result = await Retry.Run(
                task : () => faultyClass.FaultyTask(),
                retryExceptionHandler : (ex, ct) => faultyClass.ExceptionHandler(ex, ct));
        }
示例#2
0
        public async Task Retry_NoRetryWhenTaskSucceeds()
        {
            FaultyClass faultyClass = new FaultyClass()
            {
                ExceptionToThrow = null
            };

            var result = await Retry.Run(
                task : () => faultyClass.FaultyTask(),
                retryExceptionHandler : (ex, ct) => faultyClass.ExceptionHandler(ex, ct));

            Assert.IsNull(faultyClass.ExceptionReceived);
            Assert.AreEqual(1, faultyClass.CallCount);
        }
示例#3
0
        public async Task Retry_RetryThenSucceed()
        {
            FaultyClass faultyClass = new FaultyClass()
            {
                ExceptionToThrow  = new ArgumentNullException(),
                TriesUntilSuccess = 3
            };

            var result = await Retry.Run(
                task : () => faultyClass.FaultyTask(),
                retryExceptionHandler : (ex, ct) => faultyClass.ExceptionHandler(ex, ct));

            Assert.IsNotNull(faultyClass.ExceptionReceived);
            Assert.AreEqual(3, faultyClass.CallCount);
        }