Recently I answered SO question describing how to avoid internal object state validation in FluentAssertions. Now I faced the same problem and wondering why does FluentAssertions validate internal properties OOTB?
public class Class1
{
[Fact]
public void CompareCultureInternalFields()
{
var foo1 = new Foo();
var foo2 = new Foo();
foo1.ShouldBeEquivalentTo(foo2); // fails
}
public object Culture { get; set; }
}
public class Foo
{
public Foo()
{
InternalProp = Guid.NewGuid();
}
internal Guid InternalProp { get; }
}
Exception details:
Xunit.Sdk.XunitException: Expected member InternalProp to be {61625b04-c4e6-4e08-a45a-5ff8bb7d53e7}, but found {df589d73-e382-4104-8157-a41da2ca17f5}.
With configuration:
- Use declared types and members
- Compare enums by value
- Match member by name (or throw)
- Be strict about the order of items in byte arrays
Shouldn't the foo1
and foo2
objects be equivalent for a consumer who deals with the public API?