我想断言两个列表的元素包含我期望的值,如下所示:
var foundCollection = fooManager.LoadFoo();
var expectedCollection = new List<Foo>()
{
new Foo() { Bar = "a", Bar2 = "b" },
new Foo() { Bar = "c", Bar2 = "d" }
};
//assert: I use AreEquivalent since the order does not matter
CollectionAssert.AreEquivalent(expectedCollection, foundCollection);
然而,上面的代码将无法工作(我猜是因为.Equals()不会为具有相同值的不同对象返回true )。在我的测试中,我只关心公共属性值,而不关心对象是否相等。我可以做些什么来做出我的断言?
https://stackoverflow.com/questions/12171411
复制相似问题