Class SnapshotScrubber
- Namespace
- SnapshotAssertions
- Assembly
- SnapshotAssertions.dll
Base class for snapshot text transformations applied before comparison. A scrubber receives the actual content plus a per-snapshot SnapshotScrubberState and returns a transformed string in which volatile substrings (GUIDs, timestamps, epoch millis, etc.) have been replaced by stable tokens, so a snapshot baseline can survive multiple test runs.
[SuppressMessage("Major Code Smell", "S1694:An abstract class should have both abstract and concrete methods", Justification = "Class chosen over interface to leave room for future shared state (e.g. a Description property surfaced in failure diagnostics) without forcing a binary-breaking conversion.")]
public abstract class SnapshotScrubber
- Inheritance
-
SnapshotScrubber
- Inherited Members
Remarks
Scrubbers compose left-to-right via the WithScrubber chain on
MatchesSnapshot(); the output of one scrubber feeds the next. The shared
SnapshotScrubberState tracks original-value-to-index mappings so that a
recurring volatile value (e.g. the same GUID appearing three times) renders as the same
indexed token (<guid:0>) at every site.
Custom scrubbers should derive from this class and implement Apply(string, SnapshotScrubberState). The implementation must be deterministic for a given input; it must not perform IO, capture cross-test state, or rely on time.
Methods
Apply(string, SnapshotScrubberState)
Applies the scrubber to input and returns the transformed
string. The supplied state is shared across all scrubbers in the
pipeline for a single snapshot evaluation; use it to maintain stable indexed tokens for
recurring volatile values.
public abstract string Apply(string input, SnapshotScrubberState state)
Parameters
inputstringThe current pipeline content (output of the previous scrubber, or the original actual content for the first scrubber).
stateSnapshotScrubberStatePer-snapshot state used for stable indexed token assignment.
Returns
- string
The transformed content.
Exceptions
- ArgumentNullException
A required argument is null.