public void Setup() { _promotionStrategy = new AdditionalItemOffer(); _productWithOffer = new ProductCheckout() { ProductCode = "A", Quantity = 3, DefaultPrice = 50 }; _productWithOfferExtra = new ProductCheckout() { ProductCode = "A", Quantity = 4, DefaultPrice = 50 }; _productWithoutOffer = new ProductCheckout() { ProductCode = "A", Quantity = 2, DefaultPrice = 50 }; _promotions = new List <Promotion>() { new Promotion() { Type = "Single", ProductCode = "A", Price = 130, Quantity = 3 }, new Promotion() { Type = "Single", ProductCode = "B", Price = 45, Quantity = 2 }, new Promotion() { Type = "Combo", ProductCode = "C;D", Price = 30, Quantity = 3 } }; }
/// <summary> /// /// </summary> /// <param name="productCheckout"></param> /// <param name="promotions"></param> /// <returns></returns> public bool CanExecute(ProductCheckout productCheckout, List <Promotion> promotions) { recentProductCheckout = productCheckout; appliedPromotion = promotions.Where(x => x.ProductCode.Split(';').Contains(productCheckout.ProductCode)).FirstOrDefault(); if (appliedPromotion != null && !productCheckout.IsValidated && appliedPromotion.Type == PromotionTypeConstants.Combo) { return(true); } return(false); }
/// <summary> /// /// </summary> /// <param name="product"></param> /// <param name="promotions"></param> /// <returns></returns> public bool CanExecute(ProductCheckout product, List <Promotion> promotions) { ProductCheckout = product; appliedPromotion = promotions.Where(x => x.ProductCode == product.ProductCode).FirstOrDefault(); if (appliedPromotion != null && appliedPromotion.Type == PromotionTypeConstants.Single) { product.IsValidated = true; return(true); } return(false); }
void AddProductToCheckoutGrid(Backend.Objects.SaleItem item) { //Fill Grid [ CheckoutGrid ] With Rows ProductCheckout productModel = new ProductCheckout { Item = item, Sale = Sale, OnRemove = OnRemoveCheckoutProduct, OnToggle = OnToggleCheckoutItem, OnUpdate = OnUpdateCheckoutItem, }; //Add To Grid CheckoutGrid.Controls.Add(productModel); }
public void GetTotalPricewithoutSpecialOffers() { var pc = new ProductCheckout() { Id = 3, Quantity = 4, Price = 1.80 }; IList <ProductCheckout> lpc = new List <ProductCheckout> { pc }; ProductCheckout.CalculateTotalPrice(lpc); //7.2 is correct answer can change thsi to any other number to see test fail Assert.AreEqual("7.2", ProductCheckout.CalculateTotalPrice(lpc).ToString()); }
public void GetTotalPricewithSpecialOffers() { var pc = new ProductCheckout() { Id = 1, Quantity = 8, SpecialOffers = "3 for 1.30", Price = 0.5 }; IList <ProductCheckout> lpc = new List <ProductCheckout> { pc }; ProductCheckout.CalculateTotalPrice(lpc); //3.6 is correct answer can change thsi to any other number to see test fail Assert.AreEqual("3.6", ProductCheckout.CalculateTotalPrice(lpc).ToString()); }
// POST: api/ProductCheckout public double Post([FromBody] string value) { IList <ProductCheckout> pc = JsonConvert.DeserializeObject <IList <ProductCheckout> >(value); return(ProductCheckout.CalculateTotalPrice(pc)); }
public AdditionalItemOffer() { appliedPromotion = new Promotion(); ProductCheckout = new ProductCheckout(); }
static void Main() { string baseAddress = "http://localhost:9001/"; // Start OWIN host using (WebApp.Start <Startup>(url: baseAddress)) { string selected; int index; // Create HttpCient and make a request to api/ProductCheckOut HttpClient client = new HttpClient(); var response = client.GetAsync(baseAddress + "api/ProductCheckOut").Result; var outputresult = response.Content.ReadAsStringAsync().Result; IList <Products> items = JsonConvert.DeserializeObject <IList <Products> >(outputresult); StringBuilder sb = new StringBuilder(); IList <ProductCheckout> productsCheckout = new List <ProductCheckout>(); //Display data in tabular form sb.AppendLine("ID\t| Code\t| Description\t| Price\t| SpecialOffers"); sb.AppendLine("---------------------------------------------------------"); foreach (Products t in items) { sb.Append(t.Id); sb.Append("\t| "); sb.Append(t.Sku); sb.Append("\t| "); sb.Append(t.Description); sb.Append("\t| "); sb.Append(t.Price); sb.Append("\t| "); sb.AppendLine(t.SpecialOffers); } Console.WriteLine(sb.ToString()); do { Console.WriteLine("Make a number selection for item you want to buy. 'S' to checkout"); selected = Console.ReadLine(); bool itemSelectionOk = Int32.TryParse(selected, out index); if (itemSelectionOk & (index > 0 & index <= items.Count)) { Console.WriteLine("Enter quantity: "); var quantityIn = Console.ReadLine(); int quantity; bool quantitySelectionOk = Int32.TryParse(quantityIn, out quantity); if (quantitySelectionOk & quantity > 0) { ProductCheckout productCheckOut = new ProductCheckout(); productCheckOut.Id = index; productCheckOut.Quantity = quantity; productCheckOut.SpecialOffers = items.Single(s => s.Id == index).SpecialOffers; productCheckOut.Price = items.Single(s => s.Id == index).Price; productsCheckout.Add(productCheckOut); } } } while (selected != "S"); // call the Api to calculate the product checkout price var responseresult = client.PostAsJsonAsync(baseAddress + "api/ProductCheckOut", JsonConvert.SerializeObject(productsCheckout)).Result; Decimal outputresult1 = Convert.ToDecimal(responseresult.Content.ReadAsStringAsync().Result); //display total price Console.WriteLine("Your total: " + outputresult1.ToString("C", CultureInfo.CurrentCulture)); Console.ReadLine(); } }