From a4e2f6753c6c2612444847fd12f1e973a86a4aa4 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 20 May 2020 13:12:31 +0300 Subject: Fixed test SetUps and TearDowns. Did tests for Inventory and MobTile (Service/Mobs). Did some minor changes to the program. --- .../ServiceTests/Tiles/Mobs/InventoryTests.cs | 252 +++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 MundusTests/ServiceTests/Tiles/Mobs/InventoryTests.cs (limited to 'MundusTests/ServiceTests/Tiles/Mobs/InventoryTests.cs') diff --git a/MundusTests/ServiceTests/Tiles/Mobs/InventoryTests.cs b/MundusTests/ServiceTests/Tiles/Mobs/InventoryTests.cs new file mode 100644 index 0000000..9f0d687 --- /dev/null +++ b/MundusTests/ServiceTests/Tiles/Mobs/InventoryTests.cs @@ -0,0 +1,252 @@ +using System; +using Mundus.Service.Tiles.Items; +using Mundus.Service.Tiles.Items.Types; +using Mundus.Service.Tiles.Mobs; +using NUnit.Framework; + +namespace MundusTests.ServiceTests.Tiles.Mobs { + [TestFixture] + public static class InventoryTests { + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AddsToHotbar(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToHotbar(new Material(stock_id1), 2); + inv.AddToHotbar(new Material(stock_id2), 4); + + Assert.AreEqual(stock_id1, inv.Hotbar[2].stock_id, "Add to hotbar doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Hotbar[4].stock_id, "Add to hotbar doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AddsToItems(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToItems(new Material(stock_id1), 2); + inv.AddToItems(new Material(stock_id2), 4); + + Assert.AreEqual(stock_id1, inv.Items[2].stock_id, "Add to items doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Items[4].stock_id, "Add to items doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AddsToAccessories(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToAccessories(new Gear(stock_id1), 2); + inv.AddToAccessories(new Gear(stock_id2), 4); + + Assert.AreEqual(stock_id1, inv.Accessories[2].stock_id, "Add to accessories doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Accessories[4].stock_id, "Add to accessories doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AddsToGear(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToGear(new Gear(stock_id1), 2); + inv.AddToGear(new Gear(stock_id2), 4); + + Assert.AreEqual(stock_id1, inv.Gear[2].stock_id, "Add to gear doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Gear[4].stock_id, "Add to gear doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AppendsToHotbar(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AppendToHotbar(new Material(stock_id1)); + inv.AppendToHotbar(new Material(stock_id2)); + + Assert.AreEqual(stock_id1, inv.Hotbar[0].stock_id, "Append to hotbar doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Hotbar[1].stock_id, "Append to hotbar doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AppendsToItems(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AppendToItems(new Material(stock_id1)); + inv.AppendToItems(new Material(stock_id2)); + + Assert.AreEqual(stock_id1, inv.Items[0].stock_id, "Append to items doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Items[1].stock_id, "Append to items doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AppendsToAccessories(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AppendToAccessories(new Gear(stock_id1)); + inv.AppendToAccessories(new Gear(stock_id2)); + + Assert.AreEqual(stock_id1, inv.Accessories[0].stock_id, "Append to accessories doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Accessories[1].stock_id, "Append to accessories doesn't work as expected"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void AppendsToGear(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AppendToGear(new Gear(stock_id1)); + inv.AppendToGear(new Gear(stock_id2)); + + Assert.AreEqual(stock_id1, inv.Gear[0].stock_id, "Append to gear doesn't work as expected"); + Assert.AreEqual(stock_id2, inv.Gear[1].stock_id, "Append to gear doesn't work as expected"); + } + + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void DeletesFromHotbar(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToHotbar(new Gear(stock_id1), 2); + inv.AddToHotbar(new Gear(stock_id2), 4); + + inv.DeleteFromHotbar(2); + inv.DeleteFromHotbar(4); + + Assert.IsNull(inv.Hotbar[2], "Doesn't delete item properly from hotbar"); + Assert.IsNull(inv.Hotbar[4], "Doesn't delete item properly from hotbar"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void DeletesFromItems(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToItems(new Gear(stock_id1), 2); + inv.AddToItems(new Gear(stock_id2), 4); + + inv.DeleteFromItems(2); + inv.DeleteFromItems(4); + + Assert.IsNull(inv.Items[2], "Doesn't delete item properly from items"); + Assert.IsNull(inv.Items[4], "Doesn't delete item properly from items"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void DeletesFromAccessories(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToAccessories(new Gear(stock_id1), 2); + inv.AddToAccessories(new Gear(stock_id2), 4); + + inv.DeleteFromAccessories(2); + inv.DeleteFromAccessories(4); + + Assert.IsNull(inv.Accessories[2], "Doesn't delete item properly from accessories"); + Assert.IsNull(inv.Accessories[4], "Doesn't delete item properly from accessories"); + } + + [Test] + [TestCase("one", "two")] + [TestCase(null, "two")] + [TestCase("", "two")] + public static void DeletesFromGear(string stock_id1, string stock_id2) { + Inventory inv = new Inventory(5); + + inv.AddToGear(new Gear(stock_id1), 2); + inv.AddToGear(new Gear(stock_id2), 4); + + inv.DeleteFromGear(2); + inv.DeleteFromGear(4); + + Assert.IsNull(inv.Gear[2], "Doesn't delete item properly from gear"); + Assert.IsNull(inv.Gear[4], "Doesn't delete item properly from gear"); + } + + [Test] + [TestCase(1)] + [TestCase(5)] + [TestCase(10)] + public static void InstantiatesProperly(int size) { + Inventory inv = new Inventory(size); + + Assert.AreEqual(size, inv.Hotbar.Length, "Hotbar has incorrect size"); + Assert.AreEqual(size * size, inv.Items.Length, "Items has incorrect size"); + Assert.AreEqual(size * 2, inv.Accessories.Length, "Accessories has incorrect size"); + Assert.AreEqual(size, inv.Gear.Length, "Gear has incorrect size"); + } + + [Test] + [TestCase("one", 3)] + [TestCase(null, 1)] + [TestCase("", 4)] + public static void GetsProperHotbarItemTile(string stock_id, int index) { + Inventory inv = new Inventory(5); + + inv.AddToHotbar(new Material(stock_id), index); + + Assert.AreEqual(stock_id, inv.GetItemTile(Inventory.InventoryPlace.Hotbar, index).stock_id); + } + + [Test] + [TestCase("one", 3)] + [TestCase(null, 1)] + [TestCase("", 4)] + public static void GetsProperItemsItemTile(string stock_id, int index) { + Inventory inv = new Inventory(5); + + inv.AddToItems(new Material(stock_id), index); + + Assert.AreEqual(stock_id, inv.GetItemTile(Inventory.InventoryPlace.Items, index).stock_id); + } + + [Test] + [TestCase("one", 3)] + [TestCase(null, 1)] + [TestCase("", 4)] + public static void GetsProperAccessoriesItemTile(string stock_id, int index) { + Inventory inv = new Inventory(5); + + inv.AddToAccessories(new Gear(stock_id), index); + + Assert.AreEqual(stock_id, inv.GetItemTile(Inventory.InventoryPlace.Accessories, index).stock_id); + } + + [Test] + [TestCase("one", 3)] + [TestCase(null, 1)] + [TestCase("", 4)] + public static void GetsProperGearItemTile(string stock_id, int index) { + Inventory inv = new Inventory(5); + + inv.AddToGear(new Gear(stock_id), index); + + Assert.AreEqual(stock_id, inv.GetItemTile(Inventory.InventoryPlace.Gear, index).stock_id); + } + } +} -- cgit v1.2.3