Class HttpResponseSnapshotExtensions
- Namespace
- XBullet.EasyTesting.Snapshots
- Assembly
- XBullet.EasyTesting.Snapshots.Core.dll
Built-in snapshot assertions for controller responses.
public static class HttpResponseSnapshotExtensions
- Inheritance
-
HttpResponseSnapshotExtensions
- Inherited Members
Methods
ShouldMatchControllerSnapshot(HttpResponseMessage, ControllerSnapshotOptions?, SnapshotSettings?, CancellationToken, string, string)
Asserts that a controller response matches its committed JSON snapshot.
public static Task ShouldMatchControllerSnapshot(this HttpResponseMessage response, ControllerSnapshotOptions? controllerOptions = null, SnapshotSettings? snapshotSettings = null, CancellationToken cancellationToken = default, string sourceFile = "", string testName = "")
Parameters
responseHttpResponseMessageThe caller-owned, non-null response to capture. It is read but not disposed.
controllerOptionsControllerSnapshotOptionsOptional capture and redaction options. null uses the effective global or default controller options.
snapshotSettingsSnapshotSettingsOptional snapshot settings. null uses the effective global or default settings.
cancellationTokenCancellationTokenToken that cancels response reading and snapshot file operations. The default token does not cancel the operation.
sourceFilestringCalling source-file path used to locate and name the snapshot. The compiler supplies this value by default.
testNamestringCalling member name used as the default snapshot name. The compiler supplies this value by default.
Returns
- Task
A task that completes when the captured response matches or is updated; a mismatch writes a received file and throws.
ShouldMatchHttpExchangeSnapshot(HttpResponseMessage, HttpExchangeSnapshotOptions?, SnapshotSettings?, CancellationToken, string, string)
Asserts that the complete request and response represented by an HTTP response match their committed snapshot. JSON is the default; the exchange options can select HTTP text or YAML.
public static Task ShouldMatchHttpExchangeSnapshot(this HttpResponseMessage response, HttpExchangeSnapshotOptions? exchangeOptions = null, SnapshotSettings? snapshotSettings = null, CancellationToken cancellationToken = default, string sourceFile = "", string testName = "")
Parameters
responseHttpResponseMessageThe caller-owned, non-null response to capture. It and its request and content objects are read but not disposed.
exchangeOptionsHttpExchangeSnapshotOptionsOptional capture, redaction, and format options. null uses recorder options when available, otherwise the effective global or default options; supplying different options for a recorded response is not accepted.
snapshotSettingsSnapshotSettingsOptional snapshot settings. null uses the effective global or default settings.
cancellationTokenCancellationTokenToken that cancels response reading and snapshot file operations. The default token does not cancel the operation.
sourceFilestringCalling source-file path used to locate and name the snapshot. The compiler supplies this value by default.
testNamestringCalling member name used as the default snapshot name. The compiler supplies this value by default.
Returns
- Task
A task that completes when the captured exchange matches or is updated; a mismatch writes a received file and throws.
ShouldMatchHttpExchangesSnapshot(HttpExchangeRecorder, SnapshotSettings?, CancellationToken, string, string)
Asserts that all exchanges captured by a recorder match their committed snapshot.
public static Task ShouldMatchHttpExchangesSnapshot(this HttpExchangeRecorder recorder, SnapshotSettings? snapshotSettings = null, CancellationToken cancellationToken = default, string sourceFile = "", string testName = "")
Parameters
recorderHttpExchangeRecorderThe caller-owned, non-null recorder whose completed exchanges are captured in call order. It is not reset or disposed.
snapshotSettingsSnapshotSettingsOptional snapshot settings. null uses the effective global or default settings.
cancellationTokenCancellationTokenToken checked before capture and used by snapshot file operations. The default token does not cancel the operation.
sourceFilestringCalling source-file path used to locate and name the snapshot. The compiler supplies this value by default.
testNamestringCalling member name used as the default snapshot name. The compiler supplies this value by default.
Returns
- Task
A task that completes when all captured exchanges match or are updated; it throws if a call is incomplete or a snapshot differs.
ShouldMatchJsonBodySnapshot(HttpResponseMessage, SnapshotSettings?, CancellationToken, string, string)
Asserts that the JSON body of an HTTP response matches its committed
.verified.json snapshot.
public static Task ShouldMatchJsonBodySnapshot(this HttpResponseMessage response, SnapshotSettings? snapshotSettings = null, CancellationToken cancellationToken = default, string sourceFile = "", string testName = "")
Parameters
responseHttpResponseMessageThe caller-owned, non-null response whose content is read. Neither the response nor its content is disposed.
snapshotSettingsSnapshotSettingsOptional snapshot settings. null uses the effective global or default settings.
cancellationTokenCancellationTokenToken that cancels content reading and snapshot file operations. The default token does not cancel the operation.
sourceFilestringCalling source-file path used to locate and name the snapshot. The compiler supplies this value by default.
testNamestringCalling member name used as the default snapshot name. The compiler supplies this value by default.
Returns
- Task
A task that completes when the normalized JSON body matches or is updated; a mismatch writes a received file and throws.
ShouldMatchJsonSnapshot(HttpContent, SnapshotSettings?, CancellationToken, string, string)
Asserts that JSON HTTP content matches its committed .verified.json snapshot.
The content is parsed and normalized with System.Text.Json before comparison.
public static Task ShouldMatchJsonSnapshot(this HttpContent content, SnapshotSettings? snapshotSettings = null, CancellationToken cancellationToken = default, string sourceFile = "", string testName = "")
Parameters
contentHttpContentThe caller-owned, non-null HTTP content to read. It is not disposed; a seekable content stream has its position restored, while a non-seekable stream is consumed.
snapshotSettingsSnapshotSettingsOptional snapshot settings. null uses the effective global or default settings.
cancellationTokenCancellationTokenToken that cancels content reading and snapshot file operations. The default token does not cancel the operation.
sourceFilestringCalling source-file path used to locate and name the snapshot. The compiler supplies this value by default.
testNamestringCalling member name used as the default snapshot name. The compiler supplies this value by default.
Returns
- Task
A task that completes when the normalized JSON matches or is updated; a mismatch writes a received file and throws.