public void RethrowHttpRequestExceptionAfterAllAttempts() { this.MockHttpClientFixture.MockHandler.Protected() .SetupSequence <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .Throws(new HttpRequestException("Connection error 1")) .Throws(new HttpRequestException("Connection error 2")) .Throws(new HttpRequestException("Connection error 3")) .Throws(new StripeTestException("Unexpected invocation")); var service = new BalanceService(this.StripeClient); var exception = Assert.Throws <HttpRequestException>(() => service.Get()); Assert.NotNull(exception); Assert.Equal("Connection error 3", exception.Message); }
public void RetryOnTimeout() { this.MockHttpClientFixture.MockHandler.Protected() .SetupSequence <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .Throws(new OperationCanceledException("Timeout")) .Returns(Task.FromResult( new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}", Encoding.UTF8), })) .Throws(new StripeTestException("Unexpected invocation")); var service = new BalanceService(this.StripeClient); var balance = service.Get(); Assert.NotNull(balance); Assert.Equal(1, balance.StripeResponse.NumRetries); }
public async Task <IActionResult> GetFinancialAccount([FromRoute] Guid organizationId) { var account = await _financialAccountService .GetFinancialAccount(_agencyOwner); if (account == null) { return(NoContent()); } var service = new BalanceService(); var balance = service.Get(new RequestOptions() { StripeAccount = account.AccountId }); return(Ok(new { account, balance })); }