Table of Contents

Class SnapshotResult

Namespace
SnapshotAssertions
Assembly
SnapshotAssertions.dll

The outcome of a snapshot comparison, including paths to the expected baseline and (on mismatch or no-baseline) the written actual file, plus a rendered line-based diff for failure messages.

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

Properties

ActualFilePath

Absolute path to the written .actual.txt file when Outcome is Mismatched or NoBaseline; null otherwise.

public string? ActualFilePath { get; }

Property Value

string

Diff

Rendered line-based diff between expected and actual content when Outcome is Mismatched; null otherwise. Format is not stable; intended for failure-message display, not programmatic parsing.

public string? Diff { get; }

Property Value

string

ExpectedFilePath

Absolute path to the expected baseline file. Always populated.

public string ExpectedFilePath { get; }

Property Value

string

IsPass

Whether the comparison should be treated as a pass. Matched and Accepted pass; the others fail.

public bool IsPass { get; }

Property Value

bool

Outcome

The classification of the comparison outcome.

public SnapshotMatchOutcome Outcome { get; }

Property Value

SnapshotMatchOutcome

Methods

Accepted(string)

Constructs a Accepted result.

public static SnapshotResult Accepted(string expectedFilePath)

Parameters

expectedFilePath string

Absolute path to the now-overwritten expected file.

Returns

SnapshotResult

A passing result indicating the actual content was written over the baseline (accept-mode).

Exceptions

ArgumentNullException

expectedFilePath is null.

Describe()

Renders a multi-line description of the result for use in assertion failure messages and diagnostic output. Includes the expected path, the actual path (when applicable), the diff (when applicable), and accept-flow guidance.

public string Describe()

Returns

string

A multi-line description; format is not stable.

Matched(string)

Constructs a Matched result.

public static SnapshotResult Matched(string expectedFilePath)

Parameters

expectedFilePath string

Absolute path to the matching expected file.

Returns

SnapshotResult

A passing result.

Exceptions

ArgumentNullException

expectedFilePath is null.

Mismatched(string, string, string)

Constructs a Mismatched result.

public static SnapshotResult Mismatched(string expectedFilePath, string actualFilePath, string diff)

Parameters

expectedFilePath string

Absolute path to the expected file.

actualFilePath string

Absolute path to the written .actual.txt file.

diff string

Rendered line-based diff for failure-message display.

Returns

SnapshotResult

A failing result describing the mismatch.

Exceptions

ArgumentNullException

A required argument is null.

NoBaseline(string, string)

Constructs a NoBaseline result.

public static SnapshotResult NoBaseline(string expectedFilePath, string actualFilePath)

Parameters

expectedFilePath string

Absolute path to where the expected file would be.

actualFilePath string

Absolute path to the written .actual.txt file the caller can inspect and rename to .expected.txt to accept.

Returns

SnapshotResult

A failing result describing the missing baseline.

Exceptions

ArgumentNullException

A required argument is null.

WriteDescription(TextWriter)

Writes the same description as Describe() to writer.

public void WriteDescription(TextWriter writer)

Parameters

writer TextWriter

The destination text writer.

Exceptions

ArgumentNullException

writer is null.