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);
[Fact]
public Task WithDirectoryFiltered() =>
VerifyDirectory(
directoryToVerify,
include: filePath => filePath.Contains("Doc"),
pattern: "*.txt",
options: new()
{
RecurseSubdirectories = false
});
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");
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");
}
});
This applies to files where the extensions is a known text file as defined by FileExtensions.IsText.
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);
});