Пример #1
0
        public void BuyItem()                         //Test buying an item
        {
            string tempFile = Path.GetTempFileName(); //create a temporary file

            File.WriteAllText(tempFile, "Weapons:IronDagger,IronBow,\nKeys:0\nGold:500\nEquipped:IronDagger\nItems:\nCharacters:");
            InventoryItemsModel info = new InventoryItemsModel(tempFile);
            UserModel           user = new UserModel();

            user.Character = "(0_0)";
            ShopViewModel test = new ShopViewModel(new ShopModel(info), new ItemInfoModel(info), new WeaponInfoModel(info), new CharacterInfoModel(info, "test"), user, true);

            test.BuyAsync(info, 1, "HealthPotion", true);
            Assert.Single(test.Inv.pots);
            Assert.Equal("485", test.Gold);
            Assert.Equal("HealthPotion,", UserModel.CheckForstring(tempFile, "Items:"));
        }
Пример #2
0
        public void BuyWeapon()                       //Test buying a weapon
        {
            string tempFile = Path.GetTempFileName(); //create a temporary file

            File.WriteAllText(tempFile, "Weapons:IronDagger,IronBow,\nKeys:0\nGold:500\nEquipped:IronDagger\nItems:\nCharacters:");
            InventoryItemsModel info = new InventoryItemsModel(tempFile);
            UserModel           user = new UserModel();

            user.Character = "(0_0)";
            ShopViewModel test = new ShopViewModel(new ShopModel(info), new ItemInfoModel(info), new WeaponInfoModel(info), new CharacterInfoModel(info, "test"), user, true);

            test.BuyAsync(info, 0, "SteelSword", true);
            Assert.Equal(3, test.Weapon.weapons.Count);
            Assert.Equal("489", test.Gold);
            Assert.Equal("IronDagger,IronBow,SteelSword,", UserModel.CheckForstring(tempFile, "Weapons:"));
        }