|
| 1 | +<!-- |
| 2 | +GENERATED FILE - DO NOT EDIT |
| 3 | +This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets). |
| 4 | +Source File: /docs/mdsource/autoverify.source.md |
| 5 | +To change this file edit the source file and then run MarkdownSnippets. |
| 6 | +--> |
| 7 | + |
| 8 | +# AutoVerify |
| 9 | + |
| 10 | +In some scenarios it makes sense to auto-accept any changes as part of a given test run. For example: |
| 11 | + |
| 12 | + * Keeping a text representation of a Database schema in a `.verified.sql` file (see [Verify.SqlServer](https://github.com/VerifyTests/Verify.SqlServer)). |
| 13 | + |
| 14 | +Note that auto accepted changes in `.verified.` files remain visible in source control tooling. |
| 15 | + |
| 16 | +This can be done using `AutoVerify()`: |
| 17 | + |
| 18 | + |
| 19 | +### Instance |
| 20 | + |
| 21 | +<!-- snippet: AutoVerify --> |
| 22 | +<a id='snippet-AutoVerify'></a> |
| 23 | +```cs |
| 24 | +var settings = new VerifySettings(); |
| 25 | +settings.AutoVerify(); |
| 26 | +``` |
| 27 | +<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L59-L64' title='Snippet source file'>snippet source</a> | <a href='#snippet-AutoVerify' title='Start of snippet'>anchor</a></sup> |
| 28 | +<!-- endSnippet --> |
| 29 | + |
| 30 | + |
| 31 | +### Fluent |
| 32 | + |
| 33 | +<!-- snippet: AutoVerifyFluent --> |
| 34 | +<a id='snippet-AutoVerifyFluent'></a> |
| 35 | +```cs |
| 36 | +[Fact] |
| 37 | +public Task AutoVerifyFluent() => |
| 38 | + Verify("Value") |
| 39 | + .AutoVerify(); |
| 40 | +``` |
| 41 | +<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L79-L86' title='Snippet source file'>snippet source</a> | <a href='#snippet-AutoVerifyFluent' title='Start of snippet'>anchor</a></sup> |
| 42 | +<!-- endSnippet --> |
| 43 | + |
| 44 | + |
| 45 | +### Globally |
| 46 | + |
| 47 | +<!-- snippet: StaticAutoVerify --> |
| 48 | +<a id='snippet-StaticAutoVerify'></a> |
| 49 | +```cs |
| 50 | +public static class ModuleInitializer |
| 51 | +{ |
| 52 | + [ModuleInitializer] |
| 53 | + public static void Init() => |
| 54 | + VerifierSettings.AutoVerify(); |
| 55 | +} |
| 56 | +``` |
| 57 | +<sup><a href='/src/ModuleInitDocs/AutoVerify.cs#L3-L12' title='Snippet source file'>snippet source</a> | <a href='#snippet-StaticAutoVerify' title='Start of snippet'>anchor</a></sup> |
| 58 | +<!-- endSnippet --> |
| 59 | + |
| 60 | + |
| 61 | +### With a delegate |
| 62 | + |
| 63 | +AutoVerify supports passing a delegate to control what subset of files to AutoVerify based on file path. |
| 64 | + |
| 65 | + |
| 66 | +### Instance |
| 67 | + |
| 68 | +<!-- snippet: AutoVerifyDelegate --> |
| 69 | +<a id='snippet-AutoVerifyDelegate'></a> |
| 70 | +```cs |
| 71 | +var settings = new VerifySettings(); |
| 72 | +settings.AutoVerify( |
| 73 | + verifiedFile => |
| 74 | + Path.GetExtension(verifiedFile) == "png"); |
| 75 | +``` |
| 76 | +<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L69-L76' title='Snippet source file'>snippet source</a> | <a href='#snippet-AutoVerifyDelegate' title='Start of snippet'>anchor</a></sup> |
| 77 | +<!-- endSnippet --> |
| 78 | + |
| 79 | + |
| 80 | +### Fluent |
| 81 | + |
| 82 | +<!-- snippet: AutoVerifyFluentDelegate --> |
| 83 | +<a id='snippet-AutoVerifyFluentDelegate'></a> |
| 84 | +```cs |
| 85 | +[Fact] |
| 86 | +public Task AutoVerifyFluentDelegate() => |
| 87 | + Verify("Value") |
| 88 | + .AutoVerify( |
| 89 | + verifiedFile => |
| 90 | + Path.GetExtension(verifiedFile) == "png"); |
| 91 | +``` |
| 92 | +<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L107-L116' title='Snippet source file'>snippet source</a> | <a href='#snippet-AutoVerifyFluentDelegate' title='Start of snippet'>anchor</a></sup> |
| 93 | +<!-- endSnippet --> |
| 94 | + |
| 95 | + |
| 96 | +### Globally |
| 97 | + |
| 98 | +<!-- snippet: StaticAutoVerifyDelegate --> |
| 99 | +<a id='snippet-StaticAutoVerifyDelegate'></a> |
| 100 | +```cs |
| 101 | +public static class ModuleInitializer |
| 102 | +{ |
| 103 | + [ModuleInitializer] |
| 104 | + public static void Init() => |
| 105 | + VerifierSettings.AutoVerify( |
| 106 | + (typeName, methodName, verifiedFile) => |
| 107 | + Path.GetExtension(verifiedFile) == "png"); |
| 108 | +} |
| 109 | +``` |
| 110 | +<sup><a href='/src/ModuleInitDocs/AutoVerifyDelegate.cs#L4-L15' title='Snippet source file'>snippet source</a> | <a href='#snippet-StaticAutoVerifyDelegate' title='Start of snippet'>anchor</a></sup> |
| 111 | +<!-- endSnippet --> |
| 112 | + |
| 113 | + |
| 114 | +## AutoVerify on the build server |
| 115 | + |
| 116 | +By default the same AutoVerify behavior applies both to local test runs and on the build server. To opt out of AutoVerify on the build server use `includeBuildServer: false`: |
| 117 | + |
| 118 | +<!-- snippet: AutoVerifyIncludeBuildServer --> |
| 119 | +<a id='snippet-AutoVerifyIncludeBuildServer'></a> |
| 120 | +```cs |
| 121 | +[Fact] |
| 122 | +public Task AutoVerifyIncludeBuildServer() => |
| 123 | + Verify("Value") |
| 124 | + .AutoVerify(includeBuildServer: false); |
| 125 | +``` |
| 126 | +<sup><a href='/src/Verify.Tests/Snippets/Snippets.cs#L89-L96' title='Snippet source file'>snippet source</a> | <a href='#snippet-AutoVerifyIncludeBuildServer' title='Start of snippet'>anchor</a></sup> |
| 127 | +<!-- endSnippet --> |
| 128 | + |
| 129 | +This can be helpful when the requirement is to minimize the friction of accepting frequent local changes, but once checked in to source control then changes to any verified file should fail a test |
0 commit comments