public void IndexActionProvidesTheItemsToTheView() { MockRepository mocks = new MockRepository(); ItemRepository itemRepositoryMock = mocks.StrictMock<ItemRepository>(); List<Item> expectedItems = new List<Item>(); expectedItems.Add(new Item { ID = 1, ItemText = "Item1" }); expectedItems.Add(new Item { ID = 2, ItemText = "Item2" }); using (mocks.Record()) { Expect.Call(itemRepositoryMock.GetAllItems()).Return(expectedItems); } using (mocks.Playback()) { HomeController homeController = new HomeController(itemRepositoryMock); ViewResult result = homeController.Index() as ViewResult; IEnumerable<Item> actualItems = (IEnumerable<Item>)result.ViewData.Model; Assert.IsNotNull(actualItems); CollectionAssert.AreEqual(actualItems.ToList(), expectedItems); } }
public void IndexActionRendersIndexView() { MockRepository mocks = new MockRepository(); ItemRepository itemRepositoryMock = mocks.StrictMock<ItemRepository>(); HomeController homeController = new HomeController(itemRepositoryMock); ViewResult result = homeController.Index() as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("Index", result.ViewName); }