コード例 #1
0
            public void StopsAfterFiveRetriesAndBubblesExceptionWhenResponseCode429()
            {
                // Act
                Func <Task> act = async() => await _policy.ExecuteAsync(() =>
                {
                    var exception = new TumblrException((HttpStatusCode)429);
                    throw exception;
                });

                // Assert
                act.Should().Throw <TumblrException>();
                _totalTimeSlept.Should().Be(67);
                _totalRetries.Should().Be(5);
            }
コード例 #2
0
            public void RetriesUntilSuccessWhenResponseCode429()
            {
                // Act
                Func <Task> act = async() => await _policy.ExecuteAsync(() =>
                {
                    if (_totalRetries == 3)
                    {
                        return(Task.FromResult(new PostAdapter(new BasePost {
                            Id = 12345
                        })));
                    }
                    var exception = new TumblrException((HttpStatusCode)429);
                    throw exception;
                });

                // Assert
                act.Should().NotThrow();
                _totalTimeSlept.Should().Be(17);
                _totalRetries.Should().Be(3);
            }