4

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.

coder
  • 8,346
  • 16
  • 39
  • 53
Samer Adra
  • 683
  • 7
  • 16
  • 2
    Could [this](https://github.com/fluentassertions/fluentassertions/issues/170) be close to what you are looking for? – egnomerator May 04 '18 at 22:58
  • Just curious, what is the case where you don't care about exact result, but just that expected value should be different? – Fabio May 05 '18 at 05:13
  • Method returns byte array representing a PDF file from content management site. If file not found, it returns a standard "Sorry, your content could not be found" but formatted as a PDF file. So I have the exact byte array representing the not-found file. If I expect something should be found, I want to assert that the byte array does not match the "not found" byte array. – Samer Adra May 07 '18 at 14:15

1 Answers1

1

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.

Hadi R.
  • 403
  • 3
  • 12
  • Now I found that fluent assertion added NotBeEquivalentTo from version 5.7 above. It means you do not need to write the extension. – Hadi R. Aug 19 '19 at 13:01