Search code examples
fluent-assertions

how to compare subset collection by value (structural equiality) with FluentAssertions?


I want to assert if collection A is subset of collection B, using structural equality comparison (like BeEquivalentTo), using FluentAssetion. Example:

var p1 = new Point(1,2)
var p1_1 = new Point(1,2)
var p2 = new Point(2,3)
var p3 = new Point(4,5)

var A = new [] { p1 }
var B = new [] { p2, p1_1}
var C = new [] { p2, p3}

A.Should().SubsetBeEquivalentTo(B) // The assert should success
A.Should().SubsetBeEquivalentTo(C) // The assertion should fail

So, is there a way to get the behavior showed for SubsetBeEquivalentTo in the FluentAssertion library?


Solution

  • Unfortunately, ContainEquivalentOf only accepts a single item. But it's a good suggestion. Maybe you can suggest that here.