tpierrain/NFluent

IsEquivalentTo wrongly passes when comparing a dictionary with a similar subset missing some keys

tpehkone opened this issue · 4 comments

Expected Behavior

When comparing dictionaries, IsEquivalentTo() should fail if one dictionary is missing keys present in the other. It should not matter which way around the dictionaries are compared.

Current Behavior

IsEquivalentTo() falsely passes, depending on which way the comparison is done.

Possible Solution

Code that reproduce the issue

[Test]
public void Test_Dict_IsEquivalentTo()
{
    var dictA = new Dictionary<string, string> { { "aa", "AA" }, { "bb", "BB" } };
    var dictB = new Dictionary<string, string> { { "aa", "AA" } };
    Check.ThatCode(() => Check.That(dictB).IsEquivalentTo(dictA)).Throws<AssertionException>();  // Fails, as should.
    Check.ThatCode(() => Check.That(dictA).IsEquivalentTo(dictB)).Throws<AssertionException>();  // Should fail, does not!
}

Context

Your Environment

  • Version used: 2.6.0
  • Framework version: .Net Core 2.1

Thanks for opening this issue, this is a bug indeed. Working on a fix. I will soon release a beta with fix

I published a V2.6.1 beta that fixes this issue.
Can you please try it and confirm issue is solved?
Package is available on MyGet:
https://www.myget.org/feed/dupdobnightly/package/nuget/NFluent/2.6.1-beta-0204

This seems to work fine now in my own tests, too.

fixed in V 2.7.0