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
namestringThe 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
namestringThe non-empty header name to find. Header-name matching follows the case-insensitive HTTP header rules implemented by HttpHeaders.
expectedValuestringThe 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
expectedTThe value to serialize and compare structurally with the response body. JSON object-property order and insignificant whitespace do not affect the comparison.
optionsJsonSerializerOptionsSerialization options for
expected. When null, web defaults are used. The options object is read but not owned or mutated.cancellationTokenCancellationTokenCancels 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
TThe 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
expectedHttpStatusCodeThe 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.