Adds Verify support for converting YamlDotNet types.
See Milestones for release notes.
Entity Framework Extensions is a major sponsor and is proud to contribute to the development this project.
[ModuleInitializer]
public static void Init() =>
VerifyYaml.Initialize();
[Test]
public Task YamlDocumentSample()
{
var yaml =
"""
node:
original: https://www.foo.com/
short: foo
error:
code: 0
msg: No action taken
""";
var input = new StringReader(yaml);
var yamlStream = new YamlStream();
yamlStream.Load(input);
return Verify(yamlStream);
}
Results in:
[
{
node: {
error: {
msg: No action taken,
code: 0
},
short: foo,
original: https://www.foo.com/
}
}
]
Values in the json can be ignored or scrubbed:
[Test]
public Task ScrubIgnoreMemberSample()
{
var yaml =
"""
node:
original: https://www.foo.com/
short: foo
error:
code: 0
msg: No action taken
""";
var input = new StringReader(yaml);
var yamlStream = new YamlStream();
yamlStream.Load(input);
return Verify(yamlStream)
.ScrubMember("short")
.IgnoreMember("msg");
}
Results in:
[
{
node: {
error: {
code: 0
},
short: Scrubbed,
original: https://www.foo.com/
}
}
]
Json values that map to known date and time formats are scrubbed. See Guids scrubbing and Date scrubbing
[Test]
public Task GuidsAndDatesSample()
{
var yaml =
"""
node:
date: 1/10/2023
short: foo
error:
guid: 123e4567-e89b-12d3-a456-426614174000
msg: No action taken
""";
var input = new StringReader(yaml);
var yamlStream = new YamlStream();
yamlStream.Load(input);
return Verify(yamlStream);
}
Results in:
[
{
node: {
error: {
msg: No action taken,
guid: Guid_1
},
short: foo,
date: Date_1
}
}
]
Inline dates and Guids can be scrubbed:
[Test]
public Task InlineGuidsAndDatesSample()
{
var yaml =
"""
node:
date: 2023/10/01
short: foo 2023/10/01
error:
guid: 123e4567-e89b-12d3-a456-426614174000
msg: No action taken 123e4567-e89b-12d3-a456-426614174000
""";
var input = new StringReader(yaml);
var yamlStream = new YamlStream();
yamlStream.Load(input);
return Verify(yamlStream)
.ScrubInlineDates("yyyy/MM/dd")
.ScrubInlineGuids();
}
Results in:
[
{
node: {
error: {
msg: No action taken Guid_1,
guid: Guid_1
},
short: foo Date_1,
date: Date_1
}
}
]
Inline date and Guids scrubbing can also be defined globally:
Pattern designed by Grafix Point from The Noun Project.