Class HttpExchangeRecorder

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

Records HTTP exchanges without replacing the underlying transport. Add this handler to a real or in-memory client pipeline to snapshot requests, responses, and send failures. The owning HttpClient or caller remains responsible for disposing the handler.

public sealed class HttpExchangeRecorder : DelegatingHandler, IDisposable
Inheritance
HttpExchangeRecorder
Implements
Inherited Members
Extension Methods

Constructors

HttpExchangeRecorder(HttpExchangeSnapshotOptions?)

Creates a recorder with optional request and response capture settings.

public HttpExchangeRecorder(HttpExchangeSnapshotOptions? options = null)

Parameters

options HttpExchangeSnapshotOptions

Optional mutable capture options. null resolves the effective global or package defaults when the recorder is constructed.

Properties

CallCount

Gets the number of requests observed since construction or the last reset.

public int CallCount { get; }

Property Value

int

The count of recorded attempts, including requests still in progress and requests that failed while sending.

Options

Gets the options used to capture exchanges.

public HttpExchangeSnapshotOptions Options { get; }

Property Value

HttpExchangeSnapshotOptions

The mutable effective options resolved at construction. Configure them before sending requests and do not mutate them concurrently with capture.

Methods

CreateSnapshotsAsync(CancellationToken)

Creates stable snapshots for all exchanges in request order. A response body configured for capture remains {NotRead} until its replacement content is consumed.

public Task<IReadOnlyList<HttpExchangeSnapshot>> CreateSnapshotsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Token checked before snapshot creation. The default token does not cancel the operation.

Returns

Task<IReadOnlyList<HttpExchangeSnapshot>>

A completed task containing a new snapshot array. It throws when a send operation has not yet produced either a response or failure.

Reset()

Clears the recorder's current exchange list and resets CallCount to zero.

public HttpExchangeRecorder Reset()

Returns

HttpExchangeRecorder

This recorder instance for fluent reuse. Responses already returned to callers are not disposed or modified.

SendAsync(HttpRequestMessage, CancellationToken)

Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

Parameters

request HttpRequestMessage

The HTTP request message to send to the server.

cancellationToken CancellationToken

A cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

The request was null.

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.