private decimal CalculateDiscountValueForActiveDiscount( Discount activeDiscount, int qualifierProductQuantity, int discountedProductQuantity, decimal discountedProductUnitPrice) { var itemsApplicableForDiscount = qualifierProductQuantity / activeDiscount.QualifierQuantity; var discountMultiplier = itemsApplicableForDiscount >= discountedProductQuantity ? discountedProductQuantity : itemsApplicableForDiscount; var discountValue = ((discountedProductUnitPrice / 100m) * activeDiscount.DiscountPercentage) * discountMultiplier; return discountValue; }
private DiscountCalculator CreateSystemUnderTest() { var discount = new Discount { Name = "buy 2 productX and get a productY at 50% off", QualifierProductId = "product/x", DiscountedProductId = "product/y", DiscountPercentage = 50, QualifierQuantity = 2, IsActive = true }; var repository = new FakeDiscountRepository(); repository.Save(discount); var sut = new DiscountCalculator(repository); return sut; }