From 43e65fb3c92df024ee4eaff454b1fe340c07c41f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 19 May 2020 15:06:40 +0300 Subject: Fixed MITests and did all Service/SuperLayers tests (for HeightController and ImageController) --- .../SuperLayers/HeightControllerTests.cs | 13 +- .../SuperLayers/ImageControllerTests.cs | 159 +++++++++++++++++++++ 2 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs (limited to 'MundusTests/ServiceTests/SuperLayers') diff --git a/MundusTests/ServiceTests/SuperLayers/HeightControllerTests.cs b/MundusTests/ServiceTests/SuperLayers/HeightControllerTests.cs index 0612454..70a2d02 100644 --- a/MundusTests/ServiceTests/SuperLayers/HeightControllerTests.cs +++ b/MundusTests/ServiceTests/SuperLayers/HeightControllerTests.cs @@ -6,12 +6,15 @@ [TestFixture] public static class HeightControllerTests - { + { + [OneTimeSetUp] + public static void SetUp() { + DataBaseContexts.CreateInstances(); + } + [Test] - public static void GetsCorrectSuperLayerUnderneath() + public static void GetsCorrectSuperLayerUnderneath() { - DataBaseContexts.CreateInstances(); - Assert.AreEqual(DataBaseContexts.LContext, HeightController.GetSuperLayerUnderneath(DataBaseContexts.SContext), "GetSuperLayerUnderneath doesn't return that land is below sky"); Assert.AreEqual(DataBaseContexts.UContext, HeightController.GetSuperLayerUnderneath(DataBaseContexts.LContext), "GetSuperLayerUnderneath doesn't return that underground is below land"); Assert.AreEqual(null, HeightController.GetSuperLayerUnderneath(DataBaseContexts.UContext), "GetSuperLayerUnderneath doesn't return that there is nothing (null) below underground"); @@ -20,8 +23,6 @@ [Test] public static void GetsCorrectSuperLayerAbove() { - DataBaseContexts.CreateInstances(); - Assert.AreEqual(null, HeightController.GetSuperLayerAbove(DataBaseContexts.SContext), "GetSuperLayerUnderneath doesn't return that there is nothing (null) above sky"); Assert.AreEqual(DataBaseContexts.SContext, HeightController.GetSuperLayerAbove(DataBaseContexts.LContext), "GetSuperLayerUnderneath doesn't return that sky is above land"); Assert.AreEqual(DataBaseContexts.LContext, HeightController.GetSuperLayerAbove(DataBaseContexts.UContext), "GetSuperLayerUnderneath doesn't return that land is above underground"); diff --git a/MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs b/MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs new file mode 100644 index 0000000..c8d8e06 --- /dev/null +++ b/MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs @@ -0,0 +1,159 @@ +namespace MundusTests.ServiceTests.SuperLayers +{ + using Gtk; + using Mundus.Data; + using Mundus.Data.Tiles.Mobs; + using Mundus.Data.Windows; + using Mundus.Service.SuperLayers; + using NUnit.Framework; + using static Mundus.Service.SuperLayers.ImageController; + using static Mundus.Service.Tiles.Mobs.Inventory; + + [TestFixture] + public static class ImageControllerTests + { + [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(1, 5)] + [TestCase(2, 2)] + [TestCase(8, 11)] + public static void GetsCorrectGroundImage(int yPos, int xPos) + { + Image img = null; + + if (DataBaseContexts.LContext.GetGroundLayerStock(yPos, xPos) != null) + { + img = new Image(DataBaseContexts.LContext.GetGroundLayerStock(yPos, xPos), IconSize.Dnd); + } + + if (img == null) + { + Assert.AreEqual(img, ImageController.GetPlayerScreenImage(yPos, xPos, Layer.Ground), $"Ground image at Y:{yPos}, X:{xPos} should be null"); + } + else + { + Assert.AreEqual(img.Stock, ImageController.GetPlayerScreenImage(yPos, xPos, Layer.Ground).Stock, $"Ground image at Y:{yPos}, X:{xPos} should be {img.Stock}, but is {ImageController.GetPlayerScreenImage(yPos, xPos, Layer.Ground).Stock}"); + } + } + + [Test] + [TestCase(1, 5)] + [TestCase(2, 2)] + [TestCase(8, 11)] + public static void GetsCorrectMobImage(int yPos, int xPos) + { + Image img = null; + + if (DataBaseContexts.LContext.GetMobLayerStock(yPos, xPos) != null) + { + img = new Image(DataBaseContexts.LContext.GetMobLayerStock(yPos, xPos), IconSize.Dnd); + } + + if (img == null) + { + Assert.AreEqual(img, ImageController.GetPlayerScreenImage(yPos, xPos, Layer.Mob), $"Mob image at Y:{yPos}, X:{xPos} should be null"); + } + else + { + Assert.AreEqual(img.Stock, ImageController.GetPlayerScreenImage(yPos, xPos, Layer.Mob).Stock, $"Mob image at Y:{yPos}, X:{xPos} should be {img.Stock}, but is {ImageController.GetPlayerScreenImage(yPos, xPos, Layer.Ground).Stock}"); + } + } + + [Test] + [TestCase(1, 5)] + [TestCase(2, 2)] + [TestCase(8, 11)] + public static void GetsCorrectStructureImage(int yPos, int xPos) + { + Image img = null; + + if (DataBaseContexts.LContext.GetStructureLayerStock(yPos, xPos) != null) { + img = new Image(DataBaseContexts.LContext.GetStructureLayerStock(yPos, xPos), IconSize.Dnd); + } + + if (img == null) { + Assert.AreEqual(img, ImageController.GetPlayerScreenImage(yPos, xPos, Layer.Structure), $"Structure image at Y:{yPos}, X:{xPos} should be null"); + } + else { + Assert.AreEqual(img.Stock, ImageController.GetPlayerScreenImage(yPos, xPos, Layer.Structure).Stock, $"Structure image at Y:{yPos}, X:{xPos} should be {img.Stock}, but is {ImageController.GetPlayerScreenImage(yPos, xPos, Layer.Ground).Stock}"); + } + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public static void GetsCorrectPlayerHotbarImage(int index) + { + Image img = new Image("blank", IconSize.Dnd); + + if (MI.Player.Inventory.Hotbar[index] != null) + { + img = new Image(MI.Player.Inventory.Hotbar[index].stock_id, IconSize.Dnd); + } + + Assert.AreEqual(img.Stock, ImageController.GetPlayerInventoryImage(InventoryPlace.Hotbar, index).Stock, $"Hotbar image at index {index} should be {img.Stock}, but was {ImageController.GetPlayerInventoryImage(InventoryPlace.Hotbar, index).Stock}"); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public static void GetsCorrectPlayerItemsImage(int index) + { + Image img = new Image("blank", IconSize.Dnd); + + if (MI.Player.Inventory.Items[index] != null) + { + img = new Image(MI.Player.Inventory.Items[index].stock_id, IconSize.Dnd); + } + + Assert.AreEqual(img.Stock, ImageController.GetPlayerInventoryImage(InventoryPlace.Items, index).Stock, $"Items image at index {index} should be {img.Stock}, but was {ImageController.GetPlayerInventoryImage(InventoryPlace.Items, index).Stock}"); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public static void GetsCorrectPlayerAccessoriesImage(int index) { + Image img = new Image("blank_gear", IconSize.Dnd); + + if (MI.Player.Inventory.Accessories[index] != null) + { + img = new Image(MI.Player.Inventory.Accessories[index].stock_id, IconSize.Dnd); + } + + Assert.AreEqual(img.Stock, ImageController.GetPlayerInventoryImage(InventoryPlace.Accessories, index).Stock, $"Accessories image at index {index} should be {img.Stock}, but was {ImageController.GetPlayerInventoryImage(InventoryPlace.Accessories, index).Stock}"); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public static void GetsCorrectPlayerGearImage(int index) + { + Image img = new Image("blank_gear", IconSize.Dnd); + + if (MI.Player.Inventory.Gear[index] != null) + { + img = new Image(MI.Player.Inventory.Gear[index].stock_id, IconSize.Dnd); + } + + Assert.AreEqual(img.Stock, ImageController.GetPlayerInventoryImage(InventoryPlace.Gear, index).Stock, $"Gear image at index {index} should be {img.Stock}, but was {ImageController.GetPlayerInventoryImage(InventoryPlace.Gear, index).Stock}"); + } + } +} -- cgit v1.2.3