### Full F# Test Example Source: https://github.com/verifytests/verify/blob/main/docs/fsharp.md A comprehensive example demonstrating F# test setup with Argon, including custom settings and asynchronous verification. ```fsharp module Tests open Xunit open VerifyTests open VerifyXunit open Argon VerifierSettings.AddExtraSettings(fun settings -> settings.DefaultValueHandling <- DefaultValueHandling.Include) [] let MyTest () = Verifier.Verify(15).ToTask() |> Async.AwaitTask [] let WithFluentSetting () = Verifier .Verify(15) .UseMethodName("customName") .ToTask() |> Async.AwaitTask do () ``` -------------------------------- ### Sample Test with Verify Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Windows_VisualStudioWithReSharper_Gui_TUnit_AzureDevOps.source.md A basic example of a test using Verify to compare a string. Ensure necessary Verify NuGet packages are installed. ```csharp await Verify("Hello world"); ``` -------------------------------- ### Sample Expecto Test with Verify Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Rider_Gui_Expecto_AppVeyor.source.md A basic test case demonstrating how to use Verify within an Expecto test. This example assumes necessary setup and imports are in place. ```csharp [Test] let "should verify string" = async { await Verify "Hello Expecto!" } ``` -------------------------------- ### Sample TUnit Test Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Rider_Cli_TUnit_AzureDevOps.source.md A basic TUnit test example demonstrating snapshot testing with Verify. This snippet assumes necessary setup and imports are in place. ```csharp using VerifyTests; public class SampleTests { [Fact] public Task Should_pass() => Verify("hello"); } ``` -------------------------------- ### Scrubbers Example for xUnit Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/scrubbers.source.md A comprehensive example demonstrating the usage of various scrubbers within an xUnit test. ```csharp public class ScrubbersSampleXunit { [Fact] public Task Instance() => Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }) .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName(); [Fact] public Task InstanceWithScrubber() => Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }) .AddScrubber(s => s.Replace("foo", "bar")) .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName(); [Fact] public Task InstanceWithScrubberDisabled() => Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }) .DisableScrubbers() .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName(); [Fact] public Task InstanceWithScrubberDisabledFluent() => Approvals.Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }, scrubbers => scrubbers.Disable() .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName()); } ``` -------------------------------- ### Scrubbers Example for TUnit Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/scrubbers.source.md A comprehensive example demonstrating the usage of various scrubbers within a TUnit test. ```csharp public class ScrubbersSampleTUnit { [Test] public Task Instance() => Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }) .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName(); [Test] public Task InstanceWithScrubber() => Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }) .AddScrubber(s => s.Replace("foo", "bar")) .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName(); [Test] public Task InstanceWithScrubberDisabled() => Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }) .DisableScrubbers() .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName(); [Test] public Task InstanceWithScrubberDisabledFluent() => Approvals.Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }, scrubbers => scrubbers.Disable() .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName()); } ``` -------------------------------- ### Install Verify.Terminal Tool Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Cli_Expecto_GitHubActions.source.md Install the verify.tool as a global dotnet tool for managing snapshots from the command line. This is an optional tool. ```bash dotnet tool install -g verify.tool ``` -------------------------------- ### Expecto Test Example Source: https://github.com/verifytests/verify/blob/main/readme.source.md Provides an example of snapshot testing with Expecto. ```fsharp [ test "sample test" <@ let myClass = MyClass() let value = myClass.GetValue(1) verify value @] ] ``` -------------------------------- ### Scrubbers Example for Fixie Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/scrubbers.source.md A comprehensive example demonstrating the usage of various scrubbers within a Fixie test. ```csharp public class ScrubbersSampleFixie { public Task Instance() => Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }) .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName(); public Task InstanceWithScrubber() => Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }) .AddScrubber(s => s.Replace("foo", "bar")) .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName(); public Task InstanceWithScrubberDisabled() => Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }) .DisableScrubbers() .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName(); public Task InstanceWithScrubberDisabledFluent() => Approvals.Verify(new { Guid = Guid.Empty, datetime = DateTime.Now, MachineName = Environment.MachineName, User = Environment.UserName, }, scrubbers => scrubbers.Disable() .ScrubGuids() .ScrubDates() .ScrubMachineName() .ScrubUserName()); } ``` -------------------------------- ### Install DiffEngineTray Tool Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Windows_Other_Cli_Expecto_AppVeyor.source.md Install the DiffEngineTray as a global .NET tool. This tool monitors snapshot changes and allows for accepting or rejecting them, which is optional but recommended. ```bash dotnet tool install -g DiffEngineTray ``` -------------------------------- ### Example Snapshot File Content Source: https://github.com/verifytests/verify/blob/main/docs/compared-to-assertion.md This is an example of a generated snapshot file in .txt format. It shows the expected structure and content for the 'SnapshotTest'. ```txt { GivenNames: John, FamilyName: Smith, Spouse: Jill, Address: { Street: 4 Puddle Lane, Country: USA }, Children: [ Sam, Mary ], Id: Guid_1 } ``` -------------------------------- ### Sample Test with XunitV3 Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Cli_XunitV3_None.source.md A basic example of a test using Verify with XunitV3. ```csharp snippet: SampleTestXunitV3 ``` -------------------------------- ### MSTest VerifyBase Usage Example Source: https://github.com/verifytests/verify/blob/main/docs/wiz/Windows_VisualStudioWithReSharper_Cli_MSTest_GitHubActions.md Inherit from `VerifyBase` to simplify test setup when using Verify with MSTest. This example shows a basic test method that verifies string content. ```csharp [TestClass] public class VerifyBaseUsage : VerifyBase { [TestMethod] public Task Simple() => Verify("The content"); } ``` -------------------------------- ### Instance Comparer Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/comparer.source.md Demonstrates how to use an instance comparer. ```csharp await Verify(value, settings => { settings.UseComparer(new InstanceComparer( (instance1, instance2) => CompareResult.Equal )); }); ``` -------------------------------- ### Scrubber Levels Example for xUnit Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/scrubbers.source.md Demonstrates how to configure scrubbers at different levels (method, class, global) using xUnit. ```csharp public class ScrubberLevelsSampleXunit { [Fact] public Task Instance() => Verify("test"); [Fact] public Task InstanceWithScrubber() => Verify("test").AddScrubber(s => s.Replace("foo", "bar")); [Fact] public Task InstanceWithScrubberDisabled() => Verify("test").DisableScrubbers(); [Fact] public Task InstanceWithScrubberDisabledFluent() => Approvals.Verify("test", scrubbers => scrubbers.Disable()); } ``` -------------------------------- ### Sample MSTest Test Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Gui_MSTest_GitHubActions.source.md A basic MSTest test case demonstrating the use of Verify. This example assumes necessary Verify packages are installed. ```csharp [TestClass] public class SampleTests { [TestMethod] public Task ShouldPass() => Verify("Hello"); } ``` -------------------------------- ### Sample Fixie Test Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Rider_Cli_Fixie_AzureDevOps.source.md A basic example of a test using Fixie and Verify.NET. This snippet is intended to be illustrative and may require additional setup. ```csharp public class Sample { [Fact] public Task Basic() => Verify("Hello"); } ``` -------------------------------- ### Scrubber Levels Example for Fixie Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/scrubbers.source.md Demonstrates how to configure scrubbers at different levels (method, class, global) using Fixie. ```csharp public class ScrubberLevelsSampleFixie { public Task Instance() => Verify("test"); public Task InstanceWithScrubber() => Verify("test").AddScrubber(s => s.Replace("foo", "bar")); public Task InstanceWithScrubberDisabled() => Verify("test").DisableScrubbers(); public Task InstanceWithScrubberDisabledFluent() => Approvals.Verify("test", scrubbers => scrubbers.Disable()); } ``` -------------------------------- ### Sample TUnit Test with Verify Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Gui_TUnit_GitHubActions.source.md A basic TUnit test demonstrating the use of Verify. This example assumes necessary Verify packages are installed and configured. ```csharp public class SampleTests { [Fact] public Task Sample() => Verify("Hello World"); } ``` -------------------------------- ### Global Static Settings with Module Initializer Source: https://github.com/verifytests/verify/blob/main/readme.source.md Demonstrates setting global Verify settings using a C# Module Initializer, which runs before any test code. ```csharp public class Initializer
{
[ModuleInitializer]
public static void Initialize()
{
VerifySettings.AddScrubber(text => text.Replace("secret", "***"));
}
} ``` -------------------------------- ### Create and Use TempFile Source: https://github.com/verifytests/verify/blob/main/docs/temp-file.md Demonstrates basic usage of TempFile for creating a temporary file, writing content to it, and automatic cleanup upon disposal. ```cs [Fact] public void Usage() { using var temp = new TempFile(); File.WriteAllText(temp, "content"); // file automatically deleted here } ``` -------------------------------- ### Sample TUnit Test Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Cli_TUnit_AzureDevOps.source.md A basic TUnit test example demonstrating how to use Verify within a test method. This serves as a starting point for writing your own tests. ```csharp public class SampleTests { [Fact] public Task ShouldPass() => Verify("Hello"); } ``` -------------------------------- ### Scrubber Levels Example for TUnit Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/scrubbers.source.md Demonstrates how to configure scrubbers at different levels (method, class, global) using TUnit. ```csharp public class ScrubberLevelsSampleTUnit { [Test] public Task Instance() => Verify("test"); [Test] public Task InstanceWithScrubber() => Verify("test").AddScrubber(s => s.Replace("foo", "bar")); [Test] public Task InstanceWithScrubberDisabled() => Verify("test").DisableScrubbers(); [Test] public Task InstanceWithScrubberDisabledFluent() => Approvals.Verify("test", scrubbers => scrubbers.Disable()); } ``` -------------------------------- ### Sample Test with Verify.XunitV3 Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Cli_XunitV3_AzureDevOps.source.md A basic sample test demonstrating the usage of Verify with XunitV3. This test verifies a simple string. ```csharp public class Sample { [Fact] public Task Usage() { return Verify("Hello World"); } } ``` -------------------------------- ### Sample NUnit Test with Verify Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Gui_NUnit_GitHubActions.source.md A basic NUnit test case demonstrating the usage of Verify for assertions. This example assumes necessary setup and imports are in place. ```csharp public class Tests { [Test] public Task Basic() => Verify("Hello World"); } ``` -------------------------------- ### Sample Test with Verify.XunitV3 Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Cli_XunitV3_GitHubActions.source.md A basic sample test demonstrating the usage of Verify.XunitV3. This test verifies a simple string. ```csharp public class SampleTests { [Fact] public Task Basic() => Verify("Hello World"); } ``` -------------------------------- ### Sample XUnit V3 Test with Verify Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/MacOS_Rider_Gui_XunitV3_AzureDevOps.source.md A basic example of an XUnit V3 test using Verify to assert a string. Ensure you have the necessary Verify and XUnit packages installed. ```csharp [Fact] public Task Basic() => "Hello World".Verify(); ``` -------------------------------- ### Sample Verify Test Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Gui_XunitV3_GitHubActions.source.md A basic sample test demonstrating Verify usage with XunitV3. ```cs public class MyTests { [Fact] public Task Basic() { var settings = new VerifySettings(); settings.UseDirectory("Fixtures"); return Verify("Hello", settings); } } ``` -------------------------------- ### Sample NUnit Test with Verify Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Gui_NUnit_AzureDevOps.source.md A basic example of a test case using Verify within an NUnit test method. Ensure necessary setup and using directives are in place. ```csharp [Test] public Task ShouldPass() => Verify("This is a test"); ``` -------------------------------- ### Initialize All Plugins Automatically Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/plugins.source.md Use `VerifierSettings.InitializePlugins()` in a `ModuleInitializer` to automatically discover and load all available Verify plugins. ```csharp public static class ModuleInitializer { [ModuleInitializer] public static void Initialize() => VerifierSettings.InitializePlugins(); } ``` -------------------------------- ### Sample Fixie Test with Verify Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Rider_Gui_Fixie_AzureDevOps.source.md A basic example of a Fixie test using Verify to assert a result. Ensure necessary setup like implicit usings or explicit imports is in place. ```csharp public class SampleTests { [Fact] public Task Should_pass() { // Arrange var data = new SampleData(10, "hello"); // Act & Assert return Verify(data); } } ``` -------------------------------- ### Scoped Recording with `using` Source: https://github.com/verifytests/verify/blob/main/docs/recording.md Shows how to use a `using` statement with `Recording.Start()` to limit the scope of recording. Any `Recording.Add` calls outside this scope are ignored. ```cs using VerifyTests; [Fact] public Task RecordingScoped() { using (Recording.Start()) { Recording.Add("name1", "value1"); } // Recording.Add is ignored here Recording.Add("name2", "value2"); return Verify(); } ``` -------------------------------- ### Sample Test with Verify Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Windows_Rider_Gui_XunitV3_None.source.md A basic XunitV3 test using Verify to assert a string. This demonstrates a typical verification scenario. ```csharp public class SampleTests { [Fact] public Task ShouldPass() => Verify("Hello World"); } ``` -------------------------------- ### Sample TUnit Test with Verify Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Gui_TUnit_AzureDevOps.source.md A basic example of a TUnit test using Verify to assert the received output against a verified baseline. Ensure the test setup includes necessary Verify initializations. ```csharp await Verify("Hello World"); ``` -------------------------------- ### Sanitize Guids - Verify Source: https://github.com/verifytests/verify/blob/main/docs/guids.md Demonstrates how Verify sanitizes GUIDs by default. This ensures repeatable tests by replacing GUIDs with sequential counters. ```cs var guid = Guid.NewGuid(); var target = new GuidTarget { Guid = guid, GuidNullable = guid, GuidString = guid.ToString(), OtherGuid = Guid.NewGuid() }; await Verify(target); ``` ```txt { Guid: Guid_1, GuidNullable: Guid_1, GuidString: Guid_1, OtherGuid: Guid_2 } ``` -------------------------------- ### Verified Output with Inferred Named GUID Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/guids.source.md This is the expected verified output when using an inferred named GUID. The GUID is replaced by its inferred name. ```text myGuid ``` -------------------------------- ### Sample Expecto Test with Verify Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Gui_Expecto_GitHubActions.source.md A basic sample test using Expecto and Verify to demonstrate snapshot testing. Ensure you have the necessary setup for Verify. ```csharp [Tests] let "should compare strings" = test "hello world" <|> "hello world" ``` -------------------------------- ### Use Named GUID (Global) Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/guids.source.md Globally assigns a name to a specific GUID across all tests. This is useful for consistently replacing a known GUID. ```csharp VerifySettings.NamedGuid(Guid.Parse("00000000-0000-0000-0000-000000000001"), "my-guid"); ``` -------------------------------- ### Enable Default GUID Sanitization Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/guids.source.md This snippet enables the default GUID sanitization behavior, which replaces GUIDs with a counter-based value for repeatable tests. ```csharp using VerifyTests; // ... [Fact] public Task ReUseGuid() { return Verify("a guid: " + Guid.NewGuid()); } ``` -------------------------------- ### Basic Recording Usage Source: https://github.com/verifytests/verify/blob/main/docs/recording.md Starts recording, adds a key-value pair, and then verifies a string value. The added information will be included in the snapshot. ```cs using VerifyTests; [Fact] public Task Usage() { Recording.Start(); Recording.Add("name", "value"); return Verify("TheValue"); } ``` -------------------------------- ### Use Named GUID (Instance) Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/guids.source.md Allows replacing specific GUIDs with a predefined name for a given test instance. This is useful for standardizing known GUIDs. ```csharp [Fact] public class MyTests { [Fact] public Task NamedGuidInstance() { var guid = Guid.Parse("00000000-0000-0000-0000-000000000001"); return Verify(guid).NamedGuid("my-guid"); } } ``` -------------------------------- ### Add NuGet Packages for Verify XunitV3 Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Linux_Other_Cli_XunitV3_AppVeyor.source.md Install the necessary NuGet packages for Verify and XunitV3. Ensure you are using the prerelease versions for xunit packages. ```bash dotnet add package Microsoft.NET.Test.Sdk dotnet add package Verify.XunitV3 dotnet add package xunit.v3 --prerelease dotnet add package xunit.runner.visualstudio --prerelease ``` -------------------------------- ### Enable Inline GUID Scrubbing (Instance) Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/guids.source.md Enables scrubbing of inline GUIDs within strings for a specific test instance. This ensures consistency for GUIDs embedded in text. ```csharp [Fact] public class MyTests { [Fact] public Task ScrubInlineGuidsInstance() { // enable scrubbing for this test instance return Verify("a guid: " + Guid.NewGuid()).ScrubInlineGuids(); } } ``` -------------------------------- ### Sample Expecto Test Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Windows_VisualStudioWithReSharper_Gui_Expecto_AppVeyor.source.md A basic sample test using Expecto to verify a string. Ensure you have the necessary NuGet packages installed. ```fsharp test "string" { let incoming = "Hello Expecto" incoming |> VerifyString() } ``` -------------------------------- ### Sample Test with Expecto Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/wiz/Windows_Other_Gui_Expecto_None.source.md A sample test using the Expecto framework with VerifyTests. This demonstrates a basic test case structure. ```fsharp test "sample" <@ "hello" ``` -------------------------------- ### Scrub Inline Guids (Instance) - Verify Source: https://github.com/verifytests/verify/blob/main/docs/guids.md Enables scrubbing of GUIDs found within strings for a specific verification instance. Useful for verifying string content containing dynamic GUIDs. ```cs [Fact] public Task ScrubInlineGuidsInstance() { var settings = new VerifySettings(); settings.ScrubInlineGuids(); return Verify( "content 651ad409-fc30-4b12-a47e-616d3f953e4c content", settings); } ``` -------------------------------- ### Custom JsonConverter Example Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/serializer-settings.source.md Example of defining a custom `JsonConverter` that can be registered with the serializer. ```csharp public class MyConverter : WriteOnlyJsonConverter { protected override void WriteValue(VerifyJsonWriter writer, MyClass value) { writer.WriteValue("custom value"); } } ``` -------------------------------- ### Scrubber Levels Example for NUnit Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/scrubbers.source.md Demonstrates how to configure scrubbers at different levels (method, class, global) using NUnit. ```csharp [TestFixture] public class ScrubberLevelsSampleNUnit { [VerifySettings] public VerifySettings MethodSettings = new VerifySettings { }; [Test] public Task Instance() => Verify("test", MethodSettings); [Test] public Task InstanceWithScrubber() => Verify("test", MethodSettings.AddScrubber(s => s.Replace("foo", "bar"))); } ``` -------------------------------- ### Implement ITestProject and IExecution for Verify Source: https://github.com/verifytests/verify/blob/main/docs/mdsource/fixie-convention.include.md This example shows how to implement the ITestProject and IExecution interfaces to integrate Fixie with Verify. Ensure the target assembly is assigned in ITestProject.Configure and test executions are wrapped in IExecution.Run. ```csharp public class TestProject : ITestProject { public void Configure(ITestConfiguration configuration) { configuration .For() .AssignTargetAssembly(typeof(TestProject).Assembly); } } public class MyTests { [Fact] public Task Should_verify_something() => Verify("hello") .AppendExtension("txt"); } ```