public void CartViewModel_Calculates_TotalPrice() { //arrange Mock <IBusinessLogicLayer> mockOfBusinessLogicLayer = new Mock <IBusinessLogicLayer>(); mockOfBusinessLogicLayer.Setup(m => m.Products).Returns(new List <Product> { new Product { ProductId = 1, Price = 50m, Name = "first" }, new Product { ProductId = 2, Price = 100m, Name = "second" }, new Product { ProductId = 3, Price = 200m, Name = "third" } }); //act CartViewModel result = new CartViewModel(mockOfBusinessLogicLayer.Object); result.AddCartLineViewModel(1, 5); result.AddCartLineViewModel(2, 5); result.AddCartLineViewModel(3, 5); //assert Assert.IsTrue(result.TotalPrice == 1750m); }
public ViewResult AddToCart(int productId, int quantity) { CartViewModel cartViewModel = GetCart(); cartViewModel.AddCartLineViewModel(productId, quantity); return(View("DisplayCart", cartViewModel)); }
public void CartViewModel_Can_Add_CartLine() { //arrange Mock <IBusinessLogicLayer> mockOfBusinessLogicLayer = new Mock <IBusinessLogicLayer>(); mockOfBusinessLogicLayer.Setup(m => m.Products).Returns(new List <Product> { new Product { ProductId = 1, Price = 50m, Name = "first" } }); //act CartViewModel result = new CartViewModel(mockOfBusinessLogicLayer.Object); result.AddCartLineViewModel(1, 5); //assert Assert.IsTrue(result.CartLineViewModels.Count == 1); Assert.IsNotNull(result.CartLineViewModels.FirstOrDefault()); }