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
TThe 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>.AndAssertion<T>.Or
Constructors
RenderedSnapshotAssertion(AssertionContext<T>, SnapshotRenderer<T>)
Initialises the renderer-projected assertion.
public RenderedSnapshotAssertion(AssertionContext<T> context, SnapshotRenderer<T> renderer)
Parameters
contextAssertionContext<T>The assertion context supplied by TUnit.
rendererSnapshotRenderer<T>The renderer projecting
Tto a canonical string. Must not be null.
Exceptions
- ArgumentNullException
rendereris null.
Methods
AtPath(string)
Overrides path resolution with an explicit absolute or relative file path.
public RenderedSnapshotAssertion<T> AtPath(string filePath)
Parameters
filePathstringThe path to the expected baseline file.
Returns
- RenderedSnapshotAssertion<T>
This assertion for chaining.
Exceptions
- ArgumentNullException
filePathis 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
metadataEvaluationMetadata<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
WithName(string)
Overrides the default TUnit-test-derived snapshot name.
public RenderedSnapshotAssertion<T> WithName(string snapshotName)
Parameters
snapshotNamestringThe base name (without extension).
Returns
- RenderedSnapshotAssertion<T>
This assertion for chaining.
Exceptions
- ArgumentNullException
snapshotNameis null.
WithOptions(SnapshotOptions)
Overrides the comparison options.
public RenderedSnapshotAssertion<T> WithOptions(SnapshotOptions options)
Parameters
optionsSnapshotOptionsThe options to apply.
Returns
- RenderedSnapshotAssertion<T>
This assertion for chaining.
Exceptions
- ArgumentNullException
optionsis 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
scrubberSnapshotScrubberThe scrubber to append.
Returns
- RenderedSnapshotAssertion<T>
This assertion for chaining.
Exceptions
- ArgumentNullException
scrubberis null.