public PromotionsSerializerFacts() { var firstProduct = new Product { Name = "Apple", Price = 1.99, Categories = { "fruit" } }; var secondProduct = new Product { Name = "Orange", Price = 1.39, Categories = { "fruit" } }; var thirdProduct = new Product { Name = "Celery", Price = 0.99, Categories = { "vegetable" } }; var onSalePromotion = new OnSalePromotion { Product = firstProduct, SalePrice = 1.49 }; var groupPromotion = new GroupPromotion { Product = secondProduct, Quantity = 2, Price = 3 }; var additionalPromotion = new AdditionalPromotion { Category = "fruit", Percent = 50 }; products = new[] { firstProduct, secondProduct, thirdProduct }; promotions = new IPromotion[] { onSalePromotion, groupPromotion, additionalPromotion }; }
public void OnSalePromotion_WithoutProduct_ShouldNotApplyOnOrder() { var order = new Order(new [] { new Item(secondProduct) }); var onSalePromotion = new OnSalePromotion { Product = firstProduct, SalePrice = 1.49 }; var discounts = onSalePromotion.ApplyTo(order); Assert.Equal(0, discounts.Count); }
public void OnSalePromotion_WithProduct_ShouldApplyOnOrder() { var order = new Order(new [] { new Item(firstProduct), new Item(secondProduct) }); var onSalePromotion = new OnSalePromotion { Product = firstProduct, SalePrice = 1.49 }; var discounts = onSalePromotion.ApplyTo(order); Assert.Equal(1, discounts.Count); Assert.Equal(order.Items[0], discounts[0].Item); Assert.Equal(firstProduct.Price - 1.49, discounts[0].Value); }
public void WhenOneDiscount_ShouldPrintInvoice() { var items = new[] { new Item(firstProduct), new Item(secondProduct) }; var order = new Order(items); var promotion = new OnSalePromotion { Product = firstProduct, SalePrice = 1.49 }; var orderService = new OrderService(); string printedInvoice = orderService.PrintInvoice(order, new[] { promotion }); Assert.Equal("Apple 1.99\n-0.5Orange 1.39\nTotal 2.88", printedInvoice); }