public void After_Updating_The_Quantity_On_An_Item_Already_In_A_Basket_Both_The_Basket_And_Item_Quantities_Are_Correct(int itemId, string itemName, decimal itemPrice) { //Arrange IShoppingItem item = new ShoppingItem(itemId, itemName, itemPrice); //Act IShoppingBasketItem basketItem = _basket.AddItem(item); _basket.AddItem(item, 3); //As there is no "Edit" method defined on the interface updating the quantity is done by adding another item _basket.RemoveItem(basketItem); //As we added 4 Items and removed 1, 3 Items should now remain in the Basket //Assert List <IShoppingBasketItem> basketItems = _basket.Items as List <IShoppingBasketItem>; basketItems.FirstOrDefault(x => x.Id == itemId).Quantity.Should().Be(3); basketItems.Sum(x => x.Quantity).Should().Be(3); }
public void WhenItemsAreRemoved(string itemStringIds) { var itemIds = itemStringIds.Split(',').Select(s => int.Parse(s.Trim())); var basketItems = itemIds .Select(id => _shoppingBasket.Items.FirstOrDefault(i => i.Id == id)) .Where(i => i != null); // for removal of non existant item scenario if (basketItems.Count() == 0) { basketItems = itemIds.Select(id => CreateItem <DefaultShoppingBasketItem>(id)); } foreach (var basketItem in basketItems) { _shoppingBasket.RemoveItem(basketItem); } }
public ActionResult Remove(int id) { _basket.RemoveItem(id); return(RedirectToAction("Index")); }