开发者

CollectionAssert.AreEquivalent with Custom IEqualityComparer

开发者 https://www.devze.com 2023-01-08 23:23 出处:网络
I have two lists, I want to check whether the two lists are the same ( order not important), and whether it\'s the same depends on the IEqualityComparer instance I implement.

I have two lists, I want to check whether the two lists are the same ( order not important), and whether it's the same depends on the IEqualityComparer instance I implement.

The ideal case is that I can use CollectionAssert.AreEquivalent with Custom IEqualityComparer. However it seems that 开发者_如何转开发CollectionAssert.AreEquivalent doesn't take in any IEqualityComparer.

Any idea on how to do this in a succinct and reusable manner?


CollectionAssert.AreEquivalent is implemented as:

Assert.That(actual, new CollectionEquivalentConstraint(expected), message, args);

You can write out your assert that way and supply a custom IEqualityComparer with Using:

Assert.That(actual,
    new CollectionEquivalentConstraint(expected).Using(customComparer));

You can also shorten new CollectionEquivalentConstraint to Is.EquivalentTo:

Assert.That(actual, Is.EquivalentTo(expected).Using(customComparer));
0

精彩评论

暂无评论...
验证码 换一张
取 消