private BasketViewModel CreateViewModelFromBasket(Basket basket) { var pricesAndQuantities = basket.Items.Select(i => new System.Tuple <decimal, int>(i.UnitPrice, i.Quantity)); var totals = OrderCalculator.CalculateTotals(pricesAndQuantities); return(new BasketViewModel { Id = basket.Id, BuyerId = basket.BuyerId, SubTotal = totals.SubTotal, Tax = totals.Tax, Total = totals.Total, Items = basket.Items.Select(i => { var itemModel = new BasketItemViewModel { Id = i.Id, UnitPrice = i.UnitPrice, Quantity = i.Quantity, CatalogItemId = i.CatalogItemId }; var item = _itemRepository.GetById(i.CatalogItemId); itemModel.PictureUrl = _uriComposer.ComposePicUri(item.PictureUri); itemModel.ProductName = item.Name; return itemModel; }) .ToList() }); }
private void PopulateShoppingCartControls() { if (StoreContext.ShoppingCart.GetCartItems().Length > 0) { uxShoppingCartPanel.Visible = true; uxTotalAmountLabel.Text = uxCurrencyControl.CurrentCurrency.FormatPrice(GetShoppingCartTotal()); OrderCalculator orderCalculator = new OrderCalculator(); decimal discount = orderCalculator.GetPreCheckoutDiscount( StoreContext.Customer, StoreContext.ShoppingCart.SeparateCartItemGroups(), StoreContext.CheckoutDetails.Coupon); if (discount > 0) { uxDiscountTR.Visible = true; uxDiscountAmountLabel.Text = uxCurrencyControl.CurrentCurrency.FormatPrice(discount * -1); } else { uxDiscountTR.Visible = false; } uxCartItemGrid.DataSource = StoreContext.ShoppingCart.GetCartItems(); uxCartItemGrid.DataBind(); } else { uxShoppingCartPanel.Visible = false; StoreContext.CheckoutDetails.Clear(); } }
public void OrderCalculatorTest() { // Arrange AddArticlesTest(); Customer customer = new Customer(); Article product1 = articlesService.Get(1); Order order = new Order("ZAM 1/2018", customer); order.OrderDate = DateTime.Parse("2018-04-13"); order.AddArticle(product1, 2); IStrategy strategy = new HappyDayOfWeekStrategy(DayOfWeek.Friday, 0.3m); OrderCalculator calculator = new OrderCalculator(strategy); // Acts calculator.Calculate(order); // Assets Assert.AreEqual(6, order.DiscountAmount); Assert.IsTrue(order.HasDiscount); }
public void CalculateDiscountTest() { // Arrange Customer customer = new Customer(1, "Sulecki"); Order order = Order.Create(customer); order.OrderDate = DateTime.Parse("2018-09-14"); Product product = new Product("Mouse", 100, "Red"); Service service = new Service("Developing", 100); order.AddDetail(new OrderDetail(product, 10)); order.AddDetail(new OrderDetail(service, 4)); IOrderCalculator calculator = new OrderCalculator(); // Acts decimal result = calculator.Calculate(order); // Asserts Assert.True(result > 0); Assert.Equal(1260, result); // Polecam: Install-Package FluentAssertions }
public bool CalculateOrderWithoutRepricing(Order o) { var calc = new OrderCalculator(this); calc.SkipRepricing = true; return(calc.Calculate(o)); }
public void Calculate2DiscountTest() { // Arrange ICanDiscountStrategy canDiscountStrategy = new HappyHoursCanDiscountStrategy( TimeSpan.Parse("12:30"), TimeSpan.Parse("14:00")); IDiscountStrategy discountStrategy = new FixedDiscountStrategy(5); OrderCalculator orderCalculator = new OrderCalculator(canDiscountStrategy, discountStrategy); Order order = new Order("ZAM 001/2018", new Customer("M", "S")); order.CreateDate = DateTime.Parse("2018-06-19 12:30"); Product product1 = new Product("Monitor", 1000); order.Details.Add(new OrderDetail(product1, 10)); // Acts decimal discount = orderCalculator.CalculateDiscount(order); // Asserts Assert.AreEqual(5, discount); }
public static void Main() { Console.WriteLine(""); Console.WriteLine("Hello there! Welcome to Joe's bakery. We have the following specials: "); Console.WriteLine(""); Console.WriteLine("1. Bread is 5 Dollars per Loaf. Buy 2 get 1 free!"); Console.WriteLine("2. Pastries are 2 Dollars each, or 3 for 5 Dollars!"); Console.WriteLine(""); Console.WriteLine("Enter the number of bread loafs you'd like to purchase: "); int breadLoafs = int.Parse(Console.ReadLine()); BreadOrder newBreadOrder = new BreadOrder(breadLoafs); Console.WriteLine("Enter the number of pastries you'd like to purchase: "); int pastries = int.Parse(Console.ReadLine()); PastryOrder newPastryOrder = new PastryOrder(pastries); Console.WriteLine(""); Console.WriteLine("The cost of your bread order is: "); Console.WriteLine(newBreadOrder.OrderCost() + " Dollars"); Console.WriteLine("The cost of your pastry order is: "); Console.WriteLine(newPastryOrder.OrderCost() + " Dollars"); OrderCalculator newOrderCalculator = new OrderCalculator(); Console.WriteLine(""); Console.WriteLine("The total cost of your order is: "); Console.WriteLine(newOrderCalculator.TotalCost(newBreadOrder.OrderCost(), newPastryOrder.OrderCost()) + " Dollars"); }
public void グレードがいいやつはボーナスがつく() { var order = new Order ( name: OrderName.Car, 100, new[] { new OrderElement(Type.Wheel, 4), new OrderElement(Type.CarBody, 1), } ); var checker = new OrderCalculator(new[] { order }); var parts = new[] { new Part(Type.Wheel, Quality.Normal, 0), new Part(Type.Wheel, Quality.High, 0), new Part(Type.Wheel, Quality.High, 0), new Part(Type.Wheel, Quality.Normal, 0), new Part(Type.CarBody, Quality.Normal, 0), }; // Car指定 var shipment1 = new ShippingParts(parts, OrderName.Car); var result = checker.Calculate(shipment1); // 倍率で点数が上がるはず Assert.AreEqual((int)(100 * 1.2f * 1.2f), (int)result); }
public void Initialize() { //Setup //Rules section _rules = new Dictionary <char, Tuple <int, double> >(); _comboRules = new List <Tuple <char, char, double> >(); //Adding first Rule for skuid-A _rules.Add('A', new Tuple <int, double>(3, 130)); //Adding first Rule for skuid-B _rules.Add('B', new Tuple <int, double>(2, 45)); _comboRules = new List <Tuple <char, char, double> >(); //Adding combo Rule _comboRules.Add(new Tuple <char, char, double>('C', 'D', 30)); _promotionRule = new PromotionRules(_rules, _comboRules); //Master Data section productWithPrice = new Dictionary <char, double>(); productWithPrice.Add('A', 50); productWithPrice.Add('B', 30); productWithPrice.Add('C', 20); productWithPrice.Add('D', 15); _SKUCart = new SkuCart(productWithPrice); _promotionEngine = new PromotionEngine_V1(); _orderCalculator = new OrderCalculator(_promotionEngine); }
private int GetRewardPoint() { OrderAmount orderAmount = StoreContext.GetOrderAmount(); OrderCalculator calculator = new OrderCalculator(); return(calculator.GetPointFromPrice((orderAmount.Subtotal - orderAmount.Discount), ConvertUtilities.ToDecimal(DataAccessContext.Configurations.GetValue("RewardPoints", StoreContext.CurrentStore)))); }
private void PopulateControls() { IList <PaymentOption> paymentsWithoutButton = GetPaymentsWithoutButton(); if (paymentsWithoutButton.Count == 0) { uxCheckOutButton.Visible = false; } uxAmountLabel.Text = StoreContext.Currency.FormatPrice( GetShoppingCartTotal()); uxQuantityLabel.Text = StoreContext.ShoppingCart.GetCurrentQuantity().ToString(); if (StoreContext.ShoppingCart.GetCartItems().Length > 0) { OrderCalculator orderCalculator = new OrderCalculator(); decimal discount = orderCalculator.GetPreCheckoutDiscount( StoreContext.Customer, StoreContext.ShoppingCart.SeparateCartItemGroups(), StoreContext.CheckoutDetails.Coupon); uxDiscountTR.Visible = true; uxDiscountLabel.Text = StoreContext.Currency.FormatPrice(discount * -1); } else { uxDiscountTR.Visible = false; } }
public void CalculateOrder_WithOut_Promotion() { ///Arrange List <Sku> selectedSkus = new List <Sku> { new Sku { SkuId = 'A', UnitPrice = 50, Quantity = 3 }, new Sku { SkuId = 'B', UnitPrice = 30, Quantity = 3 }, new Sku { SkuId = 'C', UnitPrice = 20, Quantity = 2 }, new Sku { SkuId = 'D', UnitPrice = 15, Quantity = 2 } }; Cart checkoutCart = new Cart { Skus = selectedSkus }; OrderCalculator orderCalculator = new OrderCalculator(); ///Act orderCalculator.CalculateTotal(checkoutCart); ///Assert Assert.IsTrue(checkoutCart.OrderTotal.ToString().Equals("310")); }
public static void Test() { Product product1 = new Product { Name = "Szkolenie", UnitPrice = 100, }; Order order = new Order { Details = new List<OrderDetail> { new OrderDetail(product1, 2), new OrderDetail(product1, 1), } }; // IValidatorStrategy validatorStrategy = new HappyHoursValidatorStrategy(TimeSpan.FromHours(9), TimeSpan.FromHours(17)); IValidatorStrategy validatorStrategy = new PeriodValidatorStrategy(new Period(DateTime.Parse("2018-06-01"), DateTime.Parse("2018-06-30"))); IDiscountStrategy discountStrategy = new PercentageDiscountStrategy(0.1m); OrderCalculator calculator = new OrderCalculator(validatorStrategy, discountStrategy); var discount = calculator.CalculateDiscount(order); var finalAmount = order.TotalAmount - discount; Console.WriteLine($"Original amount: {order.TotalAmount} discount: {discount} finalAmount: {finalAmount}"); }
private void CalculateShippingCost( ShippingOption shippingOption, out decimal shippingCost, out decimal handlingFee) { OrderCalculator orderCalculator = new OrderCalculator(); ShippingMethod shippingMethod = shippingOption.CreateNonRealTimeShippingMethod(); if (StoreContext.CheckoutDetails.Coupon.DiscountType == Vevo.Domain.Discounts.Coupon.DiscountTypeEnum.FreeShipping) { shippingCost = 0; } else { shippingCost = orderCalculator.GetShippingCost( shippingMethod, StoreContext.ShoppingCart.SeparateCartItemGroups(), StoreContext.WholesaleStatus, StoreContext.GetOrderAmount().Discount) + CartItemPromotion.GetShippingCostFromPromotion(shippingMethod, StoreContext.ShoppingCart.SeparateCartItemGroups(), StoreContext.WholesaleStatus, StoreContext.GetOrderAmount().Discount); } handlingFee = orderCalculator.GetHandlingFee( shippingMethod, StoreContext.ShoppingCart.SeparateCartItemGroups(), StoreContext.WholesaleStatus); }
// Normally would split out into a separate project public void Returns_Correct_Value_Implementation() { var sut = new OrderCalculator(); var result = sut.Calculate(new string[] { "Steak Sandwich" }); Assert.Equal((decimal)5.4, result); }
private decimal GetShoppingCartTotal() { OrderCalculator orderCalculator = new OrderCalculator(); return(orderCalculator.GetShoppingCartTotal( StoreContext.Customer, StoreContext.ShoppingCart.SeparateCartItemGroups(), StoreContext.CheckoutDetails.Coupon)); }
public void CalculateTotalSingleItem() { var item = new MaterialOrderItem(new Item(2, "Two", 2.00m), 1, new MaterialOrderItemCalc()); OrderItem[] items = { item }; var order = new Order(items); var orderCalculator = new OrderCalculator(); var total = order.GetOrderTotal(orderCalculator, 0.0825m); Assert.IsTrue(total == 2.17m); }
public ActionResult DeleteCartProduct(int Prod) { ListProductCartModel listCart = new ListProductCartModel(); listCart = (ListProductCartModel)Session["Cart"]; var st = listCart.listProduct.Find(c => c.ProductId == Prod); listCart.listProduct.Remove(st); var modelCart = OrderCalculator.CalculatorCart(listCart); Session["Cart"] = modelCart; return(RedirectToAction("Index", "Cart")); }
public void CalculateTotal() { // http://www.softschools.com/math/topics/rounding_to_the_nearest_hundredth/ var item1 = new ServiceOrderItem(new Item(1, "One", 10.00m), 1, new ServiceOrderItemCalc()); var item2 = new MaterialOrderItem(new Item(2, "Two", 10.02m), 2, new MaterialOrderItemCalc()); OrderItem[] items = { item1, item2 }; var order = new Order(items); var orderCalculator = new OrderCalculator(); var total = order.GetOrderTotal(orderCalculator, 0.0825m); Assert.IsTrue(total == 31.69m); }
protected string GetItemName(object cartItem) { ICartItem item = (ICartItem)cartItem; OrderCalculator orderCalculator = new OrderCalculator(); OrderAmountPackage orderAmountPackage = orderCalculator.CalculatePackage( StoreContext.CheckoutDetails, new CartItemGroup(item), StoreContext.Customer); return(item.GetOrderItemName( StoreContext.Culture, CurrenntCurrency, orderAmountPackage)); }
public void Test_OrderCalculation1() { Product product = new Product { Code = "12345", Name = "Monitor", Type = Type.Normal, UnitPrice = 200.00 }; Coupon coupon = new Coupon { Code = "54321", ProductCode = "12345", DeductAmount = 50.00, ExpirationDate = DateTime.Now.AddDays(14) }; Promotion promotion = new Promotion { Code = "54321", ProductCode = "456789", DeductRate = 0.10, ExpirationDate = DateTime.Now.AddDays(10) }; Order order = new Order { CustomerId = "ABCDEFG", State = "NY", productsBasket = new List <Product>(), appliedCoupons = new List <Coupon>(), appliedPromotions = new List <Promotion>() }; order.AddProduct(product); order.AddCoupon(coupon); order.AddPromotion(promotion); OrderCalculator calculator = new OrderCalculator { CustomerOrder = order }; calculator.calculateOrderPayment(); Assert.Equal(12.00, calculator.CustomerOrder.TaxCharge); Assert.Equal(150.00, calculator.CustomerOrder.TotalCost); }
public void CalculateOrder_With_Promotion_With_Quotient() { ///Arrange List <Sku> selectedSkus = new List <Sku> { new Sku { SkuId = 'A', UnitPrice = 50, Quantity = 10 }, new Sku { SkuId = 'B', UnitPrice = 30, Quantity = 4 }, new Sku { SkuId = 'C', UnitPrice = 20, Quantity = 13 }, new Sku { SkuId = 'D', UnitPrice = 15, Quantity = 1 } }; List <Promotion> activePromotions = new List <Promotion> { new Promotion { SkuId = 'A', IsMutualExclusive = false, PromotionPercentage = 13, PromotionQuantity = 3 }, new Promotion { SkuId = 'B', IsMutualExclusive = false, PromotionPercentage = 4, PromotionQuantity = 2 }, new Promotion { SkuId = 'C', IsMutualExclusive = false, PromotionPercentage = 20, PromotionQuantity = 10 }, new Promotion { SkuId = 'D', IsMutualExclusive = false, PromotionPercentage = 0, PromotionQuantity = 1 } }; Cart checkoutCart = new Cart { Skus = selectedSkus, Promotions = activePromotions }; OrderCalculator orderCalculator = new OrderCalculator(); ///Act orderCalculator.CalculateTotal(checkoutCart); ///Assert Assert.AreEqual(checkoutCart.GrandPromotionTotal.ToString(), "103.3"); Assert.AreEqual(checkoutCart.GrandTotal.ToString(), "895"); Assert.AreEqual(checkoutCart.OrderTotal.ToString(), "791.7"); }
public void Returns_Correct_Value() { Mock <IItemCalculator> netMoq = new Mock <IItemCalculator>(); netMoq.Setup(m => m.Calculate(It.IsAny <string[]>())).Returns((decimal)123.45); Mock <ISurchargeCalculator> surchargeMoq = new Mock <ISurchargeCalculator>(); surchargeMoq.Setup(m => m.Calculate(It.IsAny <decimal>(), It.IsAny <string[]>())).Returns((decimal)10); var sut = new OrderCalculator(netMoq.Object, surchargeMoq.Object); var result = sut.Calculate(new string[] { "Test", "Test" }); Assert.Equal((decimal)133.45, result); }
//this method is an AJAX target for CalculateOrder public async Task<JsonResult> CalculateOrderAsync() { Stream req = Request.InputStream; req.Seek(0, SeekOrigin.Begin); string payload = new StreamReader(req).ReadToEnd(); AjaxOrder requestOrder = JsonConvert.DeserializeObject<AjaxOrder>(payload); BusinessRules busRules = await repository.GetBusinessRulesAsync(); TaxRate[] taxRates = await repository.GetTaxRatesAsync(); AjaxOrder responseOrder = OrderCalculator.CalculateOrder(requestOrder, busRules, taxRates); JsonResult response = Json(responseOrder); response.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return response; } //CalculateOrderAsync
public ActionResult CheckGiftCode(string GiftCode) { if (GiftCode != "") { var code = _StaffService.GetStaffs().Where(p => p.Yahoo.ToLower().Equals(GiftCode.ToLower())).FirstOrDefault(); ListProductCartModel listCart = new ListProductCartModel(); listCart = (ListProductCartModel)Session["Cart"]; if (code != null) { listCart.GiftCode = GiftCode; listCart.GiftCodePercent = int.Parse(code.Phone); var modelCart = OrderCalculator.CalculatorCart(listCart); Session["Cart"] = modelCart; } } return(RedirectToAction("Index", "Cart")); }
public void TotalCost_AddCostOfPastryOrderToCostOfBreadOrderToCalculateTotalCostOfOrder_int() { int intendedTotalOrderCost = 15; int numberOfPastries = 3; PastryOrder newPastryOrder = new PastryOrder(numberOfPastries); int pastryOrderCost = newPastryOrder.OrderCost(); int numberOfLoafs = 2; BreadOrder newBreadOrder = new BreadOrder(numberOfLoafs); int breadOrderCost = newBreadOrder.OrderCost(); OrderCalculator newOrderCalculator = new OrderCalculator(); int totalOrderCost = newOrderCalculator.TotalCost(breadOrderCost, pastryOrderCost); Assert.AreEqual(intendedTotalOrderCost, totalOrderCost); }
public OrderForm(OrderFormValuesValidator orderFormValuesValidator, OrderConfigurationFormValuesValidator orderConfigurationFormValuesValidator, OrderCalculator orderCalculator, OrderConverter orderConverter) { InitializeComponent(); orderFormValues = new OrderFormValues { VehicleType = VehicleType.NONE }; orderConfigurationFormValues = new OrderConfigurationFormValues(); orderFormErrors = new OrderFormErrors(); orderConfigurationFormErrors = new OrderConfigurationFormErrors(); this.OrderFormValuesValidator = orderFormValuesValidator; this.OrderConfigurationFormValuesValidator = orderConfigurationFormValuesValidator; this.OrderCalculator = orderCalculator; this.OrderConverter = orderConverter; }
public void CalculateOrderTest() { // Arrange var order = new Order { Price = 40, Quantity = 2, OrderDate = DateTime.Parse("2018-03-06") }; // Act var orderCalculator = new OrderCalculator(new NoDiscountStrategy()); var amount = orderCalculator.Calculate(order); // Assert Assert.AreEqual(80, amount); }
private void SubmitButton_Click(object sender, EventArgs e) { if (IsFormValid()) { HideValidationErrorLabel(); order = OrderConverter.convertFromFormValues(orderFormValues, orderConfigurationFormValues); OrderCalulationResult calulationResult = OrderCalculator.CalculateCost(order); OrderCalculationsResultForm calculationsResultForm = new OrderCalculationsResultForm(calulationResult) { Visible = true }; } else { System.Console.Out.WriteLine("Form is invalid"); DisplayValidationErrors(); } }
private void PopulateControls() { if (StoreContext.ShoppingCart.GetCartItems().Length > 0) { uxPanel.Visible = true; uxTotalAmountLabel.Text = StoreContext.Currency.FormatPrice( GetShoppingCartTotal()); OrderCalculator orderCalculator = new OrderCalculator(); decimal discount = orderCalculator.GetPreCheckoutDiscount( StoreContext.Customer, StoreContext.ShoppingCart.SeparateCartItemGroups(), StoreContext.CheckoutDetails.Coupon); if (discount > 0) { uxDiscountTR.Visible = true; uxDiscountAmountLabel.Text = StoreContext.Currency.FormatPrice(discount * -1); } else { uxDiscountTR.Visible = false; } uxGrid.DataSource = StoreContext.ShoppingCart.GetCartItems(); uxGrid.DataBind(); } else { uxPanel.Visible = false; uxShoppingCartDiv.Visible = true; uxMessageLabel.Text = "[$Your shopping cart is empty]"; uxBackHomeLink.Visible = true; StoreContext.CheckoutDetails.Clear(); } if (uxTaxIncludePanel.Visible) { uxTaxIncludeMessageLabel.Text = String.Format("[$TaxIncludeMessage1] {0} [$TaxIncludeMessage2]", DataAccessContext.Configurations.GetValue("TaxPercentageIncludedInPrice").ToString()); } PopulateContinueUrl(); }