ARTICLE AD BOX
In my unit tests I want to compare two collections of complex objects.
The object has a identity property (primary key) and some additional properties that need to be compared.
How do I display the identity property in the error message.
Currently I'm just getting index in expected collection, like:
Expected property actual[1].Prop2 to be the same string, but they differ at index 0:
↓ (actual)
"invalidValue"
"expectedValue"
↑ (expected).
But I would like to show something like "MyKey = "value0" in the error message
class Foo { public string MyKey { get; set; } public string Prop2 { get; set; } } [Fact] public void Test() { var expected = new[] { new Foo { MyKey = "value0", Prop2 = "expectedValue" }, new Foo { MyKey = "value1", Prop2 = "expectedValue" }, }; var actual = new[] { new Foo { MyKey = "value0", Prop2 = "expectedValue" }, new Foo { MyKey = "value1", Prop2 = "invalidValue" }, }; actual.Should().BeEquivalentTo(expected, options => { options.Using<Foo>(ctx => { ctx.Subject.Prop1.Should().Be(ctx.Expectation.Prop1); }); return options; }); }