Skip to content

Latest commit

 

History

History
97 lines (76 loc) · 3.27 KB

verify-options.md

File metadata and controls

97 lines (76 loc) · 3.27 KB

Verify Options

AutoVerify

In some scenarios it makes sense to auto-accept any changes as part of a given test run. For example:

  • Keeping a text representation of a Database schema in a .verified.sql file (see Verify.SqlServer).

This can be done using AutoVerify():

var settings = new VerifySettings();
settings.AutoVerify();

snippet source | anchor

Or globally

public static class ModuleInitializer
{
    [ModuleInitializer]
    public static void Init() =>
        VerifierSettings.AutoVerify();
}

snippet source | anchor

Note that auto accepted changes in .verified. files remain visible in source control tooling.

OnHandlers

  • OnVerify takes two actions that are called before and after each verification.
  • OnFirstVerify is called when there is no verified file.
  • OnVerifyMismatch is called when a received file does not match the existing verified file.

public Task OnHandlersSample()
{
    VerifierSettings.OnVerify(
        before: () => Debug.WriteLine("before"),
        after: () => Debug.WriteLine("after"));
    VerifierSettings.OnFirstVerify(
        (receivedFile, receivedText) =>
        {
            Debug.WriteLine(receivedFile);
            return Task.CompletedTask;
        });
    VerifierSettings.OnVerifyMismatch(
        (filePair, message) =>
        {
            Debug.WriteLine(filePair.ReceivedPath);
            Debug.WriteLine(filePair.VerifiedPath);
            Debug.WriteLine(message);
            return Task.CompletedTask;
        });
    return Verify("value");
}

snippet source | anchor

OmitContentFromException

By default, when a verify mismatch occurs for text, the content of the received and verified files is included in the exception that is thrown. This results in that text being included in test runners and build output. To omit the content use VerifierSettings.OmitContentFromException.

DisableDiff

To disable diff launching:

var settings = new VerifySettings();
settings.DisableDiff();

snippet source | anchor