Web extensions for aweXpect.
You can verify, the method of the HttpRequestMessage:
varrequest=newHttpRequestMessage(HttpMethod.Get,"https://github.com/Testably/aweXpect.Web");awaitExpect.That(request).HasMethod(HttpMethod.Get);You can verify, the request URI of the HttpRequestMessage:
varrequest=newHttpRequestMessage(HttpMethod.Get,"https://github.com/Testably/aweXpect.Web");awaitExpect.That(request).HasRequestUri("https://github.com/Testably/aweXpect.Web");awaitExpect.That(request).HasRequestUri(newUri("https://github.com/Testably/aweXpect.Web"));You can verify the headers of the HttpRequestMessage:
HttpRequestMessagerequest=newHttpRequestMessage(HttpMethod.Get,"https://github.com/Testably/aweXpect.Web");// Add headersawaitExpect.That(request).HasHeader("X-GitHub-Request-Id");awaitExpect.That(request).HasHeader("Cache-Control").WithValue("must-revalidate, max-age=0, private");awaitExpect.That(request).DoesNotHaveHeader("X-My-Header");You can also add additional expectations on the header value(s):
HttpRequestMessagerequest=newHttpRequestMessage(HttpMethod.Get,"https://github.com/Testably/aweXpect.Web");// Add headersawaitExpect.That(request).HasHeader("X-GitHub-Request-Id").WhoseValue(value =>value.IsNotEmpty());awaitExpect.That(request).HasHeader("Vary").WhoseValues(values =>values.Contains("Turbo-Frame"));You can verify, the content of the HttpRequestMessage:
varrequest=newHttpRequestMessage(HttpMethod.Post,"https://github.com/Testably/aweXpect.Web"){Content=newStringContent("my aweXpect content")};awaitExpect.That(request).HasContent("*aweXpect*").AsWildcard();You can use the same configuration options as when comparing strings.
You can verify the status code of the HttpResponseMessage:
HttpResponseMessageresponse=awaithttpClient.GetAsync("https://github.com/Testably/aweXpect.Web");awaitExpect.That(response).HasStatusCode().Success();awaitExpect.That(response).HasStatusCode(HttpStatusCode.OK);response=awaithttpClient.PostAsync("https://github.com/Testably/aweXpect.Web",newStringContent(""));awaitExpect.That(response).HasStatusCode().ClientError().Or.HasStatusCode().ServerError().Or.HasStatusCode().Redirection();You can verify the headers of the HttpResponseMessage:
HttpResponseMessageresponse=awaithttpClient.GetAsync("https://github.com/Testably/aweXpect.Web");awaitExpect.That(response).HasHeader("X-GitHub-Request-Id");awaitExpect.That(response).HasHeader("Cache-Control").WithValue("must-revalidate, max-age=0, private");awaitExpect.That(response).DoesNotHaveHeader("X-My-Header");You can also add additional expectations on the header value(s):
HttpResponseMessageresponse=awaithttpClient.GetAsync("https://github.com/Testably/aweXpect.Web");awaitExpect.That(response).HasHeader("X-GitHub-Request-Id").WhoseValue(value =>value.IsNotEmpty());awaitExpect.That(response).HasHeader("Vary").WhoseValues(values =>values.Contains("Turbo-Frame"));You can verify, the content of the HttpResponseMessage:
HttpResponseMessageresponse=awaithttpClient.GetAsync("https://github.com/Testably/aweXpect");awaitExpect.That(response).HasContent("*aweXpect*").AsWildcard();You can use the same configuration options as when comparing strings.
Great care was taken to provide as much information as possible, when a status verification failed.
The response could look similar to:
Expected that response has success status code (2xx), but it was 404 NotFound HTTP-Request: GET https://github.com/Testably/missing-repo HTTP/1.1 HTTP-Response: 404 NotFound HTTP/1.1 Server: GitHub.com Date: Fri, 29 Nov 2024 07:55:47 GMT Cache-Control: no-cache Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin X-GitHub-Request-Id: DB30:24038B:287F716:29D98BD:67497384 Content is binary
You can verify that the content contains a valid ProblemDetails object:
HttpResponseMessageresponse=// a call that returns a problem details objectawaitExpect.That(response).HasProblemDetailsContent("https://httpstatuses.com/404").WithTitle("Error: Not Found").WithStatus(404).WithInstance("93c8f977-7ff7-46ed-900f-7b6264624a31");For all string values you can use the same configuration options as when comparing strings.