public void CalculateDelay_without_XRateLimitReset()
        {
            // Arrange
            var maxAttempts           = 5;
            var mockSystemClock       = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
            var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
            var response = new HttpResponseMessage((HttpStatusCode)428);

            // Act
            var result = sendGridRetryStrategy.GetDelay(1, response);

            // Assert
            result.ShouldBe(TimeSpan.FromSeconds(1));
        }
        public void GetNextDelay_with_null_HttpHeaders()
        {
            // Arrange
            var maxAttempts           = 5;
            var mockSystemClock       = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
            var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
            var response = (HttpResponseMessage)null;

            // Act
            var result = sendGridRetryStrategy.GetDelay(1, response);

            // Assert
            result.ShouldBe(TimeSpan.FromSeconds(1));
        }
        public void ShouldRetry_returns_false_when_previous_response_is_null()
        {
            // Arrange
            var maxAttempts           = 5;
            var mockSystemClock       = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
            var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
            var response = (HttpResponseMessage)null;

            // Act
            var result = sendGridRetryStrategy.ShouldRetry(response);

            // Assert
            result.ShouldBeFalse();
        }
        public void ShouldRetry_returns_false_when_statuscode_not_429()
        {
            // Arrange
            var maxAttempts           = 5;
            var mockSystemClock       = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
            var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
            var response = new HttpResponseMessage(HttpStatusCode.BadGateway);

            // Act
            var result = sendGridRetryStrategy.ShouldRetry(response);

            // Assert
            result.ShouldBeFalse();
        }
        public void CalculateDelay_with_too_large_XRateLimitReset()
        {
            // Arrange
            var maxAttempts           = 5;
            var mockSystemClock       = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
            var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
            var response = new HttpResponseMessage((HttpStatusCode)428);

            response.Headers.Add("X-RateLimit-Reset", mockSystemClock.Object.UtcNow.AddHours(1).ToUnixTime().ToString());

            // Act
            var result = sendGridRetryStrategy.GetDelay(1, response);

            // Assert
            result.ShouldBe(TimeSpan.FromSeconds(5));
        }