示例#1
0
        public IEnumerator BuyItem_ButNotEnoughSpace()
        {
            var inv   = new Dummy_Inventory(2);
            var itemA = new Item("Test", 1);

            inv.AddItem(itemA, 4);
            inv.AddItem(itemA, 4);
            var owner = new Test_InventoryOwner(new List <Inventory>()
            {
                inv
            }, 10);
            var item     = new Item("Test1", 1);
            var shopItem = new ItemShop(item, 10);
            var shop     = new Dummy_Shop(new List <ItemShop>()
            {
                shopItem
            });

            shop.Buy(0, owner);

            Assert.AreEqual(itemA, owner.GetInventories()[0].GetItem(0));
            Assert.AreEqual(itemA, owner.GetInventories()[0].GetItem(1));
            Assert.AreEqual(10, owner.GetCurrentCurency());

            yield return(null);
        }
示例#2
0
        public IEnumerator SellAllItemOfAllInventories()
        {
            var inv  = new Dummy_Inventory(9);
            var inv2 = new Dummy_Inventory(9);
            var item = new Item("Test", 1);

            inv.AddItem(item, 2);
            inv.AddItem(item, 2);
            inv2.AddItem(item, 2);
            var owner = new Test_InventoryOwner(new List <Inventory>()
            {
                inv, inv2
            }, 10);
            var shopItem = new ItemShop(item, 10);
            var shop     = new Dummy_Shop(new List <ItemShop>()
            {
                shopItem
            });

            shop.SellAll(owner);

            Assert.AreEqual(Item.Empty, owner.GetInventories()[0].GetItem(0));
            Assert.AreEqual(Item.Empty, owner.GetInventories()[0].GetItem(1));
            Assert.AreEqual(Item.Empty, owner.GetInventories()[1].GetItem(0));
            Assert.AreEqual(16, owner.GetCurrentCurency());

            yield return(null);
        }
示例#3
0
        public IEnumerator BuyItem_ButInventoryAlreadyFull_AndPutInSecondeInventory()
        {
            var inv   = new Dummy_Inventory(2);
            var inv2  = new Dummy_Inventory(2);
            var itemA = new Item("TestA", 3);

            inv.AddItem(itemA, 4);
            inv.AddItem(itemA, 4);
            var owner = new Test_InventoryOwner(new List <Inventory>()
            {
                inv, inv2
            }, 10);
            var item     = new Item("Test", 1);
            var shopItem = new ItemShop(item, 10);
            var shop     = new Dummy_Shop(new List <ItemShop>()
            {
                shopItem
            });

            shop.Buy(0, owner);

            Assert.AreEqual(itemA, owner.GetInventories()[0].GetItem(0));
            Assert.AreEqual(itemA, owner.GetInventories()[0].GetItem(1));
            Assert.AreEqual(item, owner.GetInventories()[1].GetItem(0));
            Assert.AreEqual(1, owner.GetInventories()[1].GetItem(0).count);
            Assert.AreEqual(Item.Empty, owner.GetInventories()[1].GetItem(1));

            Assert.AreEqual(0, owner.GetCurrentCurency());

            yield return(null);
        }
示例#4
0
        public IEnumerator CraftItem()
        {
            var inv  = new Dummy_Inventory(2);
            var item = new Item("Test", 4);

            inv.AddItem(item, 4);
            inv.AddItem(item, 4);
            var owner        = new Test_InventoryOwner(inv, 10);
            var craftResult  = new Item("TestC", 1);
            var itemCrafting = new ItemCrafting(new List <Item>()
            {
                craftResult
            }, new List <CraftingRecipe>()
            {
                new CraftingRecipe(new List <Item>()
                {
                    item
                }, new List <int>()
                {
                    8
                })
            });
            var crafting = new Crafting(new List <ItemCrafting>()
            {
                itemCrafting
            });

            crafting.Craft(owner, 0);

            Assert.AreEqual(craftResult, inv.GetItem(0));
            Assert.AreEqual(1, inv.GetItem(0).count);
            Assert.AreEqual(Item.Empty, inv.GetItem(1));

            yield return(null);
        }
示例#5
0
文件: Test.cs 项目: claudyy/Inventory
        public IEnumerator AddItemTwice()
        {
            var i        = new Dummy_Inventory(9);
            var itemData = new Item("Test1", 1);

            i.AddItem(itemData, 1);
            i.AddItem(itemData, 1);
            Assert.AreEqual(i.GetItem(0), itemData);
            Assert.AreEqual(i.GetItem(0).count, 2);
            yield return(null);
        }
示例#6
0
        public IEnumerator SortByType()
        {
            var i         = new Dummy_Inventory(9);
            var itemDataA = new Item("A", ItemType.armor, 1);
            var itemDataB = new Item("B", ItemType.collectable, 1);

            i.AddItem(itemDataA, 1);
            i.AddItem(itemDataB, 1);
            i.SortByType();
            Assert.AreEqual(itemDataA.Type, i.GetItem(0).Type);
            Assert.AreEqual(itemDataB.Type, i.GetItem(1).Type);
            yield return(null);
        }
示例#7
0
文件: Test.cs 项目: claudyy/Inventory
        public IEnumerator AddItemCheckCount()
        {
            var i        = new Dummy_Inventory(9);
            var itemData = new Item("Test1", 1);

            i.AddItem(itemData, 4);
            Assert.AreEqual(i.CountOfItem(itemData) == 4, true);
            Assert.AreEqual(i.CountOfItem(itemData) == 6, false);
            i.AddItem(itemData, 6);
            Assert.AreEqual(i.CountOfItem(itemData) == 10, true);
            Assert.AreEqual(i.CountOfItem(itemData) == 12, false);
            yield return(null);
        }
示例#8
0
        public IEnumerator SortByName()
        {
            var i         = new Dummy_Inventory(9);
            var itemDataA = new Item("TestA", 1);
            var itemDataB = new Item("TestB", 1);

            i.AddItem(itemDataA, 1);
            i.AddItem(itemDataB, 1);
            i.SortByName();
            Assert.AreEqual(itemDataA, i.GetItem(0));
            Assert.AreEqual(itemDataB, i.GetItem(1));
            yield return(null);
        }
示例#9
0
        public IEnumerator SwitchItem()
        {
            var i         = new Dummy_Inventory(9);
            var itemData  = new Item("Test1", 1);
            var itemData2 = new Item("Test2", 1);

            i.AddItem(itemData, 1);
            i.AddItem(itemData2, 1);
            i.SwitchPositions(0, 1);
            Assert.AreEqual(itemData, i.GetItem(1));
            Assert.AreEqual(itemData2, i.GetItem(0));
            yield return(null);
        }
示例#10
0
        public IEnumerator FilterGetAll()
        {
            var i         = new Dummy_Inventory(9);
            var itemDataA = new Item("A", ItemType.armor, 1);
            var itemDataB = new Item("B", ItemType.collectable, 1);

            i.AddItem(itemDataA, 1);
            i.AddItem(itemDataB, 1);
            var list = i.GetAllItems();

            Assert.AreEqual(itemDataA, list[0]);
            Assert.AreEqual(itemDataB, list[1]);
            yield return(null);
        }
示例#11
0
文件: Test.cs 项目: claudyy/Inventory
        public IEnumerator AddItemFillStackTwice()
        {
            var i        = new Dummy_Inventory(9);
            var itemData = new Item("Test1", 1);

            i.AddItem(itemData, 4);
            i.AddItem(itemData, 4);
            Assert.AreEqual(i.GetItem(0), itemData);
            Assert.AreEqual(i.GetItem(0).StackFull, true);
            Assert.AreEqual(i.GetItem(1), itemData);
            Assert.AreEqual(i.GetItem(1).StackFull, true);
            Assert.AreEqual(i.GetItem(2), Item.Empty);

            yield return(null);
        }
示例#12
0
        public IEnumerator FilterGetItemsThatContainString()
        {
            var i = new Dummy_Inventory(9);

            i.AddItem(new Item("Test", ItemType.armor, 1), 1);
            i.AddItem(new Item("Test3", ItemType.collectable, 1), 1);
            i.AddItem(new Item("Bla2", ItemType.equipement, 1), 1);
            i.AddItem(new Item("Bla1", ItemType.equipement, 1), 1);
            var list = i.GetItemsThatContainInName("Bla");

            Assert.AreEqual(2, list.Count);
            list = i.GetItemsThatContainInName("bla");
            Assert.AreEqual(2, list.Count);
            yield return(null);
        }
示例#13
0
        public IEnumerator BuyItem_ThatInvnentoryAlreadyHas()
        {
            var inv   = new Dummy_Inventory(2);
            var itemA = new Item("Test", 3);

            inv.AddItem(itemA, 3);
            var owner = new Test_InventoryOwner(new List <Inventory>()
            {
                inv
            }, 10);
            var item     = new Item("Test", 1);
            var shopItem = new ItemShop(item, 10);
            var shop     = new Dummy_Shop(new List <ItemShop>()
            {
                shopItem
            });

            shop.Buy(0, owner);

            Assert.AreEqual(itemA, owner.GetInventories()[0].GetItem(0));
            Assert.AreEqual(Item.Empty, owner.GetInventories()[0].GetItem(1));
            Assert.AreEqual(0, owner.GetCurrentCurency());

            yield return(null);
        }
示例#14
0
文件: Test.cs 项目: claudyy/Inventory
        public IEnumerator IsNotFull()
        {
            var i        = new Dummy_Inventory(9);
            var itemData = new Item("Test1", 1);

            i.AddItem(itemData, 4 * 8);
            Assert.AreEqual(i.IsFull(), false);
            yield return(null);
        }
示例#15
0
        public IEnumerator FilterGetOfMultipleTypes()
        {
            var i         = new Dummy_Inventory(9);
            var itemDataA = new Item("A", ItemType.armor, 1);

            i.AddItem(itemDataA, 1);
            i.AddItem(new Item("B", ItemType.collectable, 1), 1);
            i.AddItem(new Item("E", ItemType.equipement, 1), 1);
            i.AddItem(new Item("AS", ItemType.equipement, 1), 1);
            var list = i.GetAllItems(new List <ItemType>()
            {
                ItemType.armor, ItemType.collectable
            });

            Assert.AreEqual(itemDataA, list[0]);
            Assert.AreEqual(2, list.Count);
            yield return(null);
        }
示例#16
0
文件: Test.cs 项目: claudyy/Inventory
        public IEnumerator AddItemRemoveMoreThanPossible()
        {
            var i        = new Dummy_Inventory(9);
            var itemData = new Item("Test1", 1);

            i.AddItem(itemData, 4);
            Assert.AreEqual(i.RemoveItem(itemData, 6), false);
            Assert.AreEqual(i.GetItem(0).count, 4);

            yield return(null);
        }
示例#17
0
文件: Test.cs 项目: claudyy/Inventory
        public IEnumerator AddItemRemoveItem()
        {
            var i        = new Dummy_Inventory(9);
            var itemData = new Item("Test1", 1);

            i.AddItem(itemData, 4);
            Assert.AreEqual(i.RemoveItem(itemData, 4), true);

            Assert.AreEqual(i.GetItem(0), Item.Empty);

            yield return(null);
        }
示例#18
0
        public IEnumerator CanNotCraftItem()
        {
            var inv   = new Dummy_Inventory(2);
            var item  = new Item("Test", 4);
            var item2 = new Item("Test2", 4);

            inv.AddItem(item2, 1);
            inv.AddItem(item, 1);
            var owner        = new Test_InventoryOwner(inv, 10);
            var craftResult  = new Item("TestC", 1);
            var itemCrafting = new ItemCrafting(new List <Item>()
            {
                craftResult
            }, new List <CraftingRecipe>()
            {
                new CraftingRecipe(new List <Item>()
                {
                    item
                }, new List <int>()
                {
                    4
                }), new CraftingRecipe(new List <Item>()
                {
                    item2
                }, new List <int>()
                {
                    4
                })
            });
            var crafting = new Crafting(new List <ItemCrafting>()
            {
                itemCrafting
            });

            Assert.AreEqual(false, crafting.CanCraft(owner, 0));

            yield return(null);
        }
示例#19
0
        public IEnumerator SwitchSameItemFromTwoDifferentInventories()
        {
            var i         = new Dummy_Inventory(9);
            var i2        = new Dummy_Inventory(9);
            var itemData  = new Item("Test1", 1);
            var itemData2 = new Item("Test1", 1);

            i.AddItem(itemData);
            i2.AddItem(itemData2);
            i2.SwitchPositions(0, 0, i);
            Assert.AreEqual(Item.Empty, i.GetItem(0));
            Assert.AreEqual(itemData, i2.GetItem(0));
            Assert.AreEqual(2, i2.GetItem(0).count);
            yield return(null);
        }