Skip to content

Latest commit

 

History

History
107 lines (86 loc) · 4.11 KB

verify-directory.md

File metadata and controls

107 lines (86 loc) · 4.11 KB

VerifyDirectory

Verifies all files in a directory. This approach combines UseUniqueDirectory with a target per file, to snapshot test all files in a directory.

[Fact]
public Task WithDirectory() =>
    VerifyDirectory(directoryToVerify);

snippet source | anchor

Filtering

[Fact]
public Task WithDirectoryFiltered() =>
    VerifyDirectory(
        directoryToVerify,
        include: filePath => filePath.Contains("Doc"),
        pattern: "*.txt",
        options: new()
        {
            RecurseSubdirectories = false
        });

snippet source | anchor

Optional Info

An optional info parameter can be supplied to add more context to the test. The instance passed will be json serialized.

[Fact]
public Task VerifyDirectoryWithInfo() =>
    VerifyDirectory(
        directoryToVerify,
        info: "the info");

snippet source | anchor

FileScrubber

VerifyDirectory has an optional parameter fileScrubber that allows file specific scrubbing:

[Fact]
public Task VerifyDirectoryWithFileScrubber() =>
    VerifyDirectory(
        directoryToVerify,
        fileScrubber: (path, builder) =>
        {
            if (Path.GetFileName(path) == "TextDoc.txt")
            {
                builder.Clear();
                builder.Append("New text");
            }
        });

snippet source | anchor

This applies to files where the extensions is a known text file as defined by FileExtensions.IsText.

Files with no extension

Any files in the target directory that have no extension will have .noextension added to the resulting .verified file. This is to avoid .verified being treated as the extension of that file.

These files are treated as unknown binaries by default. Given the lack of an extension, no diff tool will be launched.

Files with no extension can optionally be treated as text, with the associated diff tool being launched. This is done by using the AddTextFileConvention of EmptyFiles:

[ModuleInitializer]
public static void InitTextFileConvention() =>
    FileExtensions.AddTextFileConvention(
        path =>
        {
            var name = Path.GetFileName(path);
            return name.Equals("TextDocWithoutExtension", StringComparison.OrdinalIgnoreCase);
        });

snippet source | anchor