Пример #1
0
        private decimal?PromotionPrice(string productName, decimal productPrice, int quantity, PricingStrategy pricingStrategy)
        {
            var promotions = promotionRepository.FindByProduct(productName);

            if (!promotions.Any())
            {
                return(null);
            }

            decimal?price = null;

            foreach (var promotion in promotions)
            {
                IApplyPromotion applyPromotion = null;

                switch (promotion.PromotionType)
                {
                case PromotionType.OnSale:
                    applyPromotion = new ApplyOnSalePromotion(promotion.Price.Value);
                    break;

                case PromotionType.GroupSale:
                    applyPromotion = new ApplyGroupSalePromotion(promotion.Quantity.Value, promotion.Price.Value, productPrice);
                    break;

                case PromotionType.AdditionalSale:
                    applyPromotion = new ApplyAdditionalSalePromotion(promotion.Quantity.Value, promotion.Discount.Value, productPrice);
                    break;

                default:
                    throw new PromotionTypeUnhandledException(promotion.PromotionType);
                }

                var promotionPrice = applyPromotion.Apply(quantity);
                if (!promotionPrice.HasValue)
                {
                    continue;
                }

                price = !price.HasValue
                    ? promotionPrice
                    : (pricingStrategy == PricingStrategy.Lowest && promotionPrice < price
                        ? promotionPrice
                        : (pricingStrategy == PricingStrategy.Highest && promotionPrice > price
                            ? promotionPrice : price));
            }

            return(price);
        }
Пример #2
0
        public void FindByProductName(string productName)
        {
            var applePromotions = promotionRepository.FindByProduct(productName);

            Assert.True(applePromotions.Any());
        }