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 GroupPromotion_NoProduct_ShouldNotApplyNo() { var order = new Order(new [] { new Item(secondProduct) }); var groupPromotion = new GroupPromotion { Product = firstProduct, Quantity = 2, Price = 3 }; Assert.Equal(0, groupPromotion.ApplyTo(order).Count); }
public void GroupPromotion_MultipleProducts_ShouldApply() { var order = new Order(new [] { new Item(firstProduct), new Item(secondProduct), new Item(firstProduct), new Item(firstProduct), new Item(firstProduct) }); var groupPromotion = new GroupPromotion { Product = firstProduct, Quantity = 2, Price = 3 }; var discounts = groupPromotion.ApplyTo(order); var discountValue = firstProduct.Price - 1.5; Assert.Equal(4, discounts.Count); Assert.Equal(order.Items[0], discounts[0].Item); Assert.Equal(discountValue, discounts[0].Value); Assert.Equal(order.Items[2], discounts[1].Item); Assert.Equal(discountValue, discounts[1].Value); Assert.Equal(order.Items[3], discounts[2].Item); Assert.Equal(discountValue, discounts[2].Value); Assert.Equal(order.Items[4], discounts[3].Item); Assert.Equal(discountValue, discounts[3].Value); }