<!-- GENERATED FILE - DO NOT EDIT This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets). Source File: /docs/mdsource/verify-file.source.md To change this file edit the source file and then run MarkdownSnippets. --> # VerifyFile Verifies the contents of a file. <!-- snippet: VerifyFile --> <a id='snippet-VerifyFile'></a> ```cs [Fact] public Task VerifyFilePath() => VerifyFile("sample.txt"); ``` <sup><a href='/src/Verify.Tests/StreamTests.cs#L190-L196' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyFile' 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: VerifyFileWithInfo --> <a id='snippet-VerifyFileWithInfo'></a> ```cs [Fact] public Task VerifyFileWithInfo() => VerifyFile( "sample.txt", info: "the info"); ``` <sup><a href='/src/Verify.Tests/StreamTests.cs#L216-L224' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyFileWithInfo' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> ## Using a custom extension <!-- snippet: VerifyFileExtension --> <a id='snippet-VerifyFileExtension'></a> ```cs [Fact] public Task VerifyFilePathWithExtension() => VerifyFile("sample.txt", extension: "csv"); ``` <sup><a href='/src/Verify.Tests/StreamTests.cs#L198-L204' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyFileExtension' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> ## Verify a file without using a unit test Use the functionality of VerifyTests outside of a unit test. <!-- snippet: VerifyFileWithoutUnitTest --> <a id='snippet-VerifyFileWithoutUnitTest'></a> ```cs public async Task VerifyExternalFile() { using var verifier = new InnerVerifier(targetDirectory, name: "sample"); await verifier.VerifyFile(filePath); } ``` <sup><a href='/src/Verify.Tests/InnerVerifyTests/InnerVerifyTests.cs#L17-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyFileWithoutUnitTest' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> Result: ``` {targetDirectory}/sample.verified.txt ```