public void AsPolicy_LoggerNull_Throws()
        {
            var retryConfig = new RetryConfig
            {
                DelaysInSeconds    = new List <double>(),
                JitterMilliseconds = 10,
                Retries            = 3
            };

            Assert.ThrowsException <ArgumentNullException>(
                () => retryConfig.AsTypeModel(null));
        }
        public void AsPolicy_NegativeJitter_Throws()
        {
            var logger      = new Mock <ILogger>(MockBehavior.Loose);
            var retryConfig = new RetryConfig
            {
                DelaysInSeconds    = new List <double>(),
                JitterMilliseconds = -10,
                Retries            = 3
            };

            Assert.ThrowsException <InvalidOperationException>(
                () => retryConfig.AsTypeModel(logger.Object));
        }
        public void AsPolicy_DelaysEmpty_RetriesZero_ReturnsForeverRetryPolicy()
        {
            var logger      = new Mock <ILogger>(MockBehavior.Loose);
            var retryConfig = new RetryConfig
            {
                DelaysInSeconds    = new List <double>(),
                JitterMilliseconds = 222,
                Retries            = 0
            };

            IAsyncPolicy <HttpResponseMessage> policy = retryConfig.AsTypeModel(logger.Object);

            Assert.IsNotNull(policy);
            Assert.IsInstanceOfType(policy, typeof(AsyncRetryPolicy <HttpResponseMessage>));
        }
        public void AsPolicy_TwoNegativeDelays_WithMinusOneFirst_Throws()
        {
            var logger      = new Mock <ILogger>(MockBehavior.Loose);
            var retryConfig = new RetryConfig
            {
                DelaysInSeconds = new List <double> {
                    -1.0d, -0.1d
                },
                JitterMilliseconds = 0,
                Retries            = 1
            };

            Assert.ThrowsException <InvalidOperationException>(
                () => retryConfig.AsTypeModel(logger.Object));
        }
        public void AsPolicy_RetriesLongerThanDelays_ReturnsRetryPolicy()
        {
            var logger      = new Mock <ILogger>(MockBehavior.Loose);
            var retryConfig = new RetryConfig
            {
                DelaysInSeconds = new List <double> {
                    2.0d
                },
                JitterMilliseconds = 0,
                Retries            = 5
            };

            IAsyncPolicy <HttpResponseMessage> policy = retryConfig.AsTypeModel(logger.Object);

            Assert.IsNotNull(policy);
            Assert.IsInstanceOfType(policy, typeof(AsyncRetryPolicy <HttpResponseMessage>));
        }
        public void AsPolicy_MinusOneDelay_NegativeRetries_ReturnsExponentialForeverRetryPolicy()
        {
            var logger      = new Mock <ILogger>(MockBehavior.Loose);
            var retryConfig = new RetryConfig
            {
                DelaysInSeconds = new List <double> {
                    -1.0d
                },
                JitterMilliseconds = 0,
                Retries            = -100
            };

            IAsyncPolicy <HttpResponseMessage> policy = retryConfig.AsTypeModel(logger.Object);

            Assert.IsNotNull(policy);
            Assert.IsInstanceOfType(policy, typeof(AsyncRetryPolicy <HttpResponseMessage>));
        }