### Approvals.AssertText Before Example Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/mdsource/Features.source.md The initial state before using in-line assertions. ```csharp assert_text_before ``` -------------------------------- ### Custom Verify helper method Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/explanations/MainConcepts.md An example of how to extract repeated verification logic into a custom helper method. ```cs public static void VerifyMyObject(MyObject o) { // Do something to an Object // Print an Object ToString // Verify the ToString } ``` -------------------------------- ### Implement IApprovalFailureReporter Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/Reporters.md Create a custom reporter by implementing the IApprovalFailureReporter interface. This example demonstrates launching a file upon test failure. ```cs namespace ApprovalTests.Reporters; public class FileLauncherReporter : IApprovalFailureReporter { public static readonly FileLauncherReporter INSTANCE = new(); public void Report(string approved, string received) { QuietReporter.DisplayCommandLineApproval(approved, received); Process.Start(received); } } ``` -------------------------------- ### Simple Verify call Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/explanations/MainConcepts.md A basic example of using the Approvals.Verify method to test a string. ```cs [Test] public void Text() => Approvals.Verify("should be approved"); ``` -------------------------------- ### Example approval file names for OS variations Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/EnvironmentSpecificTests.md This list shows how approval files are named when including OS-specific information, resulting in distinct files for different Windows versions and other operating systems. ```txt Like LockDownTests.TestExceptions.Microsoft_Windows_10_Education.approved.txt LockDownTests.TestExceptions.Mac.approved.txt LockDownTests.TestExceptions.Microsoft_Windows_10_Enterprise.approved.txt LockDownTests.TestExceptions.Microsoft_Windows_10_Home_N.approved.txt LockDownTests.TestExceptions.Microsoft_Windows_10_Pro.approved.txt LockDownTests.TestExceptions.Microsoft_Windows_11_Enterprise.approved.txt LockDownTests.TestExceptions.Microsoft_Windows_11_Pro.approved.txt LockDownTests.TestExceptions.Microsoft_Windows_Server_2016_Datacenter.approved.txt LockDownTests.TestExceptions.Microsoft_Windows_Server_2019_Datacenter.approved.txt LockDownTests.TestExceptions.Microsoft_Windows_Server_2022_Datacenter.approved.txt LockDownTests.TestExceptions.Windows_7.approved.txt LockDownTests.TestExceptions.Windows_8.approved.txt ``` -------------------------------- ### Approvals.AssertText After Example Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/mdsource/Features.source.md The state after using in-line assertions, where the result is stored as an array of strings. ```csharp assert_text ``` -------------------------------- ### ApprovalsFilename Output Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/mdsource/Features.source.md The resulting filename produced by the ApprovalsFilename parsing example. ```text ApprovalsFilenameTest.TestMachineSpecificName.approved.txt ``` -------------------------------- ### Example of MachineSpecificReporter output Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/mdsource/EnvironmentSpecificTests.source.md When using a MachineSpecificReporter, if an approval file is missing, it copies the last approved version from a different machine and adds a header indicating the source. ```text Copied from: EmailTest.Testname.Microsoft_Windows_10_Pro.approved.eml ``` -------------------------------- ### Verifying a List with ApprovalTests Source: https://github.com/approvals/approvaltests.net/blob/master/readme.source.md This snippet demonstrates the basic usage of ApprovalTests to verify a list. It produces a .received.txt file and triggers a diff tool for comparison. ```csharp sample_test ``` -------------------------------- ### Create a CustomDiffReporter class Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/howtos/CustomizingDiffToolSelectionOrder.md Define a custom reporter by inheriting from FirstWorkingReporter and passing the desired DiffTool instances to the base constructor in your preferred order. ```cs public class CustomDiffReporter : FirstWorkingReporter { public CustomDiffReporter() : base( //TODO: re-order or remove as required BeyondCompareReporter.INSTANCE, TortoiseDiffReporter.INSTANCE, AraxisMergeReporter.INSTANCE, P4MergeReporter.INSTANCE, WinMergeReporter.INSTANCE, KDiff3Reporter.INSTANCE, VisualStudioReporter.INSTANCE, RiderReporter.INSTANCE, FrameworkAssertReporter.INSTANCE, QuietReporter.INSTANCE ) { } } ``` -------------------------------- ### Configure Continuous Integration Reporters Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/mdsource/Reporters.source.md ApprovalTests automatically detects CI environments and suppresses reporter launches. Use the FrontLoadedReporter annotation to configure behavior in these environments. ```csharp snippet: continuous_integration ``` -------------------------------- ### Verify a list with ApprovalTests Source: https://github.com/approvals/approvaltests.net/blob/master/readme.md Demonstrates using Approvals.VerifyAll to verify a sorted array of names. This test requires a reporter to open a diff tool on failure. ```cs [UseReporter(typeof(VisualStudioReporter))] [TestFixture] public class SampleTest { [Test] public void TestList() { var names = new[] {"Llewellyn", "James", "Dan", "Jason", "Katrina"}; Array.Sort(names); Approvals.VerifyAll(names, label: ""); } } ``` -------------------------------- ### Create a CustomDiffReporter class Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/howtos/mdsource/CustomizingDiffToolSelectionOrder.source.md Define a custom reporter class to specify your preferred order of DiffTools, then apply it using the [UseReporter] attribute. ```csharp public class CustomDiffReporter : FirstWorkingReporter { public CustomDiffReporter() : base( new BeyondCompareReporter(), new DiffMergeReporter(), new TortoiseTextDiffReporter()) { } } ``` -------------------------------- ### Continuous Integration Reporters Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/Reporters.md List of supported CI environment reporters used by the DefaultFrontLoaderReporter to suppress UI launches in automated environments. ```cs TfsReporter.INSTANCE, TfsVnextReporter.INSTANCE, TeamCityReporter.INSTANCE, JenkinsReporter.INSTANCE, BambooReporter.INSTANCE, NCrunchReporter.INSTANCE, MyGetReporter.INSTANCE, GoContinuousDeliveryReporter.INSTANCE, AppVeyorReporter.INSTANCE ``` -------------------------------- ### Approvals.Verify Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/Verify.md Verifies a file by its path. ```APIDOC ## Approvals.Verify(FileInfo receivedFilePath) ### Description Verifies the content of a file specified by a FileInfo object. ### Parameters - **receivedFilePath** (FileInfo) - Required - The path to the file to be verified. ``` -------------------------------- ### UseApprovalSubdirectoryAttribute usage Source: https://github.com/approvals/approvaltests.net/wiki/Controlling-where-approved-files-are-saved Apply the UseApprovalSubdirectoryAttribute to a test method, class, or assembly to redirect approval files into a specified subdirectory. ```csharp [Test] [UseApprovalSubdirectory("Foo")] public void TestSourcePath() { Approvals.Verify(true); } ``` -------------------------------- ### Approvals.Verify Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/mdsource/Verify.source.md Verifies the content of a file against an approved version. ```APIDOC ## Approvals.Verify(FileInfo receivedFilePath) ### Description Verifies the content of the specified file against an approved version. ### Parameters - **receivedFilePath** (FileInfo) - The path to the file to be verified. ``` -------------------------------- ### ApprovalsFilename Parsing Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/Features.md Demonstrates parsing an approval filename to extract its constituent parts. ```cs var approvalsFilename = ApprovalsFilename.Parse(@"..\Email\EmailTest.Testname.Microsoft_Windows_10_Education.approved.eml"); ``` ```txt GetFullPath: ..\Email\EmailTest.Testname.Microsoft_Windows_10_Education.approved.eml Directory: ..\Email ClassName: EmailTest MethodName: Testname AdditionalInformation: [Microsoft_Windows_10_Education] ApprovedStatus: approved Extension: eml ``` -------------------------------- ### Launch Multiple Reporters Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/ReportersGettingStarted.md Combine multiple reporters to trigger several actions simultaneously upon test failure. ```cs [UseReporter(typeof(DiffReporter), typeof(FileLauncherReporter))] ``` -------------------------------- ### NamerFactory.AsEnvironmentSpecificTest usage Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/EnvironmentSpecificTests.md Use NamerFactory.AsEnvironmentSpecificTest to inject custom additional information into the approval file name. The cleanup ensures the information is removed after test execution. ```cs using(var cleanup = NamerFactory.AsEnvironmentSpecificTest(()=> "Any.Additional.Data")) { } ``` -------------------------------- ### Combine Multiple Reporters Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/mdsource/ReportersGettingStarted.source.md Use the MultiReporter syntax to launch multiple reporters simultaneously upon test failure. ```csharp [UseReporter(typeof(DiffReporter), typeof(ClipboardReporter))] ``` -------------------------------- ### Simple C# string Source: https://github.com/approvals/approvaltests.net/blob/master/src/ApprovalTests.Tests/Reporters/InlineTextReporterTest.CSharpStrings.approved.txt A basic string variable assignment. ```csharp var expected = "boo"; ``` -------------------------------- ### Approved file content for TestList Source: https://github.com/approvals/approvaltests.net/blob/master/readme.md The expected output file content for the TestList test case. ```txt [0] = Dan [1] = James [2] = Jason [3] = Katrina [4] = Llewellyn ``` -------------------------------- ### Approvals.AssertText Initial State Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/Features.md The initial state of a test using Approvals.AssertText with an empty expected string before the actual output is generated. ```cs var header = new Header(); var actual = header.MakeHeading("I am ten chars"); var expected = ""; Approvals.AssertText(expected, actual); ``` -------------------------------- ### Configure Assembly Level Reporter Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/ReportersGettingStarted.md Set the default reporter for the entire assembly by adding this attribute to an ApprovalTestsConfig.cs file. ```cs [assembly: UseReporter(typeof(DiffReporter))] ``` -------------------------------- ### UseReporter attribute with MachineSpecificReporter Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/EnvironmentSpecificTests.md Apply the UseReporter attribute with MachineSpecificReporter to automatically copy the last approved version from a different machine if the current file is missing. ```cs [UseReporter(typeof(MachineSpecificReporter))] ``` -------------------------------- ### Extracting a custom Verify helper method Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/explanations/mdsource/MainConcepts.source.md When you find yourself repeating the process of transforming an object and verifying its string representation, extract a custom helper method to encapsulate that logic. ```cs // Do something to an Object // Print an Object ToString // Verify the ToString ``` ```cs public static void VerifyMyObject(MyObject o) { // Do something to an Object // Print an Object ToString // Verify the ToString } ``` -------------------------------- ### Approvals.VerifyXml Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/Verify.md Verifies an XML string. ```APIDOC ## Approvals.VerifyXml(String xml) ### Description Verifies the provided XML string content. ### Parameters - **xml** (String) - Required - The XML string to verify. ``` -------------------------------- ### VerifyWithExtension method signature Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/explanations/MainConcepts.md A method used for verifying text with a specific file extension, often used when formatting text before verification. ```cs public static void VerifyWithExtension(string text, string fileExtensionWithDot, Func scrubber = null) ``` -------------------------------- ### Approvals.VerifyException Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/Verify.md Verifies an exception. ```APIDOC ## Approvals.VerifyException(Exception e) ### Description Verifies the details of an exception. ### Parameters - **e** (Exception) - Required - The exception object to verify. ``` -------------------------------- ### Disposables.Create usage Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalUtilities/readme.md Creates a disposable object using a lambda expression to perform cleanup actions when the using block exits. ```cs using (Disposables.Create(() => callCount++)) { //code } ``` -------------------------------- ### Verify method signature Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/explanations/MainConcepts.md The core Verify method that utilizes an IApprovalWriter, IApprovalNamer, and IApprovalFailureReporter. ```cs public static void Verify(IApprovalWriter writer, IApprovalNamer namer, IApprovalFailureReporter reporter) ``` -------------------------------- ### Approvals.VerifyJson Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/Verify.md Verifies a JSON string. ```APIDOC ## Approvals.VerifyJson(String json) ### Description Verifies the provided JSON string content. ### Parameters - **json** (String) - Required - The JSON string to verify. ``` -------------------------------- ### Guard.AgainstNullAndEmpty usage Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalUtilities/readme.md Use this function to validate that a string argument is neither null nor empty. ```cs Guard.AgainstNullAndEmpty(subdirectory, nameof(subdirectory)); ``` -------------------------------- ### ApprovalTests Received File Output Source: https://github.com/approvals/approvaltests.net/blob/master/readme.source.md The expected output file generated by the test verification process. ```text SampleTest.TestList.received.txt ``` -------------------------------- ### ApprovalResults.UniqueForOs usage Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/EnvironmentSpecificTests.md Use ApprovalResults.UniqueForOs to include the operating system in the approval file name, ensuring unique files for different OS environments. ```cs using (ApprovalResults.UniqueForOs()) { Approvals.Verify("Data"); } ``` -------------------------------- ### Apply UseReporter attribute Source: https://github.com/approvals/approvaltests.net/blob/master/src/ApprovalTests.Tests/Reporters/IntroductionReporterTest.TestComment.approved.txt Add the [UseReporter] attribute to your class, test method, or assembly to specify the reporter used by ApprovalTests. ```csharp [UseReporter(typeof(DiffReporter))] ``` -------------------------------- ### Approvals.AssertText Inline Expectation Source: https://github.com/approvals/approvaltests.net/blob/master/docs/ApprovalTests/Features.md The updated test state where the expected output is provided as an array of strings for inline verification. ```cs var header = new Header(); var actual = header.MakeHeading("I am ten chars"); var expected = new[]{ "**************", "I am ten chars", "**************", }; Approvals.AssertText(expected, actual); ``` -------------------------------- ### C# string array Source: https://github.com/approvals/approvaltests.net/blob/master/src/ApprovalTests.Tests/Reporters/InlineTextReporterTest.CSharpStrings.approved.txt An array of strings used for multi-line text representation. ```csharp var expected = new[]{ "**************", "I am ten chars", "**************", }; ``` -------------------------------- ### Configure IgnoreLineEndingsAttribute in AssemblyInfo.cs Source: https://github.com/approvals/approvaltests.net/blob/master/readme.source.md Add this attribute to your AssemblyInfo.cs file to enable verification of line endings, which are ignored by default. ```csharp [assembly: IgnoreLineEndingsAttribute(false)] ``` -------------------------------- ### ApprovalTests Approved File Output Source: https://github.com/approvals/approvaltests.net/blob/master/readme.source.md The approved file used to validate the test results. ```text SampleTest.TestList.approved.txt ``` -------------------------------- ### C# string with escaped quotes Source: https://github.com/approvals/approvaltests.net/blob/master/src/ApprovalTests.Tests/Reporters/InlineTextReporterTest.CSharpStrings.approved.txt A string variable containing escaped double quotes. ```csharp var expected = "with \"quotes\"."; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.