<!-- GENERATED FILE - DO NOT EDIT This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets). Source File: /docs/mdsource/anonymous-types.source.md To change this file edit the source file and then run MarkdownSnippets. --> # Using anonymous type When validating multiple instances, an [anonymous type](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/anonymous-types) can be used for verification ## NUnit <!-- snippet: AnonNUnit --> <a id='snippet-AnonNUnit'></a> ```cs [Test] public Task Anon() { var person1 = new Person { GivenNames = "John", FamilyName = "Smith" }; var person2 = new Person { GivenNames = "Marianne", FamilyName = "Aguirre" }; return Verify( new { person1, person2 }); } ``` <sup><a href='/src/Verify.NUnit.Tests/VerifyObjectSamples.cs#L40-L64' title='Snippet source file'>snippet source</a> | <a href='#snippet-AnonNUnit' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> ## xUnit <!-- snippet: AnonXunit --> <a id='snippet-AnonXunit'></a> ```cs [Fact] public Task Anon() { var person1 = new Person { GivenNames = "John", FamilyName = "Smith" }; var person2 = new Person { GivenNames = "Marianne", FamilyName = "Aguirre" }; return Verify( new { person1, person2 }); } ``` <sup><a href='/src/Verify.XunitV3.Tests/VerifyObjectSamples.cs#L21-L45' title='Snippet source file'>snippet source</a> | <a href='#snippet-AnonXunit' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> ## Fixie <!-- snippet: AnonFixie --> <a id='snippet-AnonFixie'></a> ```cs public Task Anon() { var person1 = new Person { GivenNames = "John", FamilyName = "Smith" }; var person2 = new Person { GivenNames = "Marianne", FamilyName = "Aguirre" }; return Verify( new { person1, person2 }); } ``` <sup><a href='/src/Verify.Fixie.Tests/VerifyObjectSamples.cs#L37-L60' title='Snippet source file'>snippet source</a> | <a href='#snippet-AnonFixie' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> ## MSTest <!-- snippet: AnonMSTest --> <a id='snippet-AnonMSTest'></a> ```cs [TestMethod] public Task Anon() { var person1 = new Person { GivenNames = "John", FamilyName = "Smith" }; var person2 = new Person { GivenNames = "Marianne", FamilyName = "Aguirre" }; return Verify( new { person1, person2 }); } ``` <sup><a href='/src/Verify.MSTest.Tests/VerifyObjectSamples.cs#L23-L47' title='Snippet source file'>snippet source</a> | <a href='#snippet-AnonMSTest' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> ## Results Results in the following: <!-- snippet: Verify.Xunit.Tests/VerifyObjectSamples.Anon.verified.txt --> <a id='snippet-Verify.Xunit.Tests/VerifyObjectSamples.Anon.verified.txt'></a> ```txt { person1: { GivenNames: John, FamilyName: Smith }, person2: { GivenNames: Marianne, FamilyName: Aguirre } } ``` <sup><a href='/src/Verify.Xunit.Tests/VerifyObjectSamples.Anon.verified.txt#L1-L10' title='Snippet source file'>snippet source</a> | <a href='#snippet-Verify.Xunit.Tests/VerifyObjectSamples.Anon.verified.txt' title='Start of snippet'>anchor</a></sup> <!-- endSnippet -->