public async Task <AssertableHttpResponse> SendAsync( HttpRequestMessage request, Action <HttpClient> preRequestConfigureHttpClientAction, bool ensureSuccessStatusCode = true) { preRequestConfigureHttpClientAction?.Invoke(_httpClient); var response = await _httpClient.SendAsync(request); var assertableResponse = new AssertableHttpResponse( response.StatusCode, await TryGetContentAsString(response.Content), response.Headers); if (_writeToTestOutput != null) { var sb = new StringBuilder(); sb.AppendLine("Request"); sb.AppendLine($"{request.Method} {request.RequestUri}"); sb.AppendLine($"Headers: {SerializeToJson(request.Headers)}"); sb.AppendLine(assertableResponse.ToString()); _writeToTestOutput(sb.ToString()); } if (ensureSuccessStatusCode) { assertableResponse.EnsureSuccessStatusCode(); } return(assertableResponse); }
public static async Task <AssertableHttpResponse> CreateAssertableResponseAsync( HttpResponseMessage response, string testOutput, bool ensureSuccessStatusCode, Action <string> testOutputWriter) { var assertableResponse = new AssertableHttpResponse( response.StatusCode, await response.Content.ReadAsStringAsync(), response.Headers); testOutputWriter?.Invoke($"{testOutput}{Environment.NewLine}Response:{Environment.NewLine}{assertableResponse}"); if (ensureSuccessStatusCode) { assertableResponse.EnsureSuccessStatusCode(); } return(assertableResponse); }
public GraphQLResponse(AssertableHttpResponse assertableHttpResponse) { _assertableHttpResponse = assertableHttpResponse ?? throw new ArgumentNullException(nameof(assertableHttpResponse)); }