public ViewResult RemoveFromCart(int productId) { CartViewModel cartViewModel = GetCart(); cartViewModel.RemoveCartLineViewModel(productId); Product product = businessLayer.Products.Where(p => p.ProductId == productId).First(); TempData["message"] = string.Format("{0} was successfully removed from your cart", product.Name); return(View("DisplayCart", cartViewModel)); }
public void CartViewModel_Removes_CartLineViewModels() { //arrange Mock <IBusinessLogicLayer> mockOfBusinessLogicLayer = new Mock <IBusinessLogicLayer>(); Product product = new Product { ProductId = 1, Price = 50m, Name = "first" }; mockOfBusinessLogicLayer.Setup(m => m.Products).Returns(new List <Product> { product }); //act CartViewModel result = new CartViewModel(mockOfBusinessLogicLayer.Object); result.CartLineViewModels = new List <CartLineViewModel> { new CartLineViewModel { CartLineId = 1, ProductId = 1, Product = product, Quantity = 5 } }; result.RemoveCartLineViewModel(1); //assert Assert.IsTrue(result.CartLineViewModels.Count == 0); }