public void Test_Case_For_Get_Products_Total_Cost() { CartItem _cartItem = new CartItem(); _cartItem.AddToCart(new Product("SamSung", 10000), 2); _cartItem.AddToCart(new Product("ViVo", 14000), 2); Cart _cart = new Cart(_cartItem); var _actualResult = _cart.GetTotalPrice(); Assert.Equal(48000, _actualResult); }
public void Test_Case_For_Add_Products() { CartItem _cartItem = new CartItem(); _cartItem.AddToCart(new Product("SamSung", 10000), 2); _cartItem.AddToCart(new Product("ViVo", 14000), 2); Dictionary <Product, int> _expectedResult = new Dictionary <Product, int>(); _expectedResult.Add(new Product("SamSung", 10000), 2); _expectedResult.Add(new Product("ViVo", 14000), 2); var _actualResult = _cartItem.GetProductList(); Assert.Equal(_expectedResult.ToString(), _actualResult.ToString()); }
protected void Page_Load(object sender, EventArgs e) { if (Session["modal"] == null || Session["modal"].ToString().Equals("hide")) { CartItem cart = new CartItem(); List <CartItemEntity> list; if (ProductID > 0) { list = cart.Select(ProductID); } else { list = cart.Select(2); } modalContent.DataSource = list; modalContent.DataBind(); // Set the info for popup cart LblSubQuantity.Text = "0"; LblSubAmount.Text = "0"; } else { CartItem cart = new CartItem(); CartItemEntity cartItem = cart.AddToCart(ProductID, Quantity); modalContent.DataSource = new List <CartItemEntity>() { cartItem }; modalContent.DataBind(); // Set the info for popup cart LblSubQuantity.Text = cartItem.Quantity.ToString(); LblSubAmount.Text = cartItem.Total.ToString(); } Control control = (Control)sender; mainPage = control.Page.ToString(); mainPage = mainPage.Substring(4); mainPage = mainPage.Substring(0, mainPage.Length - 5); }
public ActionResult Buy() { string id = Request["txtID"]; string name = Request["txtName"]; float price = float.Parse(Request["txtPrice"]); string description = Request["txtDescription"]; int quantity = int.Parse(Request["txtQuantity"]); string image = Request["txtImage"]; ProductDTO p = new ProductDTO(id, name, price, description, image); CartItem c = (CartItem)Session["CART"]; if (c == null) { c = new CartItem(); c.AddToCart(p, quantity); Session.Add("CART", c); } else { c.AddToCart(p, quantity); } // if (TempData["PreviousPage"] != null) { if ((int)TempData["PreviousPage"] == 1) { return(RedirectToAction("SearchRandom")); } else if ((int)TempData["PreviousPage"] == 2) { return(RedirectToAction("ViewCart")); } } return(RedirectToAction("SearchProduct")); }