public void Init() { this.heroInventory = new HeroInventory(); this.commonItems = heroInventory.GetType().GetField("commonItems", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this.heroInventory) as Dictionary <string, IItem>; this.recipeItems = heroInventory.GetType().GetField("recipeItems", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this.heroInventory) as Dictionary <string, IRecipe>; }
public void Chech_Add_Recipe_To_Inventory_Without_Making_Item() { HeroInventory heroInventory = new HeroInventory(); var item1 = new CommonItem("a", 1, 1, 1, 1, 1); var item2 = new CommonItem("b", 1, 1, 1, 1, 1); heroInventory.AddCommonItem(item1); heroInventory.AddCommonItem(item2); var combine = new RecipeItem("A", 1, 1, 1, 1, 1, new List <string> { "a", "b", "c" }); heroInventory.AddRecipeItem(combine); Type type = heroInventory.GetType(); FieldInfo[] fieldInfo = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo commonItemsStorage = fieldInfo.First(f => f.GetCustomAttributes <ItemAttribute>() != null); Dictionary <string, IItem> items = (Dictionary <string, IItem>)commonItemsStorage.GetValue(heroInventory); Assert.AreEqual(2, items.Count); var item3 = new CommonItem("c", 1, 1, 1, 1, 1); heroInventory.AddCommonItem(item3); Assert.AreEqual(1, items.Values.Count); }
public void Check_Combine_Method_In_HeroInventory() { var inventory = new HeroInventory(); var item1 = new CommonItem("a", 1, 1, 1, 1, 1); var item2 = new CommonItem("b", 1, 1, 1, 1, 1); var item3 = new CommonItem("c", 1, 1, 1, 1, 1); var item4 = new CommonItem("d", 1, 1, 1, 1, 1); var combine = new RecipeItem("A", 1, 1, 1, 1, 1, new List <string> { "a", "b" }); inventory.AddCommonItem(item1); inventory.AddCommonItem(item2); inventory.AddCommonItem(item3); inventory.AddCommonItem(item4); inventory.AddRecipeItem(combine); Type type = inventory.GetType(); FieldInfo[] fieldInfo = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo commonItemsStorage = fieldInfo.First(f => f.GetCustomAttributes <ItemAttribute>() != null); Dictionary <string, IItem> items = (Dictionary <string, IItem>)commonItemsStorage.GetValue(inventory); Assert.AreEqual(3, items.Values.Count); }
public void Chech_If_Item_Storage_Is_Empty_Due_To_Initialization() { HeroInventory heroInventory = new HeroInventory(); Type type = heroInventory.GetType(); FieldInfo[] fieldInfo = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo commonItemsStorage = fieldInfo.First(f => f.GetCustomAttributes <ItemAttribute>() != null); Dictionary <string, IItem> items = (Dictionary <string, IItem>)commonItemsStorage.GetValue(heroInventory); Assert.IsEmpty(items); }
public void Check_If_HeroInventory_Add_CommonItem_To_Dictionary() { HeroInventory heroInventory = new HeroInventory(); var item = new CommonItem("maic", 1, 1, 1, 1, 1); var item2 = new CommonItem("mc", 1, 1, 1, 1, 1); Type type = heroInventory.GetType(); FieldInfo[] fieldInfo = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo commonItemsStorage = fieldInfo.First(f => f.GetCustomAttributes <ItemAttribute>() != null); Dictionary <string, IItem> items = (Dictionary <string, IItem>)commonItemsStorage.GetValue(heroInventory); heroInventory.AddCommonItem(item); heroInventory.AddCommonItem(item2); Assert.AreEqual(2, items.Values.Count); }
public void AddsCommonItem() { //Arrange var inventory = new HeroInventory(); IItem item = new CommonItem("Knife", 0, 10, 0, 0, 30); Type getType = inventory.GetType(); var field = getType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic) .FirstOrDefault(f => f.Name.Equals("commonItems", StringComparison.OrdinalIgnoreCase)); var mockField = (Dictionary <string, IItem>)field.GetValue(false); //Assert inventory.AddCommonItem(item); //Assert Assert.AreEqual(1, mockField.Values.Count); }