Samer Adra
Samer Adra

Reputation: 693

FluentAssertions check that object fields not equal?

What is the best way in FluentAssertions to check that two objects are not equivalent, if the class does not implement Equals and I want to do field-by-field comparison with reflection? Basically I want the opposite of Should().BeEquivalentTo(), which is defined for all objects. There is a NotBeEquivalentTo defined for collections, but my objects are not collections.

I don't want NotBe or NotBeSameAs, because one calls Equals and the other checks references. I need something that behaves exactly the same as BeEquivalentTo. Starting to think like I might have to write my own extension method and use BeEquivalentTo and expect it to fail.

Upvotes: 4

Views: 2950

Answers (1)

Hadi R.
Hadi R.

Reputation: 413

We do not have .NotBeEquivalentTo in fluent assertion, because this is not clear to check if all fields must not be equal to assert or if just one field is not equal assertion is approved. so it is better to write an extension for your appealing result.

Upvotes: 1

Related Questions