Class SnapshotRenderer<T>
- Namespace
- SnapshotAssertions.Render
- Assembly
- SnapshotAssertions.dll
Renders an instance of T as a canonical string for snapshot
comparison. Consumers subclass this to plug their domain types (Google.Protobuf messages,
XDocument, Activity, project-specific value objects) into the snapshot
pipeline without the framework-agnostic core taking on those types as dependencies.
public abstract class SnapshotRenderer<T>
Type Parameters
TThe type to render.
- Inheritance
-
SnapshotRenderer<T>
- Inherited Members
Remarks
The renderer should produce deterministic output for a given input.
Non-determinism (random ordering, embedded timestamps, environment-specific paths) in the
rendered string defeats the purpose of snapshot testing; if such fields exist on
T, prefer to either omit them in the renderer or rely on the
snapshot-pipeline SnapshotScrubber chain to remove them after rendering.
Inline renderers (single-test, ad-hoc) can be built from a delegate via For<T>(Func<T, string>) without subclassing.
Sibling family packages (e.g. LogAssertions.TUnit) can publish renderers
for their own types as static helper methods that match the delegate-overload of
MatchesSnapshot directly, without taking a reference on
SnapshotAssertions. Subclassing this base type is the opt-in path for renderers
that need configuration / state / inheritance.
Constructors
SnapshotRenderer()
Initialises a new renderer instance.
protected SnapshotRenderer()
Methods
Render(T)
Renders value as a canonical string suitable for snapshot
comparison.
public abstract string Render(T value)
Parameters
valueTThe value to render. Implementations should document their behaviour for null inputs (typically: throw ArgumentNullException or return a sentinel like
"<null>").
Returns
- string
The canonical string rendering.