2

I've created the following very simple test which is a simplification of a scenario I've come across in the wild.

var actual = new JObject
{
    {"prop1" , "1"},
    {"prop2" , "2"},
};

var expected = new JObject
{
    {"prop1" , "3"},
    {"prop2" , "2"},
};

actual.Should().BeEquivalentTo(expected);
           

I have two JObjects which differ at a single key and I would like a test to fail if they differ and tell me where the difference is.

This passes but I wouldn't expect it to because of the difference I've already mentioned. I've spend quite a bit of time messing around with customizing the equivalency check with no luck. Hopefully someone can point out what I've overlooked.

Ben Franklin
  • 626
  • 6
  • 21

1 Answers1

3

You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation.

Reference FluentAssertions - Dictionaries

Like

actual.Should().Equal(expected);
Nkosi
  • 235,767
  • 35
  • 427
  • 472