public void CanGetSummaryViewModel() { IRepository <Basket> baskets = new Mock.MockContext <Basket>(); IRepository <Product> products = new Mock.MockContext <Product>(); products.Insert(new Product() { Id = "1", Price = 10 }); products.Insert(new Product() { Id = "2", Price = 30 }); Basket basket = new Basket(); basket.BasketItems.Add(new BasketItem() { ProductId = "1", Quantity = 3 }); basket.BasketItems.Add(new BasketItem() { ProductId = "2", Quantity = 5 }); baskets.Insert(basket); IBasketService basketService = new BasketService(products, baskets); var controller = new BasketController(basketService); var httpContext = new Mock.MockHttpContext(); httpContext.Request.Cookies.Add(new System.Web.HttpCookie("eCommerceBasket") { Value = basket.Id }); controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); var result = controller.BasketSummary() as PartialViewResult; var basketSummary = (BasketSummaryViewModel)result.ViewData.Model; Assert.AreEqual(8, basketSummary.BasketCount); Assert.AreEqual(180, basketSummary.BasketTotoal); }
public void IndexPageDoesReturnProducts() { IRepository <Product> productContext = new Mock.MockContext <Product>(); IRepository <ProductCategory> productCategoryContext = new Mock.MockContext <ProductCategory>(); productContext.Insert(new Product()); HomeController controller = new HomeController(productContext, productCategoryContext); var result = controller.Index() as ViewResult; var viewModel = (ProductListViewModel)result.ViewData.Model; Assert.AreEqual(1, viewModel.Products.Count()); }