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