I'm trying to compare two objects with multiple properties, but need specific properties to be compared using a predicate (object1
does not have exact values for those properties at object2
, so I need to compare partial strings there).
So, I'm trying:
object1.Should().BeEquivalentTo(object2, options => options
.Including(o => o.Property1.StartsWith("something"))
.Including(o => o.Property2.StartsWith("something else")
);
I expect all other properties be compared as usual.
However, running the code above throws exception:
Message: System.ArgumentException : Expression
<Convert(o.Property1.StartsWith("something"), Object)>
cannot be used to select a member. Parameter name: expression
I checked documentation and it has the same example as mine (chapter "Selecting Members" at https://fluentassertions.com/objectgraphs/).
Why does this exception occur and how do I fix it?