Say you are testing the return value of a method returning an interface:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class UnderTest
{
IInfo GetInfo()
{
// ...
}
}


interface IInfo
{
string Text { get; };
int Number { get; }
}

How to comfortably assert on the return value if you don’t know the concrete type? It turns out FluentAssertions handles anonymous types perfectly:

1
2
var underTest= new UnderTest();
underTest.GetInfo().ShouldBeEquivalentTo(new { Text="bla", Number= 13});