public void GroupPromotionTest(int quantity, int groupQuantity, decimal groupPrice, decimal actualPrice, double?expectedPrice) { var promotion = new ApplyGroupSalePromotion(groupQuantity, groupPrice, actualPrice); var promotionPrice = promotion.Apply(quantity); Assert.Equal((decimal?)expectedPrice, promotionPrice); }
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); }