使用 MSpec 比较两个列表

发布于 2024-09-30 01:19:09 字数 40 浏览 0 评论 0原文

我应该使用哪种方法来断言两个列表包含具有 MSpec 的相同对象?

Which method should I use to assert that two lists contains the same objects with MSpec?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

知足的幸福 2024-10-07 01:19:09

您可以使用 ShouldContainOnly(IEnumerable) 扩展方法。

因此,如果您有 2 个列表,listAlistB 使用:

listA.ShouldContainOnly(listB)

You could use the ShouldContainOnly(IEnumerable<T>) extension method.

So if you have 2 lists, listA and listB use:

listA.ShouldContainOnly(listB)
孤檠 2024-10-07 01:19:09

如果列表中项目的顺序不重要,则可以使用

listA.ShouldContainOnly(listB); // both lists must have exactly the same items
listA.ShouldContain(listB);     // listA must at least contain the items of listB

如果项目的顺序很重要,则可以使用

listA.ShouldEqual(listB);

If the order of the items in the list doesn't matter, you would use

listA.ShouldContainOnly(listB); // both lists must have exactly the same items
listA.ShouldContain(listB);     // listA must at least contain the items of listB

If the order of the items matters, you can use

listA.ShouldEqual(listB);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文