Beispiel #1
0
        public async Task FixedCountThrowsExceptionWhenAllRetriesSpend()
        {
            var fetcher = new Mock <Base.Http.Fetcher.IFetcher>();
            var request = new Mock <Base.Http.IRequest>();

            fetcher.Setup(t => t.ExecuteAsync(It.IsAny <Base.Http.IRequest>()))
            .ThrowsAsync(new Base.Http.Exception.HttpException("test"));

            var policy = new Base.Http.Retry.FixedCountPolicy(1);
            await Assert.ThrowsAsync <Base.Http.Exception.NoRetriesLeftException>(
                () => policy.GetResponse(fetcher.Object, request.Object)
                );
        }
        public async Task FixedCountReturnResultForSuccessWithoutRetries()
        {
            var fetcher  = new Mock <Base.Http.Fetcher.IFetcher>();
            var request  = new Mock <Base.Http.IRequest>();
            var response = new Mock <Base.Http.IResponse>();

            fetcher.Setup(t => t.ExecuteAsync(It.IsAny <Base.Http.IRequest>())).ReturnsAsync(response.Object);

            var policy = new Base.Http.Retry.FixedCountPolicy(1);
            var result = await policy.GetResponse(fetcher.Object, request.Object);

            Assert.Equal(result, response.Object);
        }
        public async Task FixedCountMultipleAttemptsGiveResult()
        {
            var fetcher  = new Mock <Base.Http.Fetcher.IFetcher>();
            var request  = new Mock <Base.Http.IRequest>();
            var response = new Mock <Base.Http.IResponse>();

            fetcher.SetupSequence(t => t.ExecuteAsync(It.IsAny <Base.Http.IRequest>()))
            .ThrowsAsync(new Base.Http.Exception.HttpException("test"))
            .ThrowsAsync(new Base.Http.Exception.HttpException("test"))
            .Returns(Task.FromResult(response.Object));

            var policy = new Base.Http.Retry.FixedCountPolicy(3);
            var result = await policy.GetResponse(fetcher.Object, request.Object);

            Assert.Equal(result, response.Object);
        }