| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
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. Guids in the D format (00000000-0000-0000-0000-000000000000) and the N format (00000000000000000000000000000000) are matched when bounded by non-alphanumeric characters. B and P formatted Guids are covered by the D format matching between their delimiters. Note that any 32 character hex sequence is a valid N format Guid, so hex content of that exact length (an MD5 hash for example) will 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();
}By default both the D and N formats are scrubbed. To restrict scrubbing to specific formats, pass a GuidFormats value. This is useful for avoiding the scrubbing of 32 character hex content (an MD5 hash for example) that would otherwise match the N format:
// Only the "D" format is scrubbed. The 32 char hex hash is left untouched.
[Fact]
public Task ScrubInlineGuidsDashedOnly() =>
Verify("guid: 173535ae-995b-4cc6-a74e-8cd4be57039c hash: 5d41402abc4b2a76b9719d911017c592")
.ScrubInlineGuids(GuidFormats.Dashed);Results in the following, where the D format Guid is scrubbed but the hash is left untouched:
guid: Guid_1 hash: 5d41402abc4b2a76b9719d911017c592Specific 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");The name can be inferred from the variable name by omitting the name argument:
[Fact]
public Task InferredNamedGuidFluent()
{
var namedGuid = new Guid("c8eeaf99-d5c4-4341-8543-4597c3fd40d9");
return Verify(
new
{
value = namedGuid
})
.AddNamedGuid(namedGuid);
}Result:
{
value: namedGuid
}| Back | FazBrowse Home | New Git URL |