public void InsertCartItemTest() { CartRepository.AddToCart(cart); var cartFromList = CartRepository.GetCartItemById(cart.Id); Assert.AreEqual(cart, cartFromList); }
public void GetCartItemByProductIdTest() { CartRepository.AddToCart(cart); var cartItemFromList = CartRepository.GetCartItemByProductId(cart.StockControl.Product.Id); Assert.IsNotNull(cartItemFromList); }
public void GetCartItemByIdTest() { CartRepository.AddToCart(cart); var cartFromList = CartRepository.GetCartItemById(cart.Id); Assert.IsNotNull(cartFromList); }
public void InsufficientAmountIncreaseQuantityTest() { CartRepository.AddToCart(cart2); var increasedQuantity = CartRepository.IncreaseQuantity(cart2.StockControl.Product.Id); Assert.IsFalse(increasedQuantity); }
public void IncreaseQuantityTest() { CartRepository.AddToCart(cart); var increasedQuantity = CartRepository.IncreaseQuantity(cart.StockControl.Product.Id); Assert.IsTrue(increasedQuantity); }
public void RemoveCartItemTest() { CartRepository.AddToCart(cart); var cartItemFromList = CartRepository.GetCartItemById(cart.Id); CartRepository.RemoveCartItem(cartItemFromList); var checkRemovedCartItem = CartRepository.GetCartItemById(cartItemFromList.Id); Assert.IsNull(checkRemovedCartItem); }
public void UpdateCartItemTest() { CartRepository.AddToCart(cart); var cartFromList = CartRepository.GetCartItemByProductId(cart.StockControl.Product.Id); cartFromList.Quantity = 2; CartRepository.Update(cartFromList); Assert.Contains(cartFromList, CartRepository.GetCartItems()); }
public int AddToCart(int ItemId, string ItemName) { Cart cart = new Cart(); int count = GetTotal(); count++; cart.ItemId = ItemId; cart.ItemName = ItemName + " in Cart " + count; cartRepository.AddToCart(cart); return(cart.Id); }
public String Add([FromRoute] string item) { string session_id = Request.Headers["session-id"]; if (session_id == null) { Console.WriteLine("Session running"); Guid id = allCarts.AddNewCart(item); Response.Headers.Add("session-id", id.ToString()); } else { allCarts.AddToCart(Guid.Parse(session_id), item); } return("Item added to Shopping Cart"); }
public ActionResult Create(int productId) { try { var cartInList = CartRepository.GetCartItemByProductId(productId); if (cartInList != null) { if (cartInList.StockControl.ProductAmount > cartInList.Quantity) { cartInList.Quantity = ++cartInList.Quantity; CartRepository.Update(cartInList); } else { var stockControls = Repository.StockControlRepository.GetStockControls(); ModelState.AddModelError(string.Empty, "Nuk ka produkt te mjaftueshem ne stok!"); return(View("~/Views/StockControls/Index.cshtml", stockControls)); } } else { var cartItem = new Cart { Quantity = 1, CreatedAt = DateTimeOffset.Now, StockControlId = productId, StockControl = Repository.StockControlRepository.GetStockControlById(productId) }; CartRepository.AddToCart(cartItem); } return(RedirectToAction(nameof(Index), "StockControls")); } catch { return(View()); } }
public static void AddToCart(int UserId, int ProductId, int Quantity) { Cart newCart = new CartFactory().CreateCartData(UserId, ProductId, Quantity); CartRepository.AddToCart(newCart); }