public void TestViewMyAddToCart_ShouldCallCartItemAddToCartCorrectly(int productId, int quantity) { var mockedView = new Mock <IAddToCartView>(); var mockedCart = new Mock <IShoppingCart>(); var presenter = new AddToCartPresenter(mockedView.Object, mockedCart.Object); var args = new AddToCartEventArgs(productId, quantity); mockedView.Raise(v => v.MyAddToCart += null, args); mockedCart.Verify(c => c.AddItem(productId, quantity), Times.Once); }
protected void Page_Load(object sender, EventArgs e) { try { id = int.Parse(this.Request.QueryString["id"]); quantity = int.Parse(this.Request.QueryString["quantity"]); } catch (Exception) { this.ErrorMessages.Text = "Please provide valid arguments"; return; } var args = new AddToCartEventArgs(this.id, this.quantity); this.MyAddToCart?.Invoke(this, args); this.Response.Redirect("Summary"); }
/// <summary> /// Raises the onaddtocart event. /// </summary> /// <param name="args">The <see cref="Rendition.AddToCartEventArgs"/> instance containing the event data.</param> internal void raiseOnAddToCart( AddToCartEventArgs args ) { if( AddedToCart != null ) { AddedToCart( this, args ); }; }
/// <summary> /// Adds an item to the selected sessions cart with transactions /// </summary> /// <param name="args">{itemnumber:string,qty:int,sessionid:Guid,other misc item form inputs}</param> /// <param name="cn">The connection being used.</param> /// <param name="trans">The transaction being used.</param> /// <returns> /// {itemNumber:string,price:float,qty:int,cartId:Guid,addressId:Guid /// sessionId:Guid,packingSlipImage:string,auxillaryImage:string,cartImage:string,detailImage:string, /// fullSizeImage:string,listingImage:string,listing2Image:string,description:string, /// form:string,error_id:int,error_desc:string,inputs:Dictionary}. /// </returns> public static Dictionary<string, object> AddToCart(Dictionary<string, object> args, SqlConnection cn, SqlTransaction trans) { ("FUNCTION:Add to Cart > Result object to JSON").Debug(10); Dictionary<string, object> j = new Dictionary<string, object>(); Session session = null; if(args.ContainsKey("sessionId")) { if(cn == null) { session = new Session(Main.Site, new Guid((string)args["sessionId"])); } else { session = new Session(Main.Site, new Guid((string)args["sessionId"]), cn, trans); } } else { session = Main.GetCurrentSession(); } Commerce.Item item = Main.Site.Items.List.Find(delegate(Commerce.Item itm) { return itm.ItemNumber.ToLower() == ((string)args["itemNumber"]).ToLower(); }); if(item == null) { j.Add("error", -1); string passedItem = ((string)args["itemNumber"]).MaxLength(50, true); j.Add("description", "Item number " + passedItem + " (itemNumber argument length:" + passedItem.Length.ToString() + ") does not exist."); return j; } if(!args.ContainsKey("itemNumber")) { j.Add("error", -2); j.Add("description", "the key itemNumber is missing from the collection."); return j; } int qty = 1; if(args.ContainsKey("qty")) { if(!int.TryParse(args["qty"].ToString(), out qty)) { qty = 1; } } /* figure out the price that should be set. The user can override the price if: * They are an administrator (session.administrator) * An administrator is entering the order (instatitationSession.administrator) * The order is entered via EDI transmission (HttpContext.Current==null) */ decimal price = (decimal)0.00; bool allowPreorder = false; bool allowPriceOverride = false; bool allowPreorderOverride = false; bool overridePrice = false; if(session.Wholesale == 1) { price = item.WholeSalePrice; } else if(item.IsOnSale) { price = item.SalePrice; } /* check if the user is an administrator or */ if(session.Administrator || HttpContext.Current == null) { allowPriceOverride = true; } /* check if this item is being added by someone else */ if(HttpContext.Current != null) { Session instatitationSession = Main.GetCurrentSession(); if(instatitationSession != null) { /* are they an administrator (What else would they be? But what the hell.) */ if(instatitationSession.Administrator) { allowPriceOverride = true; } } } if(allowPriceOverride) { if(args.ContainsKey("price")) { /* if the key is present, try and convert it into a decimal, * if that doesn't work enter price 0 to throw an exception */ if(!decimal.TryParse(args["price"].ToString(), out price)) { price = 0; } else { /* only override the price if a valid price was provided */ overridePrice = true; } } } if(allowPreorderOverride) { if(args.ContainsKey("allowPreorder")) { /* check if somthing silly was put in the key, if not allow the user to change allowPreorder */ if(!bool.TryParse(args["allowPreorder"].ToString(), out allowPreorder)) { allowPreorder = false; } } } BeforeAddToCartEventArgs e = new BeforeAddToCartEventArgs(item, session, cn, trans, HttpContext.Current); Main.Site.raiseOnBeforeAddtoCart(e); Commerce.CartItem i = addToCartProc( (string)args["itemNumber"], qty, session, args, price, allowPreorder, overridePrice, cn, trans ); string form = ""; if(i.Item.Form == null) { form = ""; } else { form = i.Item.Form.Html; }; /* spit a json object out to the console that initiated the request */ j.Add("itemNumber", i.Item.Number); j.Add("price", (double)i.Price); j.Add("qty", i.Qty); j.Add("cartId", i.CartId.ToString()); j.Add("addressId", i.AddressId.ToString()); j.Add("sessionId", session.Id.ToString()); j.Add("packingSlipImage", i.Item.PackingSlipImage); j.Add("auxillaryImage", i.Item.AuxillaryImage); j.Add("cartImage", i.Item.CartImage); j.Add("detailImage", i.Item.FullSizeImage); j.Add("fullSizeImage", i.Item.FullSizeImage); j.Add("listingImage", i.Item.ListingImage); j.Add("listing2Image", i.Item.Listing2Image); j.Add("item_description", i.Item.Description); j.Add("formName", i.Item.FormName); j.Add("error_id", i.Error_Id); j.Add("error_desc", i.Error_Description); j.Add("error", i.Error_Id); j.Add("description", i.Error_Description); if(i.Item.Form != null) { Dictionary<string, object> k = new Dictionary<string, object>(); for(var x = 0; i.Inputs.Count > x; x++) { if(!k.ContainsKey(i.Inputs[x].Name)) { k.Add(i.Inputs[x].Name, i.Inputs[x].Value); } } j.Add("inputs", k); j.Add("formHTML", form); } else { j.Add("inputs", false); } AddToCartEventArgs f = new AddToCartEventArgs(i, session.Cart, cn, trans, session, HttpContext.Current); Main.Site.raiseOnAddToCart(f); return j; }