Snapshot Class

public static class Snapshot

No documentation is available.

Properties

NameDescription
TestContext

TestContext

Snapshot.cs
public static AsyncLocal<SnapshotTestContext?> TestContext { get; }

No documentation is available.

Methods

NameDescription
RegisterSourceRootMapping(string, string)Registers a deterministic source-root mapping so generated paths (for example /_/) can be resolved back to real source files on disk.
Validate(object?, SnapshotSettings?, string?, int, string?)
Validate(object?, SnapshotType?, SnapshotSettings?, string?, int, string?)
Validate(object?, SnapshotType?, string?, int, string?)
Validate(object?, string?, int, string?)
ValidateAsync(Stream, SnapshotSettings?, CancellationToken, string?, int, string?)Validates the content of a stream against its snapshot, reading the stream asynchronously.
ValidateAsync(Stream, SnapshotType?, SnapshotSettings?, CancellationToken, string?, int, string?)Validates the content of a stream against its snapshot, reading the stream asynchronously.
ValidateAsync(Stream, SnapshotType?, CancellationToken, string?, int, string?)Validates the content of a stream against its snapshot, reading the stream asynchronously.
ValidateAsync(Stream, CancellationToken, string?, int, string?)Validates the content of a stream against its snapshot, reading the stream asynchronously.
ValidateAsync<T>(IAsyncEnumerable<T>, SnapshotSettings?, CancellationToken, string?, int, string?)Validates the items of an asynchronous sequence against their snapshot, enumerating the sequence asynchronously.
ValidateAsync<T>(IAsyncEnumerable<T>, SnapshotType?, SnapshotSettings?, CancellationToken, string?, int, string?)Validates the items of an asynchronous sequence against their snapshot, enumerating the sequence asynchronously.
ValidateAsync<T>(IAsyncEnumerable<T>, SnapshotType?, CancellationToken, string?, int, string?)Validates the items of an asynchronous sequence against their snapshot, enumerating the sequence asynchronously.
ValidateAsync<T>(IAsyncEnumerable<T>, CancellationToken, string?, int, string?)Validates the items of an asynchronous sequence against their snapshot, enumerating the sequence asynchronously.

RegisterSourceRootMapping(string, string)

Snapshot.cs

Registers a deterministic source-root mapping so generated paths (for example /_/) can be resolved back to real source files on disk.

public static void RegisterSourceRootMapping(string mappedPath, string realPath)

Parameters

mappedPath string
Deterministic mapped prefix emitted by the compiler.
realPath string
Real source-root path on disk.

Validate overloads

Validate(object?, SnapshotSettings?, string?, int, string?)

Snapshot.cs
public static void Validate(object? value, SnapshotSettings? settings, string? filePath = null, int lineNumber = -1, string? memberName = null)
Parameters
value object?
settings SnapshotSettings?
filePath string?
lineNumber int
memberName string?

No documentation is available.

Validate(object?, SnapshotType?, SnapshotSettings?, string?, int, string?)

Snapshot.cs
public static void Validate(object? value, SnapshotType? type, SnapshotSettings? settings, string? callerFilePath = null, int callerLineNumber = -1, string? callerMemberName = null)
Parameters
value object?
type SnapshotType?
settings SnapshotSettings?
callerFilePath string?
callerLineNumber int
callerMemberName string?

No documentation is available.

Validate(object?, SnapshotType?, string?, int, string?)

Snapshot.cs
public static void Validate(object? value, SnapshotType? type, string? filePath = null, int lineNumber = -1, string? memberName = null)
Parameters
value object?
type SnapshotType?
filePath string?
lineNumber int
memberName string?

No documentation is available.

Validate(object?, string?, int, string?)

Snapshot.cs
public static void Validate(object? value, string? filePath = null, int lineNumber = -1, string? memberName = null)
Parameters
value object?
filePath string?
lineNumber int
memberName string?

No documentation is available.

ValidateAsync overloads

ValidateAsync(Stream, SnapshotSettings?, CancellationToken, string?, int, string?)

Snapshot.cs

Validates 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
stream Stream
settings SnapshotSettings?
cancellationToken CancellationToken
filePath string?
lineNumber int
memberName string?
Returns

Task

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.cs

Validates 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
stream Stream
type SnapshotType?
settings SnapshotSettings?
cancellationToken CancellationToken
callerFilePath string?
callerLineNumber int
callerMemberName string?
Returns

Task

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.cs

Validates 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
stream Stream
type SnapshotType?
cancellationToken CancellationToken
filePath string?
lineNumber int
memberName string?
Returns

Task

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.cs

Validates 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
stream Stream
cancellationToken CancellationToken
filePath string?
lineNumber int
memberName string?
Returns

Task

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.cs

Validates 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
values IAsyncEnumerable<T>
settings SnapshotSettings?
cancellationToken CancellationToken
filePath string?
lineNumber int
memberName string?
Returns

Task

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.cs

Validates 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
values IAsyncEnumerable<T>
type SnapshotType?
settings SnapshotSettings?
cancellationToken CancellationToken
callerFilePath string?
callerLineNumber int
callerMemberName string?
Returns

Task

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.cs

Validates 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
values IAsyncEnumerable<T>
type SnapshotType?
cancellationToken CancellationToken
filePath string?
lineNumber int
memberName string?
Returns

Task

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.cs

Validates 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
values IAsyncEnumerable<T>
cancellationToken CancellationToken
filePath string?
lineNumber int
memberName string?
Returns

Task

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.