public void TestShouldRetry()

in DarabonbaUnitTests/CoreTest.cs [279:425]


        public void TestShouldRetry()
        {
            var backoffPolicy = new ExponentialBackoffPolicy(2, 60 * 1000);

            var retryCondition1 = new RetryCondition
            {
                MaxAttempts = 1,
                Backoff = backoffPolicy,
                Exception = new List<string> { "AException" },
                ErrorCode = new List<string> { "BExceptionCode" }
            };

            var retryCondition2 = new RetryCondition
            {
                MaxAttempts = 2,
                Backoff = backoffPolicy,
                Exception = new List<string> { "AException", "CException" }
            };

            var retryCondition3 = new RetryCondition
            {
                Exception = new List<string> { "BException" }
            };

            var retryPolicyContext = new RetryPolicyContext
            {
                RetriesAttempted = 0,
                Exception = new AException
                {
                    Message = "AException",
                    Code = "AExceptionCode"
                }
            };

            Assert.True(Core.ShouldRetry(null, retryPolicyContext));

            retryPolicyContext = new RetryPolicyContext
            {
                RetriesAttempted = 1,
                Exception = new AException
                {
                    Message = "AException",
                    Code = "AExceptionCode"
                }
            };

            Assert.False(Core.ShouldRetry(null, retryPolicyContext));

            var retryOptions = new RetryOptions
            {
                Retryable = false,
                RetryCondition = null,
                NoRetryCondition = null
            };

            Assert.False(Core.ShouldRetry(retryOptions, retryPolicyContext));

            retryOptions = new RetryOptions
            {
                Retryable = true,
                RetryCondition = null,
                NoRetryCondition = null
            };

            Assert.False(Core.ShouldRetry(retryOptions, retryPolicyContext));

            retryOptions = new RetryOptions
            {
                Retryable = true,
                RetryCondition = new List<RetryCondition> { retryCondition1, retryCondition2 },
                NoRetryCondition = new List<RetryCondition> { retryCondition3 }
            };

            Assert.True(Core.ShouldRetry(retryOptions, retryPolicyContext));

            retryPolicyContext = new RetryPolicyContext
            {
                RetriesAttempted = 2,
                Exception = new AException
                {
                    Message = "AException",
                    Code = "AExceptionCode"
                }
            };

            Assert.False(Core.ShouldRetry(retryOptions, retryPolicyContext));

            retryPolicyContext = new RetryPolicyContext
            {
                RetriesAttempted = 0,
                Exception = new BException
                {
                    Message = "BException",
                    Code = "BExceptionCode"
                }
            };

            Assert.True(Core.ShouldRetry(retryOptions, retryPolicyContext));

            retryPolicyContext = new RetryPolicyContext
            {
                RetriesAttempted = 1,
                Exception = new BException
                {
                    Message = "BException",
                    Code = "BExceptionCode"
                }
            };

            Assert.False(Core.ShouldRetry(retryOptions, retryPolicyContext));

            retryPolicyContext = new RetryPolicyContext
            {
                RetriesAttempted = 1,
                Exception = new CException
                {
                    Message = "CException",
                    Code = "CExceptionCode"
                }
            };

            Assert.True(Core.ShouldRetry(retryOptions, retryPolicyContext));

            retryPolicyContext = new RetryPolicyContext
            {
                RetriesAttempted = 2,
                Exception = new CException
                {
                    Message = "CException",
                    Code = "CExceptionCode"
                }
            };

            Assert.True(Core.ShouldRetry(retryOptions, retryPolicyContext));

            retryPolicyContext = new RetryPolicyContext
            {
                RetriesAttempted = 3,
                Exception = new CException
                {
                    Message = "CException",
                    Code = "CExceptionCode"
                }
            };

            Assert.False(Core.ShouldRetry(retryOptions, retryPolicyContext));
        }