public void Insert_ShoppingCart_Test() { Product p1 = new Product(); p1.Id = Guid.NewGuid(); p1.Title = "iphone7 plus"; p1.Price = 6000; p1.ImgPath = "http://www.abc.com/static/plus6.jpg"; Product p2 = new Product(); p2.Id = Guid.NewGuid(); p2.Title = "Think Pad"; p2.Price = 5500; p2.ImgPath = "http://www.abc.com/static/pad.jpg"; ShoppingCart cart = new ShoppingCart(); cart.Id = Guid.NewGuid(); cart.CustomerId = Guid.NewGuid(); cart.AddItem(p1.Id, p1.Price, 1); cart.AddItem(p2.Id, p2.Price, 2); IRepository <ShoppingCart> shoppingCartRepository = new ShoppingCartRepository(); Assert.AreEqual <bool>(true, shoppingCartRepository.Insert(cart)); Assert.IsNotNull(shoppingCartRepository.GetById(cart.Id)); }
public String AddToCart(int id) { //not supposed to be here, should be after login event customer = customerRepo.GetById(1); shoppingCart = new ShoppingCart(customer.Id); shoppingCart.CreatedBy = shoppingCart.LastModifiedBy = "Customer Name"; // create a ShoppingCartRepository scr object //use scr to save shoppingCart ShoppingCartRepository scr = new ShoppingCartRepository(ConstantUtil.MyConnectionString); int shoppingCartId = scr.Insert(shoppingCart); ProductRepository pr = new ProductRepository(ConstantUtil.MyConnectionString); Product p = pr.GetById(id); ShoppingCartProduct scp = new ShoppingCartProduct(shoppingCartId, id); scp.Quantity = 100; scp.UnitOfMeasure = p.UnitOfMeasure; scp.UnitPrice = p.UnitPrice; scp.CreatedBy = p.CreatedBy; scp.LastModifiedBy = p.LastModifiedBy; scp.CreatedDate = p.CreatedDate; scp.LastModifiedDate = p.LastModifiedDate; scp.SubTotal = scp.Quantity * scp.UnitPrice; //create a ShoppinngCartProductRepository scpr //use scpr to save scp ShoppingCartProductRepository scpr = new ShoppingCartProductRepository(ConstantUtil.MyConnectionString); scpr.Create(scp); return("Add product " + id + " to the cart successfully!"); }