Excluding certain properties when asserting objects with FluentAssertion

It’s very common that we assert if two objects are equivalent in unit tests. Using FluentAssertion, this looks like the following

However, there are times where you want to exclude certain properties when comparing objects. This might be because the value of the property cannot be predicted or you just don’t want to include that property in the assertion. FluentAssert provides an overload method ShouldBeEquivalentTo that allows you to specify which property to exclude.

And to exclude certain properties when asserting if two arrays of object are equivalent, you can do the following

 

Like this post?

Leave a Reply

Your email address will not be published. Required fields are marked *