Skip to content

Sometimes BeEquivalentTo reports incorrect message for dictionary key mismatch #1450

@stevebroshar

Description

@stevebroshar

Description

BeEquivalentTo reports an incorrect message when dictionaries have same number of items and first items match, but some item has key mismatch. The message says that the key is missing from pair[key] where key is the first item key value. It's hard to describe, so see fiddle and example below.

See fiddle https://dotnetfiddle.net/DeeDi2

Complete minimal example reproducing the issue

var actual = new Dictionary<string,string>
{
	{"a", "x"},
	{"b", "x"},
};
var expected = new Dictionary<string,string>
{
	{"a", "x"},
	{"c", "x"}, // key mismatch
};

actual.Should().BeEquivalentTo(expected);

Expected behavior:

Logged output should be something like: Expected subject to contain key "c".

If remove the item with key "a" from both actual and expected, then output references subject, correctly.

Actual behavior:

Logged output: Expected pair[a] to contain key "c".

Versions

  • Which version of Fluent Assertions are you using? Tried with latest: 6.0.0.0-alpha0001, as well as 5.10.3. Same results in both.
  • Which .NET runtime and version are you targeting? .NET Core 3.1.

Additional Information

I discovered this issue at same time: #1449

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions