Skip to content

Latest commit

 

History

History
83 lines (68 loc) · 3.16 KB

jsonappender.md

File metadata and controls

83 lines (68 loc) · 3.16 KB

JsonAppender

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;
    });

snippet source | anchor

When when content is verified:

[Fact]
public Task WithJsonAppender() =>
    Verify("TheValue");

snippet source | anchor

The content from RegisterJsonAppender will be included in the output:

{
  target: TheValue,
  theData: theValue
}

snippet source | anchor

If the target is a stream or binary file:

[Fact]
public Task Stream() =>
    Verify(IoHelpers.OpenRead("sample.txt"));

snippet source | anchor

Then the appended content will be added to the .verified.txt file:

{
  target: null,
  theData: theValue
}

snippet source | anchor

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.