예제 #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);
 }