public bool RemoveInventoryItem(KeyValuePair <InventoryItem, ItemType> item) { if (InventoryItems.Contains(item)) { InventoryItems.Remove(item); return(true); } return(false); }
// This function should really be private but I wanted to have a unit test for it. Make private if possible public void CheckItemInInventory(IInventoryItem item, bool exists = true) { string errorMessage = exists ? "Item {0} in {1} category is not in the inventory" : "Item {0} in {1} category is already in the inventory"; if (exists ^ InventoryItems.Contains(item)) { throw new Exception(string.Format(errorMessage, item.Name, item.Category)); } }