Class TestHttpResponseAssertions

Namespace
XBullet.EasyTesting.Hosting
Assembly
XBullet.EasyTesting.dll

Fluently verifies the response produced by a test scenario.

public sealed class TestHttpResponseAssertions
Inheritance
TestHttpResponseAssertions
Inherited Members

Methods

BeSuccessful()

Requires the response to have a successful status code.

public TestHttpResponseAssertions BeSuccessful()

Returns

TestHttpResponseAssertions

This assertion object so additional checks can be chained.

Exceptions

TestHttpResponseVerificationException

The response status code is outside the inclusive 200 through 299 range.

HaveHeader(string)

Requires the response or content headers to contain the supplied header.

public TestHttpResponseAssertions HaveHeader(string name)

Parameters

name string

The non-empty header name to find. Header-name matching follows the case-insensitive HTTP header rules implemented by HttpHeaders.

Returns

TestHttpResponseAssertions

This assertion object so additional checks can be chained.

Exceptions

TestHttpResponseVerificationException

Neither the response headers nor content headers contain name.

HaveHeader(string, string)

Requires the response or content headers to contain the supplied value.

public TestHttpResponseAssertions HaveHeader(string name, string expectedValue)

Parameters

name string

The non-empty header name to find. Header-name matching follows the case-insensitive HTTP header rules implemented by HttpHeaders.

expectedValue string

The exact non-null value required among the header's parsed values. Value comparison is ordinal and case-sensitive; an empty value is accepted.

Returns

TestHttpResponseAssertions

This assertion object so additional checks can be chained.

Exceptions

TestHttpResponseVerificationException

The header is absent or none of its values equals expectedValue.

HaveJsonBodyAsync<T>(T, JsonSerializerOptions?, CancellationToken)

Requires the response body to structurally equal the supplied JSON value.

public Task<TestHttpResponseAssertions> HaveJsonBodyAsync<T>(T expected, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default)

Parameters

expected T

The value to serialize and compare structurally with the response body. JSON object-property order and insignificant whitespace do not affect the comparison.

options JsonSerializerOptions

Serialization options for expected. When null, web defaults are used. The options object is read but not owned or mutated.

cancellationToken CancellationToken

Cancels reading the response content. Cancellation does not dispose or otherwise mutate the response. The default token does not request cancellation.

Returns

Task<TestHttpResponseAssertions>

A task whose result is this assertion object for further chaining.

Type Parameters

T

The type of value serialized to produce the expected JSON document.

Exceptions

TestHttpResponseVerificationException

The response body is invalid JSON or is structurally different from the expected JSON.

HaveStatusCode(HttpStatusCode)

Requires the response to have the supplied status code.

public TestHttpResponseAssertions HaveStatusCode(HttpStatusCode expected)

Parameters

expected HttpStatusCode

The exact HTTP status code required.

Returns

TestHttpResponseAssertions

This assertion object so additional checks can be chained.

Exceptions

TestHttpResponseVerificationException

The response has a different status code.