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
receivedPathstringAbsolute 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
actualobjectThe value to serialize. May be null, which is serialized as JSON
null.settingsSnapshotSettingsOptional snapshot settings. null uses the effective global or default settings.
cancellationTokenCancellationTokenToken that cancels snapshot file locking and asynchronous file I/O. 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; it must not be empty.
testNamestringCalling 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
actualJsonstringThe non-null JSON text to parse, normalize, scrub, and compare.
settingsSnapshotSettingsOptional snapshot settings. null uses the effective global or default settings.
cancellationTokenCancellationTokenToken that cancels snapshot file locking and asynchronous file I/O. 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; it must not be empty.
testNamestringCalling 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
actualTextstringThe non-null text to scrub and compare. Line endings are normalized and trailing line feeds are removed.
settingsSnapshotSettingsOptional snapshot settings. null uses the effective global or default settings.
cancellationTokenCancellationTokenToken that cancels snapshot file locking and asynchronous file I/O. 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; it must not be empty.
testNamestringCalling 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.