public void AddTest() { CartManager manager = new CartManager(); manager.Add(12); manager.Add(16); manager.Add(15); manager.Add(12); manager.Add(15); }
/// <summary> /// 将书籍作为参数加入到购物车中,在Cart表中跟踪每个书辑的数量 /// 在这个方法中,我们将会检查是在表中增加一行,还是仅仅在用户已经选择的书辑上增加数量 /// </summary> /// <param name="book"></param> public void AddToCart(Book book) { //根据cartId和购买书籍的编号获取购物车对象 var cartItem = cm.GetCart(ShoppingCartId, book.Id); //如果没有该条信息,则新增一条 if (cartItem == null) { cartItem = new Cart { Book = new Book { Id = book.Id }, CartId = ShoppingCartId, Count = 1, DateCreated = DateTime.Now }; //添加Cart cm.Add(cartItem); } else { //如果存在,则改变该商品购买的数量 cartItem.Count++; cm.UpdateCount(cartItem.RecordId, cartItem.Count); } }
protected void ProductsRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) { HiddenField ProductLinkHiddenField = (HiddenField)((RepeaterItem)e.Item).FindControl("ProductLinkHiddenField"); if (!string.IsNullOrWhiteSpace(ProductLinkHiddenField.Value)) { Response.Redirect(ProductLinkHiddenField.Value); return; } HiddenField ProductIDHiddenField = (HiddenField)((RepeaterItem)e.Item).FindControl("ProductIDHiddenField"); int productID = Utils.GetDecodedInt(HttpUtility.UrlDecode(ProductIDHiddenField.Value)); if (productID == -1) { return; } if (e.CommandName == "AddToCart") { DeleteSavedCart(); CartManager manager = new CartManager(((BasePage)Page).Cart); manager.Add(productID); ((BasePage)Page).Cart = manager.ShoppingCart; Response.Redirect("ShoppingCart.aspx"); } else if (e.CommandName == "Customize") { Label ProductNameLabel = e.Item.FindControl("ProductNameLabel") as Label; Response.Redirect("Product.aspx?Product=" + HttpUtility.UrlEncode(ProductNameLabel.Text) + "&ProductID=" + WebUtility.EncodeParamForQueryString(productID.ToString())); } }
public void RemoveCurrentProductToCart() { var cartManager = new CartManager(); var cartItem = new CartItem { Product = new Product { ProductId = 1, ProductName = "Laptop", UnitPrice = 2500 }, Quantity = 1 }; cartManager.Add(cartItem); //Arrange int excepted = cartManager.TotalItem - 1; //Act cartManager.Remove(cartItem.Product.ProductId); var totalItems = cartManager.TotalItem; Assert.AreEqual(excepted, totalItems); }
public void CartManager_Can_Remove_Object() { List <CartItem> mySession = new List <CartItem>(); Mock <ISessionManager> mockSession = new Mock <ISessionManager>(); Mock <ISongRepository> mockRepository = new Mock <ISongRepository>(); mockSession.Setup(x => x.Set <List <CartItem> >(It.IsAny <string>(), It.IsAny <List <CartItem> >())).Callback((string e, List <CartItem> s) => mySession = s); mockSession.Setup(x => x.Get <List <CartItem> >(It.IsAny <string>())).Returns(mySession); //mockSession.Setup(x => x.Remove<List<CartItem>>(It.IsAny<string>())).Callback(() => mySession.Clear()); mockRepository.Setup(x => x.Songs).Returns(new Song[] { new Song() { SongId = 1, NameSong = "Test1" }, new Song() { SongId = 2, NameSong = "Test2" }, new Song() { SongId = 3, NameSong = "Test3" }, new Song() { SongId = 4, NameSong = "Test4" } }); CartManager target = new CartManager(mockSession.Object, mockRepository.Object); target.Add(1); target.Add(2); target.Add(1); target.Add(3); target.Remove(1); target.Remove(3); Assert.AreEqual(2, mySession.Count); Assert.AreEqual(1, mySession[0].Song.SongId); Assert.AreEqual(1, mySession[0].Quantity); Assert.AreEqual(2, mySession[1].Song.SongId); }
[HttpPost]//manager kur response kur jsondan cagır.. public ActionResult AddToCart(AddToCartRequest request) { CartManager manager = new CartManager(); string message = manager.Add(request.ProductID); AddToCartResponse response = new AddToCartResponse(); response.Message = message; return(Json(response)); }
public void Sepete_farkli_urunden_bir_adet_eklendiginde_sepetteki_toplam_urun_adeti_ve_eleman_sayisi_bir_artmalidir() { //Arrange int toplamAdet = _cartManager.TotalQuantity; int toplamElemanSayisi = _cartManager.TotalItems; //Act _cartManager.Add(new CartItem { Product = new Product { ProductId = 2, ProductName = "Mouse", UnitPrice = 10 }, Quantity = 1 }); //Assert Assert.AreEqual(toplamAdet + 1, _cartManager.TotalQuantity); Assert.AreEqual(toplamElemanSayisi + 1, _cartManager.TotalItems); }
public void increase_total_number_products_already_in_the_cart() { //Arrange int totalQuantity = _cartManager.TotalQuantity; int totalITems = _cartManager.TotalItems; //act _cartManager.Add((_cartItem)); //Assert Assert.AreEqual(totalQuantity + 1, _cartManager.TotalQuantity); Assert.AreEqual(totalITems, _cartManager.TotalItems, "{0} {1}", totalITems, _cartManager.TotalItems); }
public void CarManager_Method_TakeCartFromSession_Works_Correctly() { List <CartItem> mySession = new List <CartItem>(); Mock <ISessionManager> mockSession = new Mock <ISessionManager>(); Mock <ISongRepository> mockRepository = new Mock <ISongRepository>(); mockSession.Setup(x => x.Set <List <CartItem> >(It.IsAny <string>(), It.IsAny <List <CartItem> >())).Callback((string e, List <CartItem> s) => mySession = s); mockSession.Setup(x => x.Get <List <CartItem> >(It.IsAny <string>())).Returns(mySession); mockRepository.Setup(x => x.Songs).Returns(new Song[] { new Song() { SongId = 1, NameSong = "Test1" }, new Song() { SongId = 2, NameSong = "Test2" }, new Song() { SongId = 3, NameSong = "Test3" }, new Song() { SongId = 4, NameSong = "Test4" } }); CartManager manager = new CartManager(mockSession.Object, mockRepository.Object); manager.Add(1); manager.Add(1); manager.Add(3); var result = manager.TakeCartFromSession(); mockRepository.Verify(x => x.Songs); Assert.AreEqual(2, result.Count); Assert.IsInstanceOfType(result, typeof(List <CartItem>)); }
public void sepetten_urun_cikartilabilmelidir() { _cartManager.Add(_cartItem); var sepetteOlanUrunSayisi = _cartManager.TotalItems; _cartManager.Remove(1); var sepetteKalanGerekenUrunSayisi = _cartManager.TotalItems; // burada karşılaştırma yapıyoruz. Assert.AreEqual(sepetteOlanUrunSayisi - 1, sepetteKalanGerekenUrunSayisi); }
static void Main(string[] args) { BaseCustomerManager customerManager = new CustomerManager(new CustomerCheckManager()); Customer customer = new Customer { Id = 1, FirstName = "Ahmet", LastName = "Gundogan", DateofBirth = new DateTime(2000, 1, 1), NationalityId = "33333" }; customerManager.Save(customer); Product game1 = new Product(); game1.Id = 1; game1.GameName = "First Game"; game1.Price = 10; Product game2 = new Product(); game2.Id = 2; game2.GameName = "Second Game"; game2.Price = 20; CartManager cartManager = new CartManager(customer); cartManager.Add(game1); cartManager.Add(game2); ICampaign campaign = new EndOfYearCampaign(); // EndOfYearCampaign(); //HolidayCampain(); //EndOfSeriesDiscount(); cartManager.Buy(campaign); }
public static void ClassInitialize(TestContext context) { _cartManager = new CartManager(); _cartItem = new CartItem { Product = new Product { ProductId = 1, ProductName = "Laptop", UnitPrice = 2500 }, Quantity = 1 }; _cartManager.Add(_cartItem); }
public void AddProductToCart() { //Arange var totalItems = _cartManager.TotalItem; var totalQuantity = _cartManager.TotalQuantity; //Act _cartManager.Add(new CartItem { Product = new Product { ProductId = 2, ProductName = "Mouse", UnitPrice = 2500 }, Quantity = 1 }); //Assert Assert.AreEqual(totalItems + 1, _cartManager.TotalItem); Assert.AreEqual(totalQuantity + 1, _cartManager.TotalQuantity); }
public void When_different_item_add_to_basket_then_total_item_increment_one() { //Arrange int totalItem = _cartManager.TotalItems; int totalQuantity = _cartManager.TotalQuantity; //Act _cartManager.Add(new CartItem { Product = new Product { ProductId = 2, ProductName = "Mouse", UnitPrice = 10 }, Quantity = 1 }); //Assert Assert.AreEqual(totalQuantity + 1, _cartManager.TotalQuantity); Assert.AreEqual(totalItem + 1, _cartManager.TotalItems); }
public void CartManger_Calculate_Total_Value_And_Quantity_Works_Correctly() { List <CartItem> mySession = new List <CartItem>(); Mock <ISessionManager> mockSession = new Mock <ISessionManager>(); Mock <ISongRepository> mockRepository = new Mock <ISongRepository>(); mockSession.Setup(x => x.Set <List <CartItem> >(It.IsAny <string>(), It.IsAny <List <CartItem> >())).Callback((string e, List <CartItem> s) => mySession = s); mockSession.Setup(x => x.Get <List <CartItem> >(It.IsAny <string>())).Returns(mySession); mockRepository.Setup(x => x.Songs).Returns(new Song[] { new Song() { SongId = 1, NameSong = "Test1", Price = 20 }, new Song() { SongId = 2, NameSong = "Test2", Price = 30 }, new Song() { SongId = 3, NameSong = "Test3", Price = 40 }, new Song() { SongId = 4, NameSong = "Test4", Price = 50 } }); CartManager target = new CartManager(mockSession.Object, mockRepository.Object); target.Add(1); target.Add(2); target.Add(1); target.Add(3); Assert.AreEqual(110, target.CalculateTotalValue()); Assert.AreEqual(4, target.CalculateTotalQuantity()); }
public void TestInitialize() { _cartManager = new CartManager(); _cartItem = new CartItem { Product = new Product { ProductId = 1, ProductName = "Laptop", UnitPrice = 2500 }, Quantity = 1 }; _cartManager.Add(_cartItem); }
public void sepette_farkli_urunden_iki_tane_ekleme() { //Arrange int toplamElemanSayisi = _cartManager.TotalItems; int toplamAdet = _cartManager.TotalQuantity; //2. kez ürünleri ekledik _cartManager.Add(new CartItem { Product = new Product { ProductId = 2, ProductName = "Laptop", UnitPrice = 100 }, Quantity = 1 }); //Act //Assert Assert.AreEqual(toplamAdet + 1, _cartManager.TotalQuantity); Assert.AreEqual(toplamElemanSayisi + 1, _cartManager.TotalItems); }
public void ProcessRequest(HttpContext context) { //商品加入购物车 //验证是否有该商品 用户是否登陆 是否第一次加入购物车 UserManager userManager = new UserManager(); if (userManager.ValidateUserLogin()) { int bookId = Convert.ToInt32(context.Request["bookId"]); //判断数据库中是否有该商品 BookManager bookManager = new BookManager(); Book bookModel = bookManager.GetModel(bookId); if (bookModel != null) { //包括添加和更新的功能 两步 session中登陆的key值一定是一致的 //专注电商行业。。后台系统的开发。这个做好来。 //如何确保数据库数据的完整性。。约束 知道概念还要实践 组合主键 //实际需求是怎么样子的 数据库设计的 就需要他是这样的。 int userId = ((User)context.Session["userInfo"]).Id; CartManager cartManager = new CartManager(); Cart cart = cartManager.GetModel(userId, bookModel.Id); if (cart == null) { Cart cartAdd = new Cart(); cartAdd.Count = 1; cartAdd.Book = bookModel; cartAdd.User = (User)context.Session["userInfo"]; cartManager.Add(cartAdd); } else { cart.Count += 1; cartManager.Update(cart); } context.Response.Write("ok:加入购物车成功"); } else { context.Response.Write("no:改商品已经下架!"); } } else { context.Response.Write("login:没有登录"); } }
public void testInitialize() { //test methodlarından önce yaptığımız aynı işleri buraya attık. _cartManager = new CartManager(); _cartItem = new CartItem { Product = new Product { ProductId = 1, ProductName = "Laptop", UnitPrice = 100 }, Quantity = 1 }; _cartManager.Add(_cartItem); }
public void TestInitialize() { _cartManager = new CartManager(); _cartItem = new CartItem { Product = new Product { ProductId = 1, ProductName = "Table", ProductPrice = 120 }, Quantity = 1 }; _cartManager.Add(_cartItem); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); UserManager userManager = new UserManager(); if (userManager.validateUserLogin()) { int bookId = Convert.ToInt32((context.Request["bookId"])); BookManager bookManager = new BookManager(); Model.Book bookModel = bookManager.GetModel(bookId); if (bookModel != null) { int userId = ((Model.User)context.Session["userInfo"]).Id; CartManager cartManager = new CartManager(); //Model.Book bookModel = bookManager.GetModel(bookId); Model.Cart cartModel = cartManager.GetModel(userId, bookId); if (cartModel != null) { cartModel.Count = cartModel.Count + 1; cartManager.Update(cartModel); } else { Cart modelCart = new Cart(); modelCart.Count = 1; modelCart.Book = bookModel; modelCart.User = (User)context.Session["userInfo"]; cartManager.Add(modelCart); } context.Response.Write("Success"); } else { context.Response.Write("No Such Stuff"); } context.Response.Write("Success"); } else { context.Response.Write("Please Login"); } }
protected void addButton_Click(object sender, EventArgs e) { Cart cart = new Cart(); if (companyDropDownList.SelectedIndex > 0) { cart.CompanyID = Convert.ToInt32(companyDropDownList.SelectedValue); cart.CompanyName = companyDropDownList.SelectedItem.ToString(); if (itemDropDownList.SelectedItem.ToString() == "Select Item") { outputLabel.Text = "Please select item"; } else if (itemDropDownList.SelectedIndex > 0) { cart.ItemID = Convert.ToInt32(itemDropDownList.SelectedValue); cart.ItemName = itemDropDownList.SelectedItem.ToString(); if (cartManager.chkQuantityValidity(stockOutTextBox.Text)) { cart.Quantity = Convert.ToInt32(stockOutTextBox.Text); int availableQuantity = Convert.ToInt32(availableQuantityTextBox.Text); outputLabel.Text = cartManager.Add(cart, availableQuantity); } else { outputLabel.Text = "Invalid quantity"; } } else if (itemDropDownList.SelectedItem.ToString() == "No Item") { outputLabel.Text = "No Item"; } } else { outputLabel.Text = "Please select company"; } stockOutGridViewList.DataSource = cartManager.GetAllCarts(); stockOutGridViewList.DataBind(); }
public static void SelectedService(int serviceId) { ProductManager productManager = new ProductManager(); if (serviceId == 1) { Console.Write("Enter product id: "); int productId = ConsoleInputValidator.ServiceInputValidator(serviceId); int quantity = ConsoleInputValidator.QuantityInputValidator(serviceId); if (_cartManager.Retrieve(productId) != null) { _cartManager.Update(_cartManager.Retrieve(productId), serviceId, quantity); } else { _cartManager.Add(productManager.Retrieve(productId), quantity); } DisplayHandler.DisplayService(); } else if (serviceId == 2) { Console.Write("Choose which ID to decrease/remove: "); int productId = ConsoleInputValidator.ServiceInputValidator(serviceId); int quantity = ConsoleInputValidator.QuantityInputValidator(serviceId); _cartManager.Update(_cartManager.Retrieve(productId), serviceId, quantity); DisplayHandler.DisplayService(); } else if (serviceId == 3) { Console.Write("Please enter cash on hand: "); ConsoleInputValidator.ServiceInputValidator(serviceId); DoTransactionAgain(); } }
public void AddProductToCart() { //Arrange const int excepted = 1; var cartManager = new CartManager(); var cartItem = new CartItem { Product = new Product { ProductId = 1, ProductName = "Laptop", UnitPrice = 2500 }, Quantity = 1 }; //Act cartManager.Add(cartItem); var totalItems = cartManager.TotalItem; Assert.AreEqual(excepted, totalItems); }
public void ClearCart() { //Arrange var cartManager = new CartManager(); var cartItem = new CartItem { Product = new Product { ProductId = 1, ProductName = "Laptop", UnitPrice = 2500 }, Quantity = 1 }; cartManager.Add(cartItem); //Act cartManager.Clear(); Assert.AreEqual(0, cartManager.TotalQuantity); Assert.AreEqual(0, cartManager.TotalItem); }
protected void AddButton_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(CartProduct.ProductLink)) { Response.Redirect(CartProduct.ProductLink); return; } if (!Page.IsValid) { return; } DeleteSavedCart(); if (!AddToGiftRegistry()) { return; } CartManager manager = new CartManager(this.Cart); manager.Add(new CartItem() { CatalogNumber = CartProduct.CatalogNumber, PricePerUnit = CartProduct.SalePrice == 0 ? CartProduct.Price : CartProduct.SalePrice, ProductID = CartProduct.ProductID, GiftRegistryProductID = WebUtility.GetDecodedIntFromQueryString("GiftRegistryProductID"), ProductName = CartProduct.ProductName, IsDownloadable = CartProduct.IsDownloadable, DownloadURL = CartProduct.DownloadURL, IsDownloadKeyRequired = CartProduct.IsDownloadKeyRequired, IsDownloadKeyUnique = CartProduct.IsDownloadKeyUnique, Quantity = Convert.ToInt32(QtyTextBox.Text), ProductOptions = ProductOptionsControl1.SelectedOptions, CustomFields = CustomFieldsControl1.CustomFields }); this.Cart = manager.ShoppingCart; Response.Redirect("ShoppingCart.aspx"); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int bookId = Convert.ToInt32(context.Request.Form["bookId"]); BookManager bookManager = new BookManager(); Book bookModel = bookManager.GetModel(bookId); if (bookModel != null) { User userModel = (User)context.Session["userLogin"]; if (userModel != null) { CartManager cartManager = new CartManager(); Cart cartModel = cartManager.GetModel(userModel.Id, bookId); if (cartModel != null) { cartModel.Count += 1; cartManager.Update(cartModel); } else { Model.Cart modelCart = new Model.Cart(); modelCart.Count = 1; modelCart.Book = bookModel; modelCart.User = userModel; cartManager.Add(modelCart); } context.Response.Write("ok:加入购物车成功"); } } else { context.Response.Write("no:此商品已下架"); } }
protected void AddButton_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(CartProduct.ProductLink)) { Response.Redirect(CartProduct.ProductLink); return; } if (!Page.IsValid) return; DeleteSavedCart(); if (!AddToGiftRegistry()) return; CartManager manager = new CartManager(this.Cart); manager.Add(new CartItem() { CatalogNumber = CartProduct.CatalogNumber, PricePerUnit = CartProduct.SalePrice == 0 ? CartProduct.Price : CartProduct.SalePrice, ProductID = CartProduct.ProductID, GiftRegistryProductID = WebUtility.GetDecodedIntFromQueryString("GiftRegistryProductID"), ProductName = CartProduct.ProductName, IsDownloadable = CartProduct.IsDownloadable, DownloadURL = CartProduct.DownloadURL, IsDownloadKeyRequired = CartProduct.IsDownloadKeyRequired, IsDownloadKeyUnique = CartProduct.IsDownloadKeyUnique, Quantity = Convert.ToInt32(QtyTextBox.Text), ProductOptions = ProductOptionsControl1.SelectedOptions, CustomFields = CustomFieldsControl1.CustomFields }); this.Cart = manager.ShoppingCart; Response.Redirect("ShoppingCart.aspx"); }
private int AddProduct(int productId, int quantity = 1) { CartManager cartManager = new CartManager(contextdb); ProductManager productManager = new ProductManager(contextdb); UserManager <ApplicationUser> userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(contextdb)); ApplicationUser currentUser = userManager.FindByIdAsync(User.Identity.GetUserId()).Result; IQueryable <CORE.Cart> carritoPrevio; if (Context.User.Identity.IsAuthenticated) { //IQueryable<CORE.Cart> carritoPrevio = cartManager.GetCarritoByUsuarioId(Context.User.Identity.GetUserId()); carritoPrevio = cartManager.GetCarritoByUsuarioId(currentUser.Id); } else { carritoPrevio = cartManager.GetCarritoBySesionId(sessionId); } List <CORE.Cart> cart = carritoPrevio.ToList(); CORE.Cart producto = new CORE.Cart(); if (carritoPrevio.Count() == 0) { producto.Client = new ApplicationUser(); producto.Client = currentUser; producto.SessionId = sessionId; producto.Product = productManager.GetById(productId); producto.Product_Id = productId; producto.NetPrice = decimal.Parse(productManager.GetById(productId).Price.ToString()); producto.Quantity = quantity; producto.Date = DateTime.Now; cartManager.Add(producto); } else { foreach (CORE.Cart item in cart) { if (item.Product_Id.Equals(productId)) { item.Client = new ApplicationUser(); item.Client = currentUser; item.SessionId = sessionId; item.Product = productManager.GetById(productId); item.Product_Id = productId; item.NetPrice = decimal.Parse(productManager.GetById(productId).Price.ToString()); item.Quantity = item.Quantity + quantity; item.Date = DateTime.Now; cartManager.Context.SaveChanges(); if (Context.User.Identity.IsAuthenticated) { return(cartManager.GetCarritoByUsuarioId(currentUser.Id).Count()); } else { return(cartManager.GetCarritoBySesionId(sessionId).Count()); } } } producto.Client = new ApplicationUser(); producto.Client = currentUser; producto.SessionId = sessionId; producto.Product = productManager.GetById(productId); producto.Product_Id = productId; producto.NetPrice = decimal.Parse(productManager.GetById(productId).Price.ToString()); producto.Quantity = quantity; producto.Date = DateTime.Now; cartManager.Add(producto); } cartManager.Context.SaveChanges(); //carritoPrevio = cart; if (Context.User.Identity.IsAuthenticated) { return(cartManager.GetCarritoByUsuarioId(currentUser.Id).Count()); } else { return(cartManager.GetCarritoBySesionId(sessionId).Count()); } }
public void ApplyPromotion_FixedPrice_Test1() { _cartManager.Add(new Product("A", "Product A", 50.0M), 5); _cartManager.Add(new Product("B", "Product B", 30.0M), 5); _cartManager.Add(new Product("C", "Product C", 20.0M), 1); _cartManager.Add(new Product("D", "Product D", 15.0M), 1); var promotionSelector = new Func <ICollection <Promotion>, Promotion>(promotions => { //Selecting first available promotion which is 3 A's for 130 return(promotions.FirstOrDefault()); }); Assert.AreEqual(_cartManager.ApplyPromotion(promotionSelector), 130 + 100 + 150 + 35); }