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 AdditionalPromotion_NoMultiple_ShouldNotApply() { var order = new Order(new [] { new Item(firstProduct) }); var additionalPromotion = new AdditionalPromotion { Category = "fruit", Percent = 50 }; Assert.Equal(0, additionalPromotion.ApplyTo(order).Count); }
public void AdditionalPromotion_AdditionalProducts_ShouldApply() { var order = new Order(new [] { new Item(firstProduct), new Item(secondProduct) }); var additionalPromotion = new AdditionalPromotion { Category = "fruit", Percent = 50 }; var discounts = additionalPromotion.ApplyTo(order); Assert.Equal(1, discounts.Count); Assert.Equal(order.Items[1], discounts[0].Item); Assert.Equal(secondProduct.Price / 2, discounts[0].Value); }