Skip to content

Latest commit

 

History

History
125 lines (107 loc) · 2.89 KB

anonymous-types.md

File metadata and controls

125 lines (107 loc) · 2.89 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 Verify(
        new
        {
            person1,
            person2
        });
}

snippet source | anchor

NUnit

[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
        });
}

snippet source | anchor

MSTest

[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
        });
}

snippet source | anchor

Results

Results in the following:

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

snippet source | anchor