Skip to content

Latest commit

 

History

History
155 lines (133 loc) · 3.49 KB

anonymous-types.md

File metadata and controls

155 lines (133 loc) · 3.49 KB

Using anonymous type

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

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

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

Fixie

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