Skip to content

Repository files navigation

aweXpect.Web

NugetBuildQuality Gate StatusCoverageMutation testing badge

Web extensions for aweXpect.

HttpRequestMessage

Method

You can verify, the method of the HttpRequestMessage:

varrequest=newHttpRequestMessage(HttpMethod.Get,"https://github.com/Testably/aweXpect.Web");awaitExpect.That(request).HasMethod(HttpMethod.Get);

Request URI

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"));

Header

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"));

Content

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.

HttpResponseMessage

Status

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();

Header

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"));

Content

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

Problem Details

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.

About

Web extensions for aweXpect

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

1 watching

Forks

Used by

Contributors

Languages