Skip to content

Latest commit

 

History

History
125 lines (107 loc) · 2.92 KB

anonymous-types.md

File metadata and controls

125 lines (107 loc) · 2.92 KB

Using anonymous type

When validating multiple instances, an anonymous type can be used for verification

xUnit

[Fact]
public Task Anon()
{
    var person1 = new Person
    {
        GivenNames = "John",
        FamilyName = "Smith"
    };
    var person2 = new Person
    {
        GivenNames = "Marianne",
        FamilyName = "Aguirre"
    };

    return Verifier.Verify(
        new
        {
            person1,
            person2
        });
}

snippet source | anchor

NUnit

[Test]
public async Task Anon()
{
    var person1 = new Person
    {
        GivenNames = "John",
        FamilyName = "Smith"
    };
    var person2 = new Person
    {
        GivenNames = "Marianne",
        FamilyName = "Aguirre"
    };

    await Verifier.Verify(
        new
        {
            person1,
            person2
        });
}

snippet source | anchor

MSTest

[TestMethod]
public async Task Anon()
{
    var person1 = new Person
    {
        GivenNames = "John",
        FamilyName = "Smith"
    };
    var person2 = new Person
    {
        GivenNames = "Marianne",
        FamilyName = "Aguirre"
    };

    await Verify(
        new
        {
            person1,
            person2
        });
}

snippet source | anchor

Results

Results in the following:

{
  person1: {
    GivenNames: John,
    FamilyName: Smith
  },
  person2: {
    GivenNames: Marianne,
    FamilyName: Aguirre
  }
}

snippet source | anchor