public void LargePriceLargePercentage_ShouldHaveNoInternalOverflow() { var discount = new DiscountProduct{ DiscountType = DiscountType.Percentage, DiscountValue = 5000}; var actual = discount.GetAdjustedPrice(1000000); Assert.AreEqual(500000, actual); }
public static ProductInfo CreateProductInfo(int productPriceInCents, int itemCount, decimal vat = 19, DiscountProduct discount = null, IOrderInfo order = null) { var productInfo = new ProductInfo(); productInfo.IsDiscounted = discount == null; productInfo.OriginalPriceInCents = productPriceInCents; productInfo.Ranges = new List<Range>(); productInfo.Vat = vat; productInfo.ItemCount = itemCount; productInfo.Tags = new string[0]; if (order != null) { order.OrderLines = new List<OrderLine> {new OrderLine(productInfo, order)}; } productInfo.Order = order ?? CreateOrderInfo(productInfo); if (discount != null) { SetProductDiscountOnProductInfo(productInfo, discount); } return productInfo; }
public static ProductInfo CreateProductInfo(int productPriceInCents, int itemCount, DiscountProduct discount) { return CreateProductInfo(productPriceInCents, itemCount, 19, discount); }
public static void SetProductDiscountOnProductInfo(ProductInfo productInfo, DiscountProduct discount) { // todo: NewPrice. Maybe move this functionality elsewhere? (duplicate logic) if (discount.DiscountType == DiscountType.Amount) productInfo.DiscountAmountInCents = discount.RangedDiscountValue(productInfo.ItemCount.GetValueOrDefault(1)); else productInfo.DiscountPercentage = discount.RangedDiscountValue(productInfo.ItemCount.GetValueOrDefault(1))/100m; }