FrequentGuest
FrequentGuest

Reputation: 182

CollectionAssert.AreEquivalent in FluentAssertions?

I'm trying to replace usage of "CollectionAssert.AreEquivalent()" with FluentAssertion".

I've tried using ShouldAllBeEquivalentTo, but the function doesn't fail when comparing similar objects of different types.

In the example below, both calls succeed. I want the 2nd one to fail.

new int[] { 1, 2 }.ShouldAllBeEquivalentTo( new int[] { 2, 1 } );       
new int[] { 1, 2 }.ShouldAllBeEquivalentTo( new string[] {"1", "2"} );  

Is there an alterantive function or a certain option which would make the 2nd line fail?

Upvotes: 1

Views: 422

Answers (1)

haim770
haim770

Reputation: 49095

That's because by default the TryConversionEquivalencyStep is used and it will treat both "1" and 1 as equal (after attempted conversion).

Try to remove it first:

AssertionOptions.EquivalencySteps.Remove<TryConversionEquivalencyStep>();

See Source

Upvotes: 2

Related Questions