InlineSnapshot Class
Provides methods for validating objects against inline snapshots in test code.
public static class InlineSnapshotExample
var data = new { FirstName = "John", LastName = "Doe" };
InlineSnapshot.Validate(data, """
FirstName: John
LastName: Doe
""");Methods
| Name | Description |
|---|---|
| RegisterSourceRootMapping(string, string) | Registers a deterministic source-root mapping so generated paths (for example /_/) can be resolved back to real source files on disk. |
| Validate(object?, InlineSnapshotSettings?, string?, string?, int) | Validates that the serialized representation of the subject matches the expected snapshot using the provided settings. If the snapshot doesn't match, the source file is updated with the actual value based on the configured update strategy. |
| 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?) | Creates a new InlineSnapshotBuilder with a human-readable serializer configured with the specified options. |
| WithSerializer(SnapshotSerializer) | Creates a new InlineSnapshotBuilder with the specified snapshot serializer. |
| WithSerializer(Action<HumanReadableSerializerOptions>?) | Creates a new InlineSnapshotBuilder with a human-readable serializer configured by the specified action. |
| WithSettings(InlineSnapshotSettings?) | Creates a new InlineSnapshotBuilder with the specified settings. |
| WithSettings(Action<InlineSnapshotSettings>?) | Creates a new InlineSnapshotBuilder with settings configured by the specified action. |
RegisterSourceRootMapping(string, string)
InlineSnapshot.csRegisters a deterministic source-root mapping so generated paths (for example /_/) can be resolved back to real source files on disk.
Validate overloads
Validate(object?, InlineSnapshotSettings?, string?, string?, int)
InlineSnapshot.csValidates that the serialized representation of the subject matches the expected snapshot using the provided settings. If the snapshot doesn't match, the source file is updated with the actual value based on the configured update strategy.
public static void Validate(object? subject, InlineSnapshotSettings? settings, string? expected, string? filePath = null, int lineNumber = -1)Parameters
subjectobject?- The object to validate.
settingsInlineSnapshotSettings?- The settings to use for validation. If null,
InlineSnapshotSettings.Defaultis used. 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.
Validate(object?, string?, string?, int)
InlineSnapshot.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 static 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?)
InlineSnapshot.csCreates a new InlineSnapshotBuilder with a human-readable serializer configured with the specified options.
public static InlineSnapshotBuilder WithSerializer(HumanReadableSerializerOptions? options)WithSerializer(SnapshotSerializer)
InlineSnapshot.csCreates a new InlineSnapshotBuilder with the specified snapshot serializer.
public static InlineSnapshotBuilder WithSerializer(SnapshotSerializer serializer)WithSerializer(Action<HumanReadableSerializerOptions>?)
InlineSnapshot.csCreates a new InlineSnapshotBuilder with a human-readable serializer configured by the specified action.
public static InlineSnapshotBuilder WithSerializer(Action<HumanReadableSerializerOptions>? configure)WithSettings overloads
WithSettings(InlineSnapshotSettings?)
InlineSnapshot.csCreates a new InlineSnapshotBuilder with the specified settings.
public static InlineSnapshotBuilder WithSettings(InlineSnapshotSettings? settings)WithSettings(Action<InlineSnapshotSettings>?)
InlineSnapshot.csCreates a new InlineSnapshotBuilder with settings configured by the specified action.
public static InlineSnapshotBuilder WithSettings(Action<InlineSnapshotSettings>? configure)