public void TestBasketSubtractFromTotalLessThanZero() { BasketItemModel basketItemApple = new BasketItemModel(_apple); BasketModel basket = new BasketModel(); basket.AddOrUpdateBasket(basketItemApple); basket.AddOrUpdateBasket(basketItemApple); Assert.AreEqual(2, basket.Total); basket.SubtractFromTotal(3); Assert.AreEqual(0, basket.Total); }
/// <summary> /// Takes a basket of items and a list of promotions and sees if any apply. /// If they apply it will add it to the item and subtract it from the total basket price. /// This only allows one Promotion per Item. /// </summary> /// <param name="basket"></param> /// <param name="promotions"></param> public void ApplyPromotionsToBasket(BasketModel basket, List <PromotionModel> promotions) { foreach (var basketItem in basket.Basket) { var promotion = promotions.FirstOrDefault(p => p.ItemId == basketItem.ItemId); if (promotion == null) { continue; } var discount = new DiscountModel(promotion, basketItem.ItemPrice); decimal discountAmount = ApplyDiscountToBasketItems(basketItem, discount); basket.SubtractFromTotal(discountAmount); } }