public static HttpResponseInspector AssertResponse(this HttpResponseInspector inspector, Func <HttpResponseMessage, string> errorSelector) { var response = inspector.Response; if (errorSelector.Invoke(response) is { } error) { throw new HttpResponseException(error); } return(inspector); }
public static HttpResponseInspector AssertStatusCode( this HttpResponseInspector inspector, HttpStatusCode status, Func <HttpResponseMessage, string> errorSelector = null) { var response = inspector.Response; if (response.StatusCode != status) { throw new HttpResponseException( errorSelector == null ? $"Expected status code {status} but found {response.StatusCode}" : errorSelector.Invoke(response)); } return(inspector); }
public static async Task <JObject> GetBodyAsJson(this HttpResponseInspector inspector, JsonSerializerSettings settings) { return(await inspector.GetBodyAsJson <JObject>(settings)); }
public static async Task <T> GetBodyAsJson <T>(this HttpResponseInspector inspector, JsonSerializerSettings settings) { return(JsonConvert.DeserializeObject <T>(await inspector.GetBodyAsync(), settings)); }
public static async Task <JObject> GetBodyAsJson(this HttpResponseInspector inspector) { return(await inspector.GetBodyAsJson <JObject>()); }
public static HttpResponseInspector AssertSuccessfulStatusCode(this HttpResponseInspector inspector) { inspector.Response.EnsureSuccessStatusCode(); return(inspector); }