Why are nested classes ignored in FluentAssertions when using "Including"?

Viewed 812

To illustrate the problem, consider these three classes:

class Orange
{
    public String color { get; set; }
}
class Foo
{
    public Int32 size { get; set; }
    public Orange orange { get; set; }
}
class Bar
{
    public Int32 size { get; set; }
    public Orange orange { get; set; }
}

If I create instances of Foo and Bar, and set their Orange instance to be different, and then do an assertion (without using "Including") then the assertion works as expedcted; it finds the difference between "red" and "bff":

Foo foo = new Foo() { size = 3 };
foo.orange = new Orange() {color = "red" }; 

Bar bar = new Bar() { size = 3 };
bar.orange = new Orange() { color = "bff" };

foo.ShouldBeEquivalentTo(bar);  // assertion fails, as expected

But if I do the same assertion, while specifically telling FluentAssertions what to compare via "Including", the assertion doesn't catch the difference in Orange:

foo.ShouldBeEquivalentTo(bar, options => options
    .Including(o => o.size)
    .Including(o => o.orange)
    );   // assertion does not fail, why?
1 Answers
Related