public async Task RequestStreamingAsync_OkResponse_InvalidJson() { var streamedResponse = new StripeStreamedResponse( HttpStatusCode.OK, null, StringToStream("this isn't JSON")); this.httpClient.StreamedResponse = streamedResponse; var stream = await this.stripeClient.RequestStreamingAsync( HttpMethod.Post, "/v1/charges", this.options, this.requestOptions); Assert.NotNull(stream); Assert.Equal("this isn't JSON", StreamToString(stream)); }
public async Task RequestStreamingAsync_Error_InvalidErrorObject() { var streamedResponse = new StripeStreamedResponse( HttpStatusCode.InternalServerError, null, StringToStream("{}")); this.httpClient.StreamedResponse = streamedResponse; var exception = await Assert.ThrowsAsync <StripeException>(async() => await this.stripeClient.RequestStreamingAsync( HttpMethod.Post, "/v1/charges", this.options, this.requestOptions)); Assert.NotNull(exception); Assert.Equal(HttpStatusCode.InternalServerError, exception.HttpStatusCode); Assert.Equal("Invalid response object from API: \"{}\"", exception.Message); Assert.Equal(await streamedResponse.ToStripeResponseAsync(), exception.StripeResponse); }
public async Task RequestStreamingAsync_OAuthError() { var streamedResponse = new StripeStreamedResponse( HttpStatusCode.BadRequest, null, StringToStream("{\"error\": \"invalid_request\"}")); this.httpClient.StreamedResponse = streamedResponse; var exception = await Assert.ThrowsAsync <StripeException>(async() => await this.stripeClient.RequestStreamingAsync( HttpMethod.Post, "/oauth/token", this.options, this.requestOptions)); Assert.NotNull(exception); Assert.Equal(HttpStatusCode.BadRequest, exception.HttpStatusCode); Assert.Equal("invalid_request", exception.StripeError.Error); Assert.Equal(await streamedResponse.ToStripeResponseAsync(), exception.StripeResponse); }
public async Task RequestStreamingAsync_ApiError() { var streamedResponse = new StripeStreamedResponse( HttpStatusCode.PaymentRequired, null, StringToStream("{\"error\": {\"type\": \"card_error\"}}")); this.httpClient.StreamedResponse = streamedResponse; var exception = await Assert.ThrowsAsync <StripeException>(async() => await this.stripeClient.RequestStreamingAsync( HttpMethod.Post, "/v1/charges", this.options, this.requestOptions)); Assert.NotNull(exception); Assert.Equal(HttpStatusCode.PaymentRequired, exception.HttpStatusCode); Assert.Equal("card_error", exception.StripeError.Type); Assert.Equal(await streamedResponse.ToStripeResponseAsync(), exception.StripeResponse); }