InlineSnapshotBuilder Struct

Provides a fluent API for configuring and validating inline snapshots.

public readonly struct InlineSnapshotBuilder

Example

var data = new { LastName = "Doe", FirstName = "John" };
InlineSnapshot
    .WithSerializer(options => options.PropertyOrder = StringComparer.Ordinal)
    .Validate(data, """
        FirstName: John
        LastName: Doe
        """);

Methods

NameDescription
Validate(object?, string?, string?, int)Validates that the serialized representation of the subject matches the expected snapshot. If the snapshot doesn't match, the source file is updated with the actual value based on the configured update strategy.
WithSerializer(HumanReadableSerializerOptions?)Configures the human-readable serializer with the specified options.
WithSerializer(SnapshotSerializer)Sets the snapshot serializer to use for serializing objects.
WithSerializer(Action<HumanReadableSerializerOptions>?)Configures the human-readable serializer using an action.
WithSettings(Action<InlineSnapshotSettings>?)Configures the settings for the snapshot validation.

Validate(object?, string?, string?, int)

InlineSnapshotBuilder.cs

Validates that the serialized representation of the subject matches the expected snapshot. If the snapshot doesn't match, the source file is updated with the actual value based on the configured update strategy.

public void Validate(object? subject, string? expected = null, string? filePath = null, int lineNumber = -1)

Parameters

subject object?
The object to validate.
expected string?
The expected snapshot value. This parameter will be automatically updated when the snapshot changes.
filePath string?
The source file path. Automatically populated by the compiler.
lineNumber int
The line number in the source file. Automatically populated by the compiler.

WithSerializer overloads

WithSerializer(HumanReadableSerializerOptions?)

InlineSnapshotBuilder.cs

Configures the human-readable serializer with the specified options.

WithSerializer(SnapshotSerializer)

InlineSnapshotBuilder.cs

Sets the snapshot serializer to use for serializing objects.

public InlineSnapshotBuilder WithSerializer(SnapshotSerializer serializer)
Parameters
serializer SnapshotSerializer
Returns

InlineSnapshotBuilder

WithSerializer(Action<HumanReadableSerializerOptions>?)

InlineSnapshotBuilder.cs

Configures the human-readable serializer using an action.

WithSettings(Action<InlineSnapshotSettings>?)

InlineSnapshotBuilder.cs

Configures the settings for the snapshot validation.

public InlineSnapshotBuilder WithSettings(Action<InlineSnapshotSettings>? configure)