Snapshot Class
public static class SnapshotNo documentation is available.
Properties
| Name | Description |
|---|---|
| TestContext |
TestContext
Snapshot.cspublic static AsyncLocal<SnapshotTestContext?> TestContext { get; }Property value
No documentation is available.
Methods
RegisterSourceRootMapping(string, string)
Snapshot.csRegisters a deterministic source-root mapping so generated paths (for example /_/) can be resolved back to real source files on disk.
Validate overloads
Validate(object?, SnapshotSettings?, string?, int, string?)
Snapshot.csValidate(object?, SnapshotType?, SnapshotSettings?, string?, int, string?)
Snapshot.cspublic static void Validate(object? value, SnapshotType? type, SnapshotSettings? settings, string? callerFilePath = null, int callerLineNumber = -1, string? callerMemberName = null)Parameters
valueobject?typeSnapshotType?settingsSnapshotSettings?callerFilePathstring?callerLineNumberintcallerMemberNamestring?
No documentation is available.
Validate(object?, SnapshotType?, string?, int, string?)
Snapshot.csValidate(object?, string?, int, string?)
Snapshot.csValidateAsync overloads
ValidateAsync(Stream, SnapshotSettings?, CancellationToken, string?, int, string?)
Snapshot.csValidates the content of a stream against its snapshot, reading the stream asynchronously.
public static Task ValidateAsync(Stream stream, SnapshotSettings? settings, CancellationToken cancellationToken = default, string? filePath = null, int lineNumber = -1, string? memberName = null)Parameters
streamStreamsettingsSnapshotSettings?cancellationTokenCancellationTokenfilePathstring?lineNumberintmemberNamestring?
Returns
Remarks
The stream is read with Stream.CopyToAsync, from its current position to its end, so a stream that only supports asynchronous reads can be validated. It is neither rewound nor disposed. Once read, the content is validated like a stream passed to Snapshot.Validate. The returned task completes after the comparison and the snapshot updates. No snapshot file is read or written before the stream is fully read, so canceling the read leaves the snapshots untouched.
ValidateAsync(Stream, SnapshotType?, SnapshotSettings?, CancellationToken, string?, int, string?)
Snapshot.csValidates the content of a stream against its snapshot, reading the stream asynchronously.
public static Task ValidateAsync(Stream stream, SnapshotType? type, SnapshotSettings? settings, CancellationToken cancellationToken = default, string? callerFilePath = null, int callerLineNumber = -1, string? callerMemberName = null)Parameters
streamStreamtypeSnapshotType?settingsSnapshotSettings?cancellationTokenCancellationTokencallerFilePathstring?callerLineNumberintcallerMemberNamestring?
Returns
Remarks
The stream is read with Stream.CopyToAsync, from its current position to its end, so a stream that only supports asynchronous reads can be validated. It is neither rewound nor disposed. Once read, the content is validated like a stream passed to Snapshot.Validate. The returned task completes after the comparison and the snapshot updates. No snapshot file is read or written before the stream is fully read, so canceling the read leaves the snapshots untouched.
ValidateAsync(Stream, SnapshotType?, CancellationToken, string?, int, string?)
Snapshot.csValidates the content of a stream against its snapshot, reading the stream asynchronously.
public static Task ValidateAsync(Stream stream, SnapshotType? type, CancellationToken cancellationToken = default, string? filePath = null, int lineNumber = -1, string? memberName = null)Parameters
streamStreamtypeSnapshotType?cancellationTokenCancellationTokenfilePathstring?lineNumberintmemberNamestring?
Returns
Remarks
The stream is read with Stream.CopyToAsync, from its current position to its end, so a stream that only supports asynchronous reads can be validated. It is neither rewound nor disposed. Once read, the content is validated like a stream passed to Snapshot.Validate. The returned task completes after the comparison and the snapshot updates. No snapshot file is read or written before the stream is fully read, so canceling the read leaves the snapshots untouched.
ValidateAsync(Stream, CancellationToken, string?, int, string?)
Snapshot.csValidates the content of a stream against its snapshot, reading the stream asynchronously.
public static Task ValidateAsync(Stream stream, CancellationToken cancellationToken = default, string? filePath = null, int lineNumber = -1, string? memberName = null)Parameters
streamStreamcancellationTokenCancellationTokenfilePathstring?lineNumberintmemberNamestring?
Returns
Remarks
The stream is read with Stream.CopyToAsync, from its current position to its end, so a stream that only supports asynchronous reads can be validated. It is neither rewound nor disposed. Once read, the content is validated like a stream passed to Snapshot.Validate. The returned task completes after the comparison and the snapshot updates. No snapshot file is read or written before the stream is fully read, so canceling the read leaves the snapshots untouched.
ValidateAsync<T>(IAsyncEnumerable<T>, SnapshotSettings?, CancellationToken, string?, int, string?)
Snapshot.csValidates the items of an asynchronous sequence against their snapshot, enumerating the sequence asynchronously.
public static Task ValidateAsync<T>(IAsyncEnumerable<T> values, SnapshotSettings? settings, CancellationToken cancellationToken = default, string? filePath = null, int lineNumber = -1, string? memberName = null)Type parameters
T
Parameters
valuesIAsyncEnumerable<T>settingsSnapshotSettings?cancellationTokenCancellationTokenfilePathstring?lineNumberintmemberNamestring?
Returns
Remarks
The sequence is enumerated with await foreach, passing filePath, instead of blocking the test while the items are produced. The items are then validated as a List<T>: the human-readable serializer writes it as it writes the sequence, but a serializer registered for IAsyncEnumerable<T> does not apply. The returned task completes after the comparison and the snapshot updates. No snapshot file is read or written before the sequence is fully enumerated, so canceling the enumeration leaves the snapshots untouched.
ValidateAsync<T>(IAsyncEnumerable<T>, SnapshotType?, SnapshotSettings?, CancellationToken, string?, int, string?)
Snapshot.csValidates the items of an asynchronous sequence against their snapshot, enumerating the sequence asynchronously.
public static Task ValidateAsync<T>(IAsyncEnumerable<T> values, SnapshotType? type, SnapshotSettings? settings, CancellationToken cancellationToken = default, string? callerFilePath = null, int callerLineNumber = -1, string? callerMemberName = null)Type parameters
T
Parameters
valuesIAsyncEnumerable<T>typeSnapshotType?settingsSnapshotSettings?cancellationTokenCancellationTokencallerFilePathstring?callerLineNumberintcallerMemberNamestring?
Returns
Remarks
The sequence is enumerated with await foreach, passing cancellationToken, instead of blocking the test while the items are produced. The items are then validated as a List<T>: the human-readable serializer writes it as it writes the sequence, but a serializer registered for IAsyncEnumerable<T> does not apply. The returned task completes after the comparison and the snapshot updates. No snapshot file is read or written before the sequence is fully enumerated, so canceling the enumeration leaves the snapshots untouched.
ValidateAsync<T>(IAsyncEnumerable<T>, SnapshotType?, CancellationToken, string?, int, string?)
Snapshot.csValidates the items of an asynchronous sequence against their snapshot, enumerating the sequence asynchronously.
public static Task ValidateAsync<T>(IAsyncEnumerable<T> values, SnapshotType? type, CancellationToken cancellationToken = default, string? filePath = null, int lineNumber = -1, string? memberName = null)Type parameters
T
Parameters
valuesIAsyncEnumerable<T>typeSnapshotType?cancellationTokenCancellationTokenfilePathstring?lineNumberintmemberNamestring?
Returns
Remarks
The sequence is enumerated with await foreach, passing filePath, instead of blocking the test while the items are produced. The items are then validated as a List<T>: the human-readable serializer writes it as it writes the sequence, but a serializer registered for IAsyncEnumerable<T> does not apply. The returned task completes after the comparison and the snapshot updates. No snapshot file is read or written before the sequence is fully enumerated, so canceling the enumeration leaves the snapshots untouched.
ValidateAsync<T>(IAsyncEnumerable<T>, CancellationToken, string?, int, string?)
Snapshot.csValidates the items of an asynchronous sequence against their snapshot, enumerating the sequence asynchronously.
public static Task ValidateAsync<T>(IAsyncEnumerable<T> values, CancellationToken cancellationToken = default, string? filePath = null, int lineNumber = -1, string? memberName = null)Type parameters
T
Parameters
valuesIAsyncEnumerable<T>cancellationTokenCancellationTokenfilePathstring?lineNumberintmemberNamestring?
Returns
Remarks
The sequence is enumerated with await foreach, passing lineNumber, instead of blocking the test while the items are produced. The items are then validated as a List<T>: the human-readable serializer writes it as it writes the sequence, but a serializer registered for IAsyncEnumerable<T> does not apply. The returned task completes after the comparison and the snapshot updates. No snapshot file is read or written before the sequence is fully enumerated, so canceling the enumeration leaves the snapshots untouched.