public void LowestPricingRuleWins() { var checkout = new Checkout(new StandardPricingRule("productId", 1.0m), new StandardPricingRule("productId", 2.0m)); checkout.Add("productId"); checkout.Add("productId"); checkout.Total().Should().Be(2.0m); }
public void CheckoutDefault() { Checkout checkout = Checkout.New(_pricingService.GetPricingRules("DEFAULT")); checkout.Add(classic); checkout.Add(standout); checkout.Add(premium); Assert.AreEqual(987.97m, checkout.Total()); }
public void AppleCheckout() { var co = new Checkout(new ClassicJobStrategy(), new AppleStandoutStrategy(), new PremiumJobStrategy()); co.Add(new Job(JobTypes.Classic)); co.Add(new Job(JobTypes.Standout)); var total = co.Total(); total.Should().Be(269.99 + 299.99); }
public void CheckoutNike() { Checkout checkout = Checkout.New(_pricingService.GetPricingRules("NIKE")); checkout.Add(premium); checkout.Add(premium); checkout.Add(premium); checkout.Add(premium); Assert.AreEqual(1519.96m, checkout.Total()); }
public void CheckoutApple() { Checkout checkout = Checkout.New(_pricingService.GetPricingRules("APPLE")); checkout.Add(standout); checkout.Add(standout); checkout.Add(standout); checkout.Add(premium); Assert.AreEqual(1294.96m, checkout.Total()); }
public void CheckoutUnilever() { Checkout checkout = Checkout.New(_pricingService.GetPricingRules("UNILEVER")); checkout.Add(classic); checkout.Add(classic); checkout.Add(classic); checkout.Add(premium); Assert.AreEqual(934.97m, checkout.Total()); }
public void Nike3PremiumCheckout() { var co = new Checkout(new ClassicJobStrategy(), new StandOutJobStrategy(), new NikePremiumStrategy()); co.Add(new Job(JobTypes.Premium)); co.Add(new Job(JobTypes.Premium)); co.Add(new Job(JobTypes.Premium)); var total = co.Total(); total.Should().Be(394.99 * 3); }
public void Uniliever2ClassicCheckout() { var co = new Checkout(new UnilevierClassicStrategy(), new StandOutJobStrategy(), new PremiumJobStrategy()); var classicJob = new Job(JobTypes.Classic); co.Add(classicJob); co.Add(classicJob); var total = co.Total(); total.Should().Be(269.99 * 2); }
public Order Checkout(OrderDto orderDto) { var order = new Order(); var customer = _context.Customers.First(c => c.UserName == orderDto.CustomerId); _context.Entry(customer).Collection(c => c.PriceRules).Load(); order.Customer = customer; var orderDetails = new List <OrderDetail>(); foreach (var od in orderDto.OrderDetails) { var d = new OrderDetail(); var p = _context.Products.First(x => x.Id == od.ProductId); d.Order = order; d.Product = p; d.Quantity = od.Quantity; orderDetails.Add(d); } order.OrderDetails = orderDetails; // Calculate Discount var co = new Checkout(customer.PriceRules != null && customer.PriceRules.Any() ? new HashSet <PriceRule>(customer.PriceRules) : new HashSet <PriceRule>()); co.Add(order); order.PriceAfterDiscount = co.Total(); return(order); }
public void NoMatchingPricingRules_Throws() { var checkout = new Checkout(new StandardPricingRule("productId_A", 1.0m)); checkout.Add("productId_B"); checkout.Invoking(pr => pr.Total()).Should() .Throw <InvalidOperationException>() .WithMessage("There are no pricing rules associated with 'productId_B'."); }
public void NoPricingRules_Throws() { var checkout = new Checkout(); checkout.Add("productId"); checkout.Invoking(pr => pr.Total()).Should() .Throw <InvalidOperationException>() .WithMessage("There are no pricing rules associated with 'productId'."); }
/// <summary> /// Add <see cref="ArticleItemDataModel"/> to checkout list /// </summary> /// <param name="arg"></param> public void AddToCheckoutAction(object arg) { var data = (ArticleItemDataModel)arg; //todo; make typecheck Checkout.Add(data); NumberOfItemsInCheckout = Checkout.Count(); //TotalCheckoutPrice = (float)data.Article.BasePrice; AddToCheckoutSum((float)data.Article.BasePrice); BuyButtonEnabledMode = "True"; }
public void ExampleScenarios(string customer, string[] products, decimal total) { var checkout = new Checkout(GetPricingRulesForCustomer(customer)); foreach (var product in products) { checkout.Add(product); } checkout.Total().Should().Be(total); }
public void StandoutCheckout() { var co = new Checkout(new ClassicJobStrategy(), new StandOutJobStrategy(), new PremiumJobStrategy()); var standoutJob = new Job(JobTypes.Standout); var result = co.Add(standoutJob); result.Should().Be(true); var total = co.Total(); total.Should().Be(322.99); }
public void ClassicCheckout() { var co = new Checkout(new ClassicJobStrategy(), new StandOutJobStrategy(), new PremiumJobStrategy()); var classicJob = new Job(JobTypes.Classic); var result = co.Add(classicJob); result.Should().Be(true); var total = co.Total(); total.Should().Be(269.99); }
public decimal CheckoutProducts([FromBody] CheckoutRequest checkoutRequest) { List <Product> products = _productData.Get(); List <PricingRule> pricingRules = _pricingService.GetPricingRules(checkoutRequest.CustomerID); Checkout checkout = Checkout.New(pricingRules); foreach (string productID in checkoutRequest.ProductIDs) { Product product = products.FirstOrDefault(p => p.Id == productID); checkout.Add(product); } return(checkout.Total()); }
public void Ford3PremiumCheckout() { var co = new Checkout(new FordClassicStrategy(), new FordStandOutStrategy(), new FordPremiumStrategy()); co.Add(new Job(JobTypes.Classic)); co.Add(new Job(JobTypes.Classic)); co.Add(new Job(JobTypes.Classic)); co.Add(new Job(JobTypes.Classic)); co.Add(new Job(JobTypes.Classic)); co.Add(new Job(JobTypes.Standout)); co.Add(new Job(JobTypes.Premium)); co.Add(new Job(JobTypes.Premium)); co.Add(new Job(JobTypes.Premium)); var total = co.Total(); total.Should().Be(269.99 * 4 + 309.99 + 389.99 * 3); }
private void ScanMultipleItems(IPricingRules pricingRules, IPriceList priceList, string items, double total) { // Arrange var checkout = new Checkout(pricingRules, priceList); var list = items.Split(','); // Act foreach (var t in list) { Product result; Enum.TryParse(t, true, out result); checkout.Add(result); } // Assert Assert.AreEqual(total, checkout.Total); }