Class SnapshotAssert

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

Framework-independent file snapshot assertions.

public static class SnapshotAssert
Inheritance
SnapshotAssert
Inherited Members

Remarks

Start with snapshot testing, then review stabilization and maintenance.

Methods

AcceptReceived(string)

Promotes one received snapshot file to its verified counterpart, replacing an existing verified file.

public static string AcceptReceived(string receivedPath)

Parameters

receivedPath string

Absolute or current-directory-relative path to an existing file whose name contains .received. followed by a runtime qualifier and file extension.

Returns

string

The full path of the verified file. The received file is moved and no longer exists at its original path.

MatchAsync(object?, SnapshotSettings?, CancellationToken, string, string)

Serializes a value and compares it with its committed .verified.json snapshot. A runtime-qualified received file is written when the snapshot is new or differs.

public static Task MatchAsync(object? actual, SnapshotSettings? settings = null, CancellationToken cancellationToken = default, string sourceFile = "", string testName = "")

Parameters

actual object

The value to serialize. May be null, which is serialized as JSON null.

settings SnapshotSettings

Optional snapshot settings. null uses the effective global or default settings.

cancellationToken CancellationToken

Token that cancels snapshot file locking and asynchronous file I/O. The default token does not cancel the operation.

sourceFile string

Calling source-file path used to locate and name the snapshot. The compiler supplies this value by default; it must not be empty.

testName string

Calling member name used as the default snapshot name. The compiler supplies this value by default.

Returns

Task

A task that completes after a match or an allowed automatic update; otherwise it writes a received file and throws SnapshotMismatchException.

MatchJsonAsync(string, SnapshotSettings?, CancellationToken, string, string)

Parses JSON content with JsonDocument and compares its normalized JSON representation with a committed .verified.json snapshot.

public static Task MatchJsonAsync(string actualJson, SnapshotSettings? settings = null, CancellationToken cancellationToken = default, string sourceFile = "", string testName = "")

Parameters

actualJson string

The non-null JSON text to parse, normalize, scrub, and compare.

settings SnapshotSettings

Optional snapshot settings. null uses the effective global or default settings.

cancellationToken CancellationToken

Token that cancels snapshot file locking and asynchronous file I/O. The default token does not cancel the operation.

sourceFile string

Calling source-file path used to locate and name the snapshot. The compiler supplies this value by default; it must not be empty.

testName string

Calling member name used as the default snapshot name. The compiler supplies this value by default.

Returns

Task

A task that completes after a match or an allowed automatic update; otherwise it writes a received file and throws SnapshotMismatchException.

MatchTextAsync(string, SnapshotSettings?, CancellationToken, string, string)

Compares text with a committed .verified.txt snapshot. A runtime-qualified .received.*.txt file is written when the snapshot is new or differs.

public static Task MatchTextAsync(string actualText, SnapshotSettings? settings = null, CancellationToken cancellationToken = default, string sourceFile = "", string testName = "")

Parameters

actualText string

The non-null text to scrub and compare. Line endings are normalized and trailing line feeds are removed.

settings SnapshotSettings

Optional snapshot settings. null uses the effective global or default settings.

cancellationToken CancellationToken

Token that cancels snapshot file locking and asynchronous file I/O. The default token does not cancel the operation.

sourceFile string

Calling source-file path used to locate and name the snapshot. The compiler supplies this value by default; it must not be empty.

testName string

Calling member name used as the default snapshot name. The compiler supplies this value by default.

Returns

Task

A task that completes after a match or an allowed automatic update; otherwise it writes a received file and throws SnapshotMismatchException.