Ejemplo n.º 1
0
        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 };
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }