Replies: 1 comment
-
There's nothing built-in to do this, but a For the general case a chain of calls to class MyDto
{
public int Foo { get; set; }
public int Bar { get; set; }
}
[Fact]
public void False_positive()
{
var dtos = new[]
{
new MyDto { Foo = 13, Bar = 37 }
};
dtos.Should().ContainEquivalentOf(new { Foo = 13 })
.And.ContainEquivalentOf(new { Bar = 37 });
} I added some related notes about how to use MaximumMatchingProblem to solve this in #1486. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm looking for a way to assert that a collection contains a set of objects. I want the behavior of BeEquivalentTo combined with Contain.
So let's say my orderDtos variable contains 4 items. I want to assert that two specific items exist in the collection. Not the exact same instance of the OrderDto, but an equivalent.
This won't work. This asserts that orderDtos contains a single item that is equivalent to an array with the two items.
This fails because orderDtos contains more than the two orderDto's.
This works but seems complicated:
For simple types, the Contain method does what I want:
But as I said, I'd like to compare the object. I would even want to be able to compare with an anonymous type.
Is there a method that is able to do this that I am overlooking? Or is this just not possible?
Beta Was this translation helpful? Give feedback.
All reactions