Skip to content

Latest commit

 

History

History
81 lines (66 loc) · 2.9 KB

verify-directory.md

File metadata and controls

81 lines (66 loc) · 2.9 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 WithZipAndStructure() =>
    VerifyZip(zipPath, includeStructure: true);

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.