Table of Contents

Class RenderedSnapshotAssertion<T>

Namespace
SnapshotAssertions.TUnit
Assembly
SnapshotAssertions.TUnit.dll

Renderer-projected TUnit assertion that verifies a value of type T, after canonical-string rendering via a SnapshotRenderer<T>, matches a baseline snapshot stored on disk. Used by the MatchesSnapshot<T>(IAssertionSource<T>, SnapshotRenderer<T>) and MatchesSnapshot<T>(IAssertionSource<T>, Func<T, string>) overloads. Shares the underlying scrubber / path / evaluator pipeline with SnapshotAssertion via SnapshotAssertions.TUnit.SnapshotAssertionImpl.

public sealed class RenderedSnapshotAssertion<T> : Assertion<T>, IAssertion

Type Parameters

T

The source type that the renderer projects to a canonical string.

Inheritance
Assertion<T>
RenderedSnapshotAssertion<T>
Implements
IAssertion
Inherited Members
Assertion<T>.AssertAsync()
Assertion<T>.GetAwaiter()
Assertion<T>.And
Assertion<T>.Or

Constructors

RenderedSnapshotAssertion(AssertionContext<T>, SnapshotRenderer<T>)

Initialises the renderer-projected assertion.

public RenderedSnapshotAssertion(AssertionContext<T> context, SnapshotRenderer<T> renderer)

Parameters

context AssertionContext<T>

The assertion context supplied by TUnit.

renderer SnapshotRenderer<T>

The renderer projecting T to a canonical string. Must not be null.

Exceptions

ArgumentNullException

renderer is null.

Methods

AtPath(string)

Overrides path resolution with an explicit absolute or relative file path.

public RenderedSnapshotAssertion<T> AtPath(string filePath)

Parameters

filePath string

The path to the expected baseline file.

Returns

RenderedSnapshotAssertion<T>

This assertion for chaining.

Exceptions

ArgumentNullException

filePath is null.

CheckAsync(EvaluationMetadata<T>)

Implements the specific check logic for this assertion. Called after the context has been evaluated. Override this method if your assertion uses the default AssertAsync() flow. If you override AssertAsync() with custom logic (like AndAssertion/OrAssertion), you don't need to implement this.

protected override Task<AssertionResult> CheckAsync(EvaluationMetadata<T> metadata)

Parameters

metadata EvaluationMetadata<T>

Metadata about the evaluation including value, exception, and timing information

Returns

Task<AssertionResult>

The result of the assertion check

GetExpectation()

Gets a human-readable description of what this assertion expects. Used in error messages.

protected override string GetExpectation()

Returns

string

WithName(string)

Overrides the default TUnit-test-derived snapshot name.

public RenderedSnapshotAssertion<T> WithName(string snapshotName)

Parameters

snapshotName string

The base name (without extension).

Returns

RenderedSnapshotAssertion<T>

This assertion for chaining.

Exceptions

ArgumentNullException

snapshotName is null.

WithOptions(SnapshotOptions)

Overrides the comparison options.

public RenderedSnapshotAssertion<T> WithOptions(SnapshotOptions options)

Parameters

options SnapshotOptions

The options to apply.

Returns

RenderedSnapshotAssertion<T>

This assertion for chaining.

Exceptions

ArgumentNullException

options is null.

WithScrubber(SnapshotScrubber)

Adds a SnapshotScrubber to the pipeline. Applied AFTER the renderer projects the value to a string; multiple .WithScrubber() calls compose left-to-right.

public RenderedSnapshotAssertion<T> WithScrubber(SnapshotScrubber scrubber)

Parameters

scrubber SnapshotScrubber

The scrubber to append.

Returns

RenderedSnapshotAssertion<T>

This assertion for chaining.

Exceptions

ArgumentNullException

scrubber is null.