0
我在以下链接上自学关于TDD的内容; http://msdn.microsoft.com/en-us/library/gg416511%28VS.98%29.aspx无法获取CollectionAssert的正确语法
我发现一些代码是错误的,这是令人失望的主题是关于测试,但我不应该抱怨太多,因为从错误中学习是很好的。
但是我从来没有用过;在下面的代码不能编译之前收集集合;
[TestMethod]
public void Index_Get_RetrievesAllContactsFromRepository()
{
// Arrange
Contact contact1 = GetContact(1, "Orlando", "Gee");
Contact contact2 = GetContact(2, "Keith", "Harris");
InMemoryContactRepository repository = new InMemoryContactRepository();
repository.Add(contact1);
repository.Add(contact2);
var controller = GetHomeController(repository);
// Act
var result = controller.Index();
// Assert
var model = (ICollection<Contact>)result.ViewData.Model;
CollectionAssert.Contains(model, contact1);
CollectionAssert.Contains(model, contact2);
}
错误消息是 错误4参数1:不能从 '了System.Collections.Generic.ICollection' 到 'System.Collections.ICollection' C转换:\ MVC3 \训练\ MvcContracts \ MvcContracts.Tests \ Controllers \ HomeControllerTest.cs 94 39 MvcContracts.Tests
我试着将ICollection强制转换为IEnumerable,但这样做有效果。
这是行不通的。 ToList()不适用于ICollection对象。我也尝试在前一行将演员从ICollection更改为IList,但这也不起作用。 – arame3333 2011-06-09 10:09:38