public void Load(string inventoryFile, ItemsData itemsData) { using (var writer = XmlWriter.Create(inventoryFile)) (new XmlSerializer(typeof(Inventory))).Serialize(writer, this); using (StreamReader reader2 = new StreamReader(inventoryFile)) { var serializer = new XmlSerializer(typeof(Inventory)); try { Inventory inventory = serializer.Deserialize(reader2) as Inventory; if (inventory != null) { foreach (var item in inventory.ItemToQuantity) { Item newitem = itemsData.FindItem(item.Key.ToString()); Console.WriteLine("Item: {0} Quantity: {1} Description {2} Effect {3} UnlockRequirement {4}" , item.Key, item.Value, newitem.Description, newitem.Effect, newitem.UnlockRequirement); } } } catch (Exception ex) { Console.WriteLine("Cannot load {0} due to the following {1}", inventoryFile, ex.Message); } } }
public void Search_For_Item() { string itemname = "Super Potion"; Item itemfound = mitemsData.FindItem(itemname); itemfound.Print(); Assert.IsTrue(itemfound.Name == "Super Potion"); }