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
}The name part of the JsonAppender can be inferred:
[Fact]
public Task WithInferredNameJsonAppenderFluent()
{
var name = "value";
return Verify("TheValue")
.AppendValue(name);
}Results in:
{
target: TheValue,
theData: theValue,
name: value
}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:
{
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.