Skip to content

About

Web extensions for aweXpect

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

190 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aweXpect.Web

Nuget Build Quality Gate Status Coverage Mutation testing badge

Expectations for HttpRequestMessage, HttpResponseMessage, Uri and IPAddress for aweXpect.

At a glance

HttpResponseMessage response = await httpClient.GetAsync("https://music.example.com/tracks/1");

// verify the status code, either the exact value or its category
await Expect.That(response).HasStatusCode().Success();

// verify the media type and the headers of the response
await Expect.That(response).HasContentType("application/json");
await Expect.That(response).HasHeader("Cache-Control").WithValue("must-revalidate, max-age=0, private");

// verify the content of the response
await Expect.That(response).HasContent("*Let It Be*").AsWildcard();

A failing expectation on a request or response includes the formatted HTTP request and response. If the test server returned the track, HasStatusCode(HttpStatusCode.NotFound) would fail with:

Expected that response
has status code 404 NotFound,
but it had status code 200 OK

HTTP-Request:
  GET http://localhost/tracks/1 HTTP/1.1

HTTP-Response:
  200 OK HTTP/1.1
    x-vendor: VENDOR
    Content-Type: application/json; charset=utf-8
    Content-Length: 51
  {
    "id": 1,
    "title": "Let It Be",
    "artist": "The Beatles"
  }

Overview

Expectations for HttpRequestMessage:

Expectation Negated Summary
HasMethod DoesNotHaveMethod has the expected HTTP method
HasRequestUri DoesNotHaveRequestUri has the expected request URI
HasHeader DoesNotHaveHeader has a header, optionally with a value
HasContent DoesNotHaveContent has the expected string content

Expectations for HttpResponseMessage:

Expectation Negated Summary
HasStatusCode HasStatusCode().DifferentTo has the expected status code or status category
HasHeader DoesNotHaveHeader has a header, optionally with a value
HasContentType DoesNotHaveContentType has the expected media type
HasContent DoesNotHaveContent has the expected string content
HasProblemDetailsContent DoesNotComplyWith has a ProblemDetails content
HasRequestMessage the request message meets nested expectations

Expectations for Uri:

Expectation Negated Summary
IsAbsolute IsNotAbsolute an absolute URI
IsFile IsNotFile a file URI
IsLoopback IsNotLoopback references the local host
IsUnc IsNotUnc a UNC path
HasDefaultPort DoesNotHaveDefaultPort uses the default port of its scheme
HasPort negated comparison has the expected port
HasScheme negated comparison has the expected scheme
HasHost negated comparison has the expected host
HasPath negated comparison has the expected path
HasFragment negated comparison has the expected fragment
IsBaseOf IsNotBaseOf a base URI of the expected URI
HasQueryParameter DoesNotHaveQueryParameter has a query parameter, optionally with a value

Expectations for IPAddress:

Expectation Negated Summary
IsIPv4 IsNotIPv4 an IPv4 address
IsIPv6 IsNotIPv6 an IPv6 address
IsLoopback IsNotLoopback a loopback address
IsInSubnet IsNotInSubnet in the expected subnet
IsEqualTo IsNotEqualTo equal to the expected address, optionally ignoring mapping

Documentation

The full documentation is available at docs.testably.org:

  • HTTP requests and responses: method, request URI, headers and content of an HttpRequestMessage, and status code, headers, content type, content, problem details and the request message of an HttpResponseMessage
  • URIs: kind, port, scheme, host, path, fragment, base URI and query parameters of a Uri
  • IP addresses: IPv4, IPv6, loopback, subnet membership and equality of an IPAddress
  • Customization: formatting the request and response content in failure messages

About

Web extensions for aweXpect

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

1 watching

Forks

Used by

Contributors

Languages