Example #1
0
        public void RetriableDocumentClientExceptionsShouldBeRetriedALimitedNumberOfTimes(int httpStatusCode, int maxRetries)
        {
            // Arrange
            var id = Guid.NewGuid();

            var repository = new Mock <IDocumentRepository>();

            repository.Setup(r => r.Get <string>(id)).ThrowsAsync(DocumentClientExceptionFactory.Create((HttpStatusCode)httpStatusCode));

            var options     = new RetryOptions(maxRetries);
            var stuffGetter = new RetriableGetStuff(repository.Object, options);

            // Act
            AsyncTestDelegate actor = async() => await stuffGetter.Get <string>(id);

            // Assert
            Assert.ThrowsAsync <DocumentClientException>(actor).StatusCode.Should().Be((HttpStatusCode)httpStatusCode);
            repository.Verify(r => r.Get <string>(id), Times.Exactly(maxRetries));
        }
Example #2
0
        public async Task DoNotRetrySuccessfulAttempts()
        {
            // Arramge
            var id       = Guid.NewGuid();
            var expected = "{ }";

            var repository = new Mock <IDocumentRepository>();

            repository.Setup(r => r.Get <string>(id)).ReturnsAsync(expected);

            var options     = new RetryOptions(5);
            var stuffGetter = new RetriableGetStuff(repository.Object, options);

            // Act
            var actual = await stuffGetter.Get <string>(id);

            // Assert
            actual.Should().Be(expected);
            repository.Verify(r => r.Get <string>(id), Times.Once);
        }
Example #3
0
        public async Task RetriableDocumentClientExceptionsShouldBeRetried(int httpStatusCode)
        {
            // Arrange
            var id       = Guid.NewGuid();
            var expected = "{ }";

            var repository = new Mock <IDocumentRepository>();

            repository.SetupSequence(r => r.Get <string>(id))
            .ThrowsAsync(DocumentClientExceptionFactory.Create((HttpStatusCode)httpStatusCode))
            .ReturnsAsync(expected);

            var options     = new RetryOptions(5);
            var stuffGetter = new RetriableGetStuff(repository.Object, options);

            // Act
            var actual = await stuffGetter.Get <string>(id);

            // Assert
            actual.Should().Be(expected);
            repository.Verify(r => r.Get <string>(id), Times.Exactly(2));
        }