Class ControllerResponseSnapshot

Namespace
XBullet.EasyTesting.Snapshots
Assembly
XBullet.EasyTesting.Snapshots.Core.dll

A stable representation of an HTTP controller response for snapshot assertions.

public sealed record ControllerResponseSnapshot : IEquatable<ControllerResponseSnapshot>
Inheritance
ControllerResponseSnapshot
Implements
Inherited Members

Constructors

ControllerResponseSnapshot(ControllerRequestSnapshot?, int, string?, IReadOnlyDictionary<string, string[]>, object?)

A stable representation of an HTTP controller response for snapshot assertions.

public ControllerResponseSnapshot(ControllerRequestSnapshot? Request, int StatusCode, string? ReasonPhrase, IReadOnlyDictionary<string, string[]> Headers, object? Body)

Parameters

Request ControllerRequestSnapshot

Captured request context, or null when request capture is disabled or no request is associated with the response.

StatusCode int

Numeric HTTP status code.

ReasonPhrase string

HTTP reason phrase, or null when none is supplied.

Headers IReadOnlyDictionary<string, string[]>

Captured headers, or an empty case-insensitive dictionary when header capture is disabled.

Body object

Captured JSON, text, or base64 binary body, or null when body capture is disabled or the body is empty.

Properties

Body

Captured JSON, text, or base64 binary body, or null when body capture is disabled or the body is empty.

public object? Body { get; init; }

Property Value

object

Headers

Captured headers, or an empty case-insensitive dictionary when header capture is disabled.

public IReadOnlyDictionary<string, string[]> Headers { get; init; }

Property Value

IReadOnlyDictionary<string, string[]>

ReasonPhrase

HTTP reason phrase, or null when none is supplied.

public string? ReasonPhrase { get; init; }

Property Value

string

Request

Captured request context, or null when request capture is disabled or no request is associated with the response.

public ControllerRequestSnapshot? Request { get; init; }

Property Value

ControllerRequestSnapshot

StatusCode

Numeric HTTP status code.

public int StatusCode { get; init; }

Property Value

int

Methods

FromResponseAsync(HttpResponseMessage, ControllerSnapshotOptions?, CancellationToken)

Creates a deterministic snapshot model from an HTTP response.

public static Task<ControllerResponseSnapshot> FromResponseAsync(HttpResponseMessage response, ControllerSnapshotOptions? options = null, CancellationToken cancellationToken = default)

Parameters

response HttpResponseMessage

The caller-owned, non-null response to capture. It and its request and content are read but not disposed.

options ControllerSnapshotOptions

Optional capture and redaction options. null uses the effective global or default controller options.

cancellationToken CancellationToken

Token that cancels response-content reading. The default token does not cancel the operation.

Returns

Task<ControllerResponseSnapshot>

A task whose result is a new deterministic controller-response snapshot with configured redaction applied.