CollectionAssert.AreEquivalent 与自定义 IEqualityComparer
我有两个列表,我想检查两个列表是否相同(顺序不重要),是否相同取决于我实现的 IEqualityComparer 实例。
理想的情况是我可以将 CollectionAssert.AreEquivalent
与自定义 IEqualityComparer
结合使用。然而,CollectionAssert.AreEquivalent
似乎不接受任何IEqualityComparer
。
关于如何以简洁且可重用的方式做到这一点有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CollectionAssert.AreEquivalent
实现为:您可以以这种方式写出您的断言,并使用
Using
提供自定义IEqualityComparer
:您还可以缩短
new CollectionEquivalentConstraint
为Is.EquivalentTo
:CollectionAssert.AreEquivalent
is implemented as:You can write out your assert that way and supply a custom
IEqualityComparer
withUsing
:You can also shorten
new CollectionEquivalentConstraint
toIs.EquivalentTo
: