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);
Results in the following:
{
Guid: Guid_1,
GuidNullable: Guid_1,
GuidString: Guid_1,
OtherGuid: Guid_2
}
To disable this behavior use:
var settings = new VerifySettings();
settings.DontScrubGuids();
await Verify(target, settings);
await Verify(target)
.DontScrubGuids();
VerifierSettings.DontScrubGuids();
Strings containing inline Guids can also be scrubbed. To enable this behavior, use:
[Fact]
public Task ScrubInlineGuidsInstance()
{
var settings = new VerifySettings();
settings.ScrubInlineGuids();
return Verify(
"content 651ad409-fc30-4b12-a47e-616d3f953e4c content",
settings);
}
[Fact]
public Task ScrubInlineGuidsFluent() =>
Verify("content 651ad409-fc30-4b12-a47e-616d3f953e4c content")
.ScrubInlineGuids();
public static class ModuleInitializer
{
[ModuleInitializer]
public static void Init() =>
VerifierSettings.ScrubInlineGuids();
}
Specific Guids can be named. When any of those Guids are found, it will be replaced with the supplied name.
[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);
}
[Fact]
public Task NamedGuidFluent()
{
var guid = new Guid("c8eeaf99-d5c4-4341-8543-4597c3fd40d9");
return Verify(
new
{
value = guid
})
.AddNamedGuid(guid, "instanceNamed");
}
[ModuleInitializer]
public static void Init() => VerifierSettings.AddNamedGuid(new("c8eeaf99-d5c4-4341-8543-4597c3fd40c9"), "guidName");