MSTest 框架有一个接受 ICollections 的 CollectionAssert。我的方法返回一个 IList。显然列表不是集合..
有没有办法让我的 IList 成为 ICollection?
MSTest 框架有一个接受 ICollections 的 CollectionAssert。我的方法返回一个 IList。显然列表不是集合..
有没有办法让我的 IList 成为 ICollection?
您可以在其上调用 ToArray() 扩展方法 - Array 实现 ICollection
编辑:另外,虽然List<T>
实现了 ICollection,IList<T>
但只实现ICollection<T>
了不实现 ICollection 的实现,所以如果你知道测试中的项目是 a List<T>
,你应该能够转换它......
您可以发送列表
List<string> actual = new List<string>(){"1","2","3"};
List<string> expected = new List<string>(){"1","2","**EditCaseFalse**"};
CollectionAssert.AreEqual(actual,expected)
我返回失败(第三个元素不匹配。)