Skip to content

Latest commit

 

History

History
198 lines (156 loc) · 5.94 KB

guids.md

File metadata and controls

198 lines (156 loc) · 5.94 KB

Guids

By default guids are sanitized during verification. This is done by finding each guid and taking a counter based that that specific guid. That counter is then used replace the guid values. This allows for repeatable tests when guid values are changing.

var guid = Guid.NewGuid();
var target = new GuidTarget
{
    Guid = guid,
    GuidNullable = guid,
    GuidString = guid.ToString(),
    OtherGuid = Guid.NewGuid()
};

await Verify(target);

snippet source | anchor

Results in the following:

{
  Guid: Guid_1,
  GuidNullable: Guid_1,
  GuidString: Guid_1,
  OtherGuid: Guid_2
}

snippet source | anchor

Disable

To disable this behavior use:

Instance

var settings = new VerifySettings();
settings.DontScrubGuids();
await Verify(target, settings);

snippet source | anchor

Fluent

await Verify(target)
    .DontScrubGuids();

snippet source | anchor

Globally

VerifierSettings.DontScrubGuids();

snippet source | anchor

Inline Guids

Strings containing inline Guids can also be scrubbed. To enable this behavior, use:

Instance

[Fact]
public Task ScrubInlineGuidsInstance()
{
    var settings = new VerifySettings();
    settings.ScrubInlineGuids();
    return Verify(
        "content 651ad409-fc30-4b12-a47e-616d3f953e4c content",
        settings);
}

snippet source | anchor

Fluent

[Fact]
public Task ScrubInlineGuidsFluent() =>
    Verify("content 651ad409-fc30-4b12-a47e-616d3f953e4c content")
        .ScrubInlineGuids();

snippet source | anchor

Globally

public static class ModuleInitializer
{
    [ModuleInitializer]
    public static void Init() =>
        VerifierSettings.ScrubInlineGuids();
}

snippet source | anchor

Named Guid

Specific Guids can be named. When any of those Guids are found, it will be replaced with the supplied name.

Instance

[Fact]
public Task NamedGuidInstance()
{
    var settings = new VerifySettings();
    var guid = new Guid("c8eeaf99-d5c4-4341-8543-4597c3fd40d9");
    settings.AddNamedGuid(guid, "instanceNamed");
    return Verify(
        new
        {
            value = guid
        },
        settings);
}

snippet source | anchor

Instance

[Fact]
public Task NamedGuidFluent()
{
    var guid = new Guid("c8eeaf99-d5c4-4341-8543-4597c3fd40d9");
    return Verify(
            new
            {
                value = guid
            })
        .AddNamedGuid(guid, "instanceNamed");
}

snippet source | anchor

Globally

[ModuleInitializer]
public static void Init() => VerifierSettings.AddNamedGuid(new("c8eeaf99-d5c4-4341-8543-4597c3fd40c9"), "guidName");

snippet source | anchor