单元测试的IList与CollectionAssert [英] Unit-testing IList with CollectionAssert

查看:143
本文介绍了单元测试的IList与CollectionAssert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MSTest的框架有一个接受ICollections一个CollectionAssert。 我的方法返回一个IList。显然列表不是一个集合。

The MSTest framework has a CollectionAssert that accepts ICollections. My method returns an IList. Apparently a list is not a collection..

有没有办法让我的IList的一个ICollection的?

Are there ways to make my IList an ICollection?

推荐答案

您可以调用的ToArray()扩展方法就可以了 - 阵列实现的ICollection

You could call the ToArray() extension method on it - Array implements ICollection

编辑:另外,虽然名单,其中,T> 实现ICollection的,的IList< T> 只实现的ICollection< T> 不实现ICollection的,所以如果你知道在测试的项目是名单,其中,T> ,你应该能够施展它...

Also, while List<T> implements ICollection, IList<T> only implements ICollection<T> which does not implement ICollection, so if you know the item in the test is a List<T>, you should be able to cast it...

这篇关于单元测试的IList与CollectionAssert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆