public void CreateActionCreatesNewItem()
        {
            MockRepository mocks = new MockRepository();
            ItemRepository itemRepositoryMock = mocks.StrictMock<ItemRepository>();

            Item item = new Item { ID = 1, ItemText = "Item1" };

            using (mocks.Record())
            {
                Expect.Call(delegate { itemRepositoryMock.CreateNewItem(item); });
            }

            using (mocks.Playback())
            {
                HomeController homeController = new HomeController(itemRepositoryMock);
                RedirectToRouteResult redirectResult = homeController.Create(item) as RedirectToRouteResult;
                Assert.IsNotNull(redirectResult);
                Console.Write(redirectResult.RouteValues);
                Assert.AreEqual("Index", redirectResult.RouteValues["Action"]);
            }
        }
        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);
        }