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