InlineSnapshotBuilder Struct
Provides a fluent API for configuring and validating inline snapshots.
public readonly struct InlineSnapshotBuilderExample
var data = new { LastName = "Doe", FirstName = "John" };
InlineSnapshot
.WithSerializer(options => options.PropertyOrder = StringComparer.Ordinal)
.Validate(data, """
FirstName: John
LastName: Doe
""");Methods
| Name | Description |
|---|---|
| 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.csValidates 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
subjectobject?- The object to validate.
expectedstring?- The expected snapshot value. This parameter will be automatically updated when the snapshot changes.
filePathstring?- The source file path. Automatically populated by the compiler.
lineNumberint- The line number in the source file. Automatically populated by the compiler.
WithSerializer overloads
WithSerializer(HumanReadableSerializerOptions?)
InlineSnapshotBuilder.csConfigures the human-readable serializer with the specified options.
public InlineSnapshotBuilder WithSerializer(HumanReadableSerializerOptions? options)WithSerializer(SnapshotSerializer)
InlineSnapshotBuilder.csSets the snapshot serializer to use for serializing objects.
public InlineSnapshotBuilder WithSerializer(SnapshotSerializer serializer)WithSerializer(Action<HumanReadableSerializerOptions>?)
InlineSnapshotBuilder.csConfigures the human-readable serializer using an action.
public InlineSnapshotBuilder WithSerializer(Action<HumanReadableSerializerOptions>? configure)WithSettings(Action<InlineSnapshotSettings>?)
InlineSnapshotBuilder.csConfigures the settings for the snapshot validation.
public InlineSnapshotBuilder WithSettings(Action<InlineSnapshotSettings>? configure)