Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 public static async Task <JObject> GetBodyAsJson(this HttpResponseInspector inspector, JsonSerializerSettings settings)
 {
     return(await inspector.GetBodyAsJson <JObject>(settings));
 }
Пример #4
0
 public static async Task <T> GetBodyAsJson <T>(this HttpResponseInspector inspector, JsonSerializerSettings settings)
 {
     return(JsonConvert.DeserializeObject <T>(await inspector.GetBodyAsync(), settings));
 }
Пример #5
0
 public static async Task <JObject> GetBodyAsJson(this HttpResponseInspector inspector)
 {
     return(await inspector.GetBodyAsJson <JObject>());
 }
Пример #6
0
 public static HttpResponseInspector AssertSuccessfulStatusCode(this HttpResponseInspector inspector)
 {
     inspector.Response.EnsureSuccessStatusCode();
     return(inspector);
 }