<!-- GENERATED FILE - DO NOT EDIT This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets). Source File: /docs/mdsource/verify-directory.source.md To change this file edit the source file and then run MarkdownSnippets. --> # VerifyDirectory Verifies all files in a directory. This approach combines [UseUniqueDirectory](/docs/naming.md#useuniquedirectory) with a target per file, to snapshot test all files in a directory. <!-- snippet: VerifyDirectoryXunitV3 --> <a id='snippet-VerifyDirectoryXunitV3'></a> ```cs [Fact] public Task WithDirectory() => VerifyDirectory(directoryToVerify); ``` <sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L92-L98' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyDirectoryXunitV3' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> ## Filtering <!-- snippet: VerifyDirectoryFilterXunitV3 --> <a id='snippet-VerifyDirectoryFilterXunitV3'></a> ```cs [Fact] public Task WithDirectoryFiltered() => VerifyDirectory( directoryToVerify, include: filePath => filePath.Contains("Doc"), pattern: "*.txt", options: new() { RecurseSubdirectories = false }); ``` <sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L129-L142' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyDirectoryFilterXunitV3' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> ## Optional Info An optional `info` parameter can be supplied to add more context to the test. The instance passed will be json serialized. <!-- snippet: VerifyDirectoryWithInfoXunitV3 --> <a id='snippet-VerifyDirectoryWithInfoXunitV3'></a> ```cs [Fact] public Task VerifyDirectoryWithInfo() => VerifyDirectory( directoryToVerify, info: "the info"); ``` <sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L100-L108' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyDirectoryWithInfoXunitV3' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> ## FileScrubber `VerifyDirectory` has an optional parameter `fileScrubber` that allows file specific scrubbing: <!-- snippet: VerifyDirectoryWithFileScrubberXunitV3 --> <a id='snippet-VerifyDirectoryWithFileScrubberXunitV3'></a> ```cs [Fact] public Task VerifyDirectoryWithFileScrubber() => VerifyDirectory( directoryToVerify, fileScrubber: (path, builder) => { if (Path.GetFileName(path) == "TextDoc.txt") { builder.Clear(); builder.Append("New text"); } }); ``` <sup><a href='/src/Verify.XunitV3.Tests/Tests.cs#L110-L125' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyDirectoryWithFileScrubberXunitV3' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> This applies to files where the extensions is a known text file as defined by [FileExtensions.IsText](https://github.com/VerifyTests/EmptyFiles#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](https://github.com/VerifyTests/EmptyFiles?tab=readme-ov-file#addtextfileconvention) of EmptyFiles: <!-- snippet: AddTextFileConvention --> <a id='snippet-AddTextFileConvention'></a> ```cs [ModuleInitializer] public static void InitTextFileConvention() => FileExtensions.AddTextFileConvention( path => { var name = Path.GetFileName(path); return name.Equals("TextDocWithoutExtension", StringComparison.OrdinalIgnoreCase); }); ``` <sup><a href='/src/Verify.Tests/VerifyDirectoryTests.cs#L6-L15' title='Snippet source file'>snippet source</a> | <a href='#snippet-AddTextFileConvention' title='Start of snippet'>anchor</a></sup> <!-- endSnippet -->