A JsonAppender allows extra content (key value pairs) to be optionally appended to the output being verified. JsonAppenders can use the current context to determine what should be appended or if anything should be appended.
Register a JsonAppender:
VerifierSettings.RegisterJsonAppender(
context =>
{
if (ShouldInclude(context))
{
return new ToAppend("theData", "theValue");
}
return null;
});
When when content is verified:
[Fact]
public Task WithJsonAppender() =>
Verify("TheValue");
The content from RegisterJsonAppender will be included in the output:
{
target: TheValue,
theData: theValue
}
If the target is a stream or binary file:
[Fact]
public Task Stream() =>
Verify(IoHelpers.OpenRead("sample.txt"));
Then the appended content will be added to the .verified.txt
file:
{
target: null,
theData: theValue
}
See Converters for more information on *.00.verified.txt
files.
Examples of extensions using JsonAppenders are Recorders in Verify.SqlServer and Recorders in Verify.EntityFramework.