public void DeleteShoppingCart_ShoppingCartItem_For_An_User() { var shoppingCartRepository = new MockShoppingCartRepository(); shoppingCartRepository.DeleteDelegate = (userId) => { Assert.AreEqual("JohnDoe", userId); return(true); }; var target = new ShoppingCartController(shoppingCartRepository, new MockProductRepository()); target.DeleteShoppingCart("JohnDoe"); }
public void DeleteShoppingCart_Throws_ForUnknownUser() { var shoppingCartRepository = new MockShoppingCartRepository(); shoppingCartRepository.DeleteDelegate = s => false; HttpResponseException caughtException = null; var target = new ShoppingCartController(shoppingCartRepository, new MockProductRepository()); try { target.DeleteShoppingCart("UnknownUser"); } catch (HttpResponseException ex) { caughtException = ex; } Assert.AreEqual(System.Net.HttpStatusCode.NotFound, caughtException.Response.StatusCode); }
protected void PlaceOrder_Click(object sender, EventArgs e) { List <SaleDetailsList> listsaledetails = new List <SaleDetailsList>(); List <ListSale> listsales = new List <ListSale>(); string username = User.Identity.Name; int employeeid; if (SaleList.Items.Count == 0) { MessageUserControl.ShowInfo("Warning", "Please add at least one product in order to place order."); } else { if (PaymentTypeDDL.SelectedIndex == 0) { MessageUserControl.ShowInfo("Warning", "Please select a payment method to place order."); } else { MessageUserControl.TryRun(() => { ApplicationUserManager secmgr = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext())); EmployeeInfo info = secmgr.User_GetEmployee(username); employeeid = info.EmployeeID; foreach (ListViewItem item in SaleList.Items) { Label quantityLabel = item.FindControl("QuantityLabel") as Label; Label priceLabel = item.FindControl("PriceLabel") as Label; HiddenField itemIDLabel = item.FindControl("StockItemIDLabel") as HiddenField; Label descriptionLabel = item.FindControl("DescriptionLabel") as Label; SaleDetailsList newSaleDetailsList = new SaleDetailsList(); newSaleDetailsList.Description = descriptionLabel.Text; newSaleDetailsList.Price = decimal.Parse(priceLabel.Text.Replace(@"$", string.Empty)); newSaleDetailsList.Quantity = int.Parse(quantityLabel.Text); newSaleDetailsList.StockItemID = int.Parse(itemIDLabel.Value); listsaledetails.Add(newSaleDetailsList); } Label SubtotalLabel = (Label)UpdatePanel3.FindControl("totalLabel2") as Label; Label taxLabel = (Label)UpdatePanel3.FindControl("TaxLabel") as Label; CouponController cpmgr = new CouponController(); Coupon coupon = cpmgr.Coupons_Get(CouponTextBox.Text); ListSale newSaleList = new ListSale(); newSaleList.PaymentType = PaymentTypeDDL.SelectedItem.ToString(); newSaleList.CouponID = coupon == null ? null : coupon.CouponID; newSaleList.SubTotal = decimal.Parse(SubtotalLabel.Text.Replace(@"$", string.Empty)); newSaleList.TaxAmount = decimal.Parse(taxLabel.Text.Replace(@"$", string.Empty)); listsales.Add(newSaleList); SaleDetailController sysmgr = new SaleDetailController(); sysmgr.Add_AddToSale(employeeid, listsales, listsaledetails); foreach (ListViewItem item in SaleList.Items) { HiddenField itemidLabel = item.FindControl("ItemIDLabel") as HiddenField; int itemid = int.Parse(itemidLabel.Value); ShoppingCartItemController spcitemmgr = new ShoppingCartItemController(); spcitemmgr.DeleteShoppingItems(employeeid, itemid); } ShoppingCartController spcmgr = new ShoppingCartController(); spcmgr.DeleteShoppingCart(employeeid); //refresh the table ShoppingCartItemController systemmgr = new ShoppingCartItemController(); List <UserShoppingCartItem> infos = systemmgr.List_ItemsForShoppingCart(employeeid); ShoppingCartList.DataSource = infos; ShoppingCartList.DataBind(); subtotalLabel.Text = "$" + "0"; TaxLabel.Text = "$" + "0"; CouponTextBox.Text = ""; DiscountLabel.Text = "$" + "0"; totalLabel2.Text = "$" + "0"; PaymentTypeDDL.SelectedIndex = 0; }, "Success", "Order has been placed"); } } }