How to test nested collections using FluentAssertions

I have the following specification

BidirectionalGraph Fixture = new BidirectionalGraph(); public void VerticesShouldBeAbleToAssociateMultipleEdges() { int a = 0; int b = 1; int c = 2; Fixture.AddEdge(a, b); Fixture.AddEdge(b, c); Fixture.AddEdge(c, a); Fixture.EdgesFrom(a).Should().BeEquivalentTo ( new []{a, b} , new []{a, c}); } 

where EdgesFrom is defined like this

 public IEnumerable<int[]> EdgesFrom(int vertex) 

however my test failed with

 Result Message: Expected collection {{0, 1}, {0, 2}} to be equivalent to {{0, 1}, {0, 2}}. 

This is not entirely reasonable for me, as they are obviously equivalent. FluentAssertions just not work when comparing collections of collections?

+4
source share
1 answer

This is because collection.Should (). BeEquivalentTo () uses the standard Equals () implementation of your type to make sure that every element in the first collection appears somewhere in the second collection. You really need the new equivalence that I introduced in Fluent Assertions 2.0. Unfortunately, I only recently found out about the confusing syntax (collection.Should (). BeEquivalentTo () vs ShouldAllBeEquivalentTo ()).

+2
source

Source: https://habr.com/ru/post/1480060/


All Articles