/// <summary> /// 計算折扣 /// </summary> /// <param name="discount">折扣</param> /// <returns>折扣後金額</returns> public int CalculateDiscount(IDiscount discount) { int checkoutAmount = this.OriginalPrice; checkoutAmount = this.OriginalPrice - discount.CalculateDiscountAmount(this.OriginalPrice); return(checkoutAmount); }
public void Caclulate_Discount_No_Special_Offers_To_Be_Applied_Returns_Zero() { // Arrange var items = new List <Item> { new Item { SKU = "A99", Price = 0.50m }, new Item { SKU = "B15", Price = 0.30m }, new Item { SKU = "C40", Price = 0.60m } }; // Act var discount = _discount.CalculateDiscountAmount(items); // Assert Assert.AreEqual(0, discount); }
public decimal Total() { if (!_items.Any()) { return(0); } var total = _items.Sum(item => item.Price); var discountAmount = _discount.CalculateDiscountAmount(_items); return(total - discountAmount); }