Table of Contents

Class SnapshotOptions

Namespace
SnapshotAssertions
Assembly
SnapshotAssertions.dll

Configuration for snapshot comparison: line-ending handling, BOM behavior, trailing whitespace, and trailing-newline policy. Strict by default; opt into normalization explicitly via the convenience presets or by mutating the properties directly.

public sealed record SnapshotOptions : IEquatable<SnapshotOptions>
Inheritance
SnapshotOptions
Implements
Inherited Members

Remarks

The default options preserve the captured artefact as-is, with one minor exception: a leading UTF-8 BOM is stripped from both sides before comparison (BomHandling defaults to StripBom). All other content: line endings, per-line trailing whitespace, end-of-file trailing-newline state: is preserved. Cross-platform false positives (LF vs CRLF) are real but should be opted into via NormalizedLineEndings rather than silently normalized away. This matches the family-wide convention of explicit StringComparison on string-matching APIs.

Properties

BomHandling

How a leading byte-order-mark in either file is handled. Defaults to StripBom: a UTF-8 BOM is stripped from both sides before comparison.

public SnapshotBomHandling BomHandling { get; init; }

Property Value

SnapshotBomHandling

Default

Strict defaults: preserve everything as-is. Used when no options are passed to the snapshot assertion entry points.

public static SnapshotOptions Default { get; }

Property Value

SnapshotOptions

LineEndingMode

How line-ending differences between the actual content and the expected baseline are handled. Defaults to Ordinal (no normalization).

public SnapshotLineEndingMode LineEndingMode { get; init; }

Property Value

SnapshotLineEndingMode

NormalizedLineEndings

Convenience preset for cross-platform tests that should treat all line-ending differences as non-meaningful, including the presence or absence of a trailing newline at end-of-file. Sets LineEndingMode to IgnoreLineEndings (line breaks stripped) and TrailingNewline to Optional (presence vs absence is unobservable). BOM and per-line trailing-whitespace handling remain at their strict defaults.

public static SnapshotOptions NormalizedLineEndings { get; }

Property Value

SnapshotOptions

Normalizer

An optional caller-supplied transform applied to both the actual content and the expected baseline before any built-in normalization (BOM, line endings, trailing whitespace, trailing newline). Defaults to null (no transform). Use it to canonicalize content whose textual form is noisy but semantically irrelevant: JSON or XML reformatting, nondeterministic-collection sorting, masking volatile fields, decimal formatting. Prefer WithNormalizer(Func<string, string>) to set it, which composes with any normalizer already configured.

public Func<string, string>? Normalizer { get; init; }

Property Value

Func<string, string>

TrailingNewline

How the trailing newline at end-of-file is treated. Defaults to Required: the baseline must end with a newline or the comparison fails.

public SnapshotTrailingNewline TrailingNewline { get; init; }

Property Value

SnapshotTrailingNewline

TrailingWhitespace

How per-line trailing whitespace is treated. Defaults to Preserve: whitespace differences fail the match.

public SnapshotTrailingWhitespace TrailingWhitespace { get; init; }

Property Value

SnapshotTrailingWhitespace

Methods

WithNormalizer(Func<string, string>)

Returns a copy of these options with normalizer applied before comparison. If a normalizer is already configured, the two compose: the existing one runs first, then normalizer. The transform runs ahead of all built-in normalization, so the supplied delegate sees the raw rendered text.

public SnapshotOptions WithNormalizer(Func<string, string> normalizer)

Parameters

normalizer Func<string, string>

A pure string-to-string transform.

Returns

SnapshotOptions

A new SnapshotOptions with the composed normalizer.

Exceptions

ArgumentNullException

normalizer is null.