Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }