From 09d14d1f330d71bc69a4e9fedace680f9c69de3b Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 19 May 2020 20:06:43 +0300 Subject: Did all tests for Service/Tiles/Items and Service/Tiles/Items --- .../Tiles/Crafting/CraftingControllerTests.cs | 45 +++++++++++++++ .../Tiles/Items/ItemControllerTests.cs | 64 ++++++++++++++++++++++ .../ServiceTests/Tiles/Items/Types/GearTests.cs | 28 ++++++++++ .../Tiles/Items/Types/GroundTileTests.cs | 28 ++++++++++ .../Tiles/Items/Types/MaterialTests.cs | 28 ++++++++++ .../Tiles/Items/Types/StructureTests.cs | 29 ++++++++++ .../ServiceTests/Tiles/Items/Types/ToolTests.cs | 29 ++++++++++ 7 files changed, 251 insertions(+) create mode 100644 MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs create mode 100644 MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs create mode 100644 MundusTests/ServiceTests/Tiles/Items/Types/GearTests.cs create mode 100644 MundusTests/ServiceTests/Tiles/Items/Types/GroundTileTests.cs create mode 100644 MundusTests/ServiceTests/Tiles/Items/Types/MaterialTests.cs create mode 100644 MundusTests/ServiceTests/Tiles/Items/Types/StructureTests.cs create mode 100644 MundusTests/ServiceTests/Tiles/Items/Types/ToolTests.cs (limited to 'MundusTests/ServiceTests') diff --git a/MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs b/MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs new file mode 100644 index 0000000..1594f03 --- /dev/null +++ b/MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs @@ -0,0 +1,45 @@ +namespace MundusTests.ServiceTests.Tiles.Crafting +{ + using System.Linq; + using Gtk; + using Mundus.Data; + using Mundus.Data.Tiles.Mobs; + using Mundus.Data.Tiles.Presets; + using Mundus.Data.Windows; + using Mundus.Service.Tiles.Crafting; + using NUnit.Framework; + + [TestFixture] + public static class CraftingControllerTests + { + [OneTimeSetUp] + public static void SetUp() + { + Application.Init(); + DataBaseContexts.CreateInstances(); + WI.CreateInstances(); + WI.WNewGame.OnBtnGenerateClicked(null, null); + } + + [OneTimeTearDown] + public static void TearDown() + { + Application.Quit(); + } + + [Test] + public static void PlayerSuccessfullyCrafts() + { + var recipe = DataBaseContexts.CTContext.CraftingRecipes.First(x => x.ResultItem == "wooden_shovel"); + + for(int i = 0; i < recipe.Count1; i++) + { + MI.Player.Inventory.AppendToItems(MaterialPresets.GetALandStick()); + } + CraftingController.CraftItemPlayer(recipe); + + Assert.Contains(recipe.ResultItem, MI.Player.Inventory.Items.Where(x => x != null).Select(x => x.stock_id).ToArray(), "Result item isn't added to player's inventory"); + Assert.AreEqual(1, MI.Player.Inventory.Items.Where(x => x != null).Count(), "Not all required items are removed from player's inventory"); + } + } +} diff --git a/MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs b/MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs new file mode 100644 index 0000000..1ccc228 --- /dev/null +++ b/MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs @@ -0,0 +1,64 @@ +using System; +using Mundus.Data; +using NUnit.Framework; +using Gtk; +using Mundus.Data.Windows; +using static Mundus.Service.Tiles.Mobs.Inventory; +using Mundus.Service.Tiles.Items; +using Mundus.Service.Tiles.Mobs; + +namespace MundusTests.ServiceTests.Tiles.Items { + [TestFixture] + public static class ItemControllerTests { + [OneTimeSetUp] + public static void SetUp() { + Application.Init(); + DataBaseContexts.CreateInstances(); + WI.CreateInstances(); + WI.WNewGame.OnBtnGenerateClicked(null, null); + } + + [OneTimeTearDown] + public static void TearDown() { + Application.Quit(); + } + + [Test] + [TestCase(InventoryPlace.Accessories, 1)] + [TestCase(InventoryPlace.Hotbar, 4)] + public static void SelectsItemProperly(InventoryPlace place, int index) { + ItemController.SelectItem(place, index); + + Assert.AreEqual(place, ItemController.SelItemPlace, "Item place isn't set correctly"); + Assert.AreEqual(index, ItemController.SelItemIndex, "Item index isn't set correctly"); + } + + [Test] + [TestCase(InventoryPlace.Hotbar, 1, InventoryPlace.Items, 1)] + public static void SwitchesDifferentItemsProperly(InventoryPlace origin, int originIndex, InventoryPlace destination, int destinationIndex) { + ItemController.SelectItem(destination, destinationIndex); + var destinationItem = Inventory.GetPlayerItemFromItemSelection(); + + ItemController.SelectItem(origin, originIndex); + var originItem = Inventory.GetPlayerItemFromItemSelection(); + + ItemController.SwitchItems(destination, destinationIndex); + + ItemController.SelectItem(origin, originIndex); + if (Inventory.GetPlayerItemFromItemSelection() != null) { + Assert.AreEqual(destinationItem.stock_id, Inventory.GetPlayerItemFromItemSelection().stock_id); + } + else { + Assert.Pass(); + } + + ItemController.SelectItem(destination, destinationIndex); + if (Inventory.GetPlayerItemFromItemSelection() != null) { + Assert.AreEqual(originItem.stock_id, Inventory.GetPlayerItemFromItemSelection()); + } + else { + Assert.Pass(); + } + } + } +} diff --git a/MundusTests/ServiceTests/Tiles/Items/Types/GearTests.cs b/MundusTests/ServiceTests/Tiles/Items/Types/GearTests.cs new file mode 100644 index 0000000..ab3d91c --- /dev/null +++ b/MundusTests/ServiceTests/Tiles/Items/Types/GearTests.cs @@ -0,0 +1,28 @@ +namespace MundusTests.ServiceTests.Tiles.Items.Types +{ + using Mundus.Service.Tiles.Items.Types; + using NUnit.Framework; + + [TestFixture] + public static class GearTests + { + [Test] + [TestCase(null)] + [TestCase("test")] + public static void InstantiatesFromStock(string stock_id) + { + Gear gt = new Gear(stock_id); + + Assert.AreEqual(stock_id, gt.stock_id, "Gear doesn't set stock_id properly"); + } + + [Test] + public static void InstantiatesFromAnotherGear() + { + Gear gt = new Gear("testing"); + Gear gt1 = new Gear(gt); + + Assert.AreEqual(gt.stock_id, gt1.stock_id, "Gear constructor doesn't work properly with a groundtile as a parameter"); + } + } +} diff --git a/MundusTests/ServiceTests/Tiles/Items/Types/GroundTileTests.cs b/MundusTests/ServiceTests/Tiles/Items/Types/GroundTileTests.cs new file mode 100644 index 0000000..807d652 --- /dev/null +++ b/MundusTests/ServiceTests/Tiles/Items/Types/GroundTileTests.cs @@ -0,0 +1,28 @@ +namespace MundusTests.ServiceTests.Tiles.Items.Types +{ + using Mundus.Service.Tiles.Items.Types; + using NUnit.Framework; + + [TestFixture] + public static class GroundTileTests + { + [Test] + [TestCase(null)] + [TestCase("test")] + public static void InstantiatesFromStock(string stock_id) + { + GroundTile gt = new GroundTile(stock_id, 0); + + Assert.AreEqual(stock_id, gt.stock_id, "GroundTile doesn't set stock_id properly"); + } + + [Test] + public static void InstantiatesFromAnotherGroundTile() + { + GroundTile gt = new GroundTile("testing", 0); + GroundTile gt1 = new GroundTile(gt); + + Assert.AreEqual(gt.stock_id, gt1.stock_id, "GroundTile constructor doesn't work properly with a groundtile as a parameter"); + } + } +} diff --git a/MundusTests/ServiceTests/Tiles/Items/Types/MaterialTests.cs b/MundusTests/ServiceTests/Tiles/Items/Types/MaterialTests.cs new file mode 100644 index 0000000..c4e64d8 --- /dev/null +++ b/MundusTests/ServiceTests/Tiles/Items/Types/MaterialTests.cs @@ -0,0 +1,28 @@ +namespace MundusTests.ServiceTests.Tiles.Items.Types +{ + using Mundus.Service.Tiles.Items.Types; + using NUnit.Framework; + + [TestFixture] + public static class MaterialTests + { + [Test] + [TestCase(null)] + [TestCase("test")] + public static void InstantiatesFromStock(string stock_id) + { + Material gt = new Material(stock_id); + + Assert.AreEqual(stock_id, gt.stock_id, "Material doesn't set stock_id properly"); + } + + [Test] + public static void InstantiatesFromAnotherMaterial() + { + Material gt = new Material("testing"); + Material gt1 = new Material(gt); + + Assert.AreEqual(gt.stock_id, gt1.stock_id, "Material constructor doesn't work properly with a groundtile as a parameter"); + } + } +} diff --git a/MundusTests/ServiceTests/Tiles/Items/Types/StructureTests.cs b/MundusTests/ServiceTests/Tiles/Items/Types/StructureTests.cs new file mode 100644 index 0000000..0a18a1b --- /dev/null +++ b/MundusTests/ServiceTests/Tiles/Items/Types/StructureTests.cs @@ -0,0 +1,29 @@ +namespace MundusTests.ServiceTests.Tiles.Items.Types +{ + using Mundus.Service.Tiles.Items.Types; + using NUnit.Framework; + using static Mundus.Data.Values; + + [TestFixture] + public static class StructureTests + { + [Test] + [TestCase(null)] + [TestCase("test")] + public static void InstantiatesFromStock(string stock_id) + { + Structure gt = new Structure(stock_id, "", 0, ToolType.Axe, 0); + + Assert.AreEqual(stock_id, gt.stock_id, "Structure doesn't set stock_id properly"); + } + + [Test] + public static void InstantiatesFromAnotherStructure() + { + Structure gt = new Structure("testing", "", 0, ToolType.Axe, 0); + Structure gt1 = new Structure(gt); + + Assert.AreEqual(gt.stock_id, gt1.stock_id, "Structure constructor doesn't work properly with a groundtile as a parameter"); + } + } +} diff --git a/MundusTests/ServiceTests/Tiles/Items/Types/ToolTests.cs b/MundusTests/ServiceTests/Tiles/Items/Types/ToolTests.cs new file mode 100644 index 0000000..79f2438 --- /dev/null +++ b/MundusTests/ServiceTests/Tiles/Items/Types/ToolTests.cs @@ -0,0 +1,29 @@ +namespace MundusTests.ServiceTests.Tiles.Items.Types +{ + using Mundus.Service.Tiles.Items.Types; + using NUnit.Framework; + using static Mundus.Data.Values; + + [TestFixture] + public static class ToolTests + { + [Test] + [TestCase(null)] + [TestCase("test")] + public static void InstantiatesFromStock(string stock_id) + { + Tool gt = new Tool(stock_id, ToolType.Axe, 0); + + Assert.AreEqual(stock_id, gt.stock_id, "Tool doesn't set stock_id properly"); + } + + [Test] + public static void InstantiatesFromAnotherTool() + { + Tool gt = new Tool("testing", ToolType.Axe, 0); + Tool gt1 = new Tool(gt); + + Assert.AreEqual(gt.stock_id, gt1.stock_id, "Tool constructor doesn't work properly with a groundtile as a parameter"); + } + } +} -- cgit v1.2.3