2

Using FluentAssertions 3.5.1, I'm trying to assert that a List of Integer arrays is equivalent to another list of integer arrays, without caring about item order. This is not working. In trying to break this problem down, I've tried to assert that they are equal when they do have the same order and that's not working either:

var a = new List <Int32[]> { new Int32[] { 1, 2 } };
var b = new List <Int32[]> { new Int32[] { 1, 2 } };

a.Should().BeEquivalentTo(b);

This gives me the message:

Expected collection {{1, 2}} to be equivalent to {{1, 2}}, but it misses {{1, 2}}.

Perhaps BeEquivalentTo is not the right assertion for comparing nested collections??

Michael

CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
Michael Ray Lovett
  • 6,668
  • 7
  • 27
  • 36

1 Answers1

3

You can fix it by using next code:

a.ShouldBeEquivalentTo(b);

or

a.ShouldAllBeEquivalentTo(b);

It will work, because ShouldBeEquivalentTo is deep equals comparison and Should().BeEquivalentTo() isn't.

Kote
  • 2,116
  • 1
  • 19
  • 20
  • Thanks. I'm new to the library and I haven't found any docs yet explaining these kinds of things yet ;( – Michael Ray Lovett Feb 24 '16 at 19:55
  • 1
    You can find the ordering documentation [here](https://github.com/dennisdoomen/fluentassertions/wiki#ordering). By default, it will ignore the order, unless you use the `WithStrictOrdering` option. – Dennis Doomen Feb 25 '16 at 09:47