diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-22 12:59:32 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-22 12:59:32 +0300 |
| commit | 747aa00440eb9b219d989a536b0ff0c959b35143 (patch) | |
| tree | f8b866f8e95c4597cae6b246746c23967e03def6 /MundusTests/ServiceTests | |
| parent | a4e2f6753c6c2612444847fd12f1e973a86a4aa4 (diff) | |
| download | Mundus-747aa00440eb9b219d989a536b0ff0c959b35143.tar Mundus-747aa00440eb9b219d989a536b0ff0c959b35143.tar.gz Mundus-747aa00440eb9b219d989a536b0ff0c959b35143.zip | |
Completed all tests (there is still some code that can be tested, but it will be very hard to do so and I am skipping it for now).
Diffstat (limited to 'MundusTests/ServiceTests')
7 files changed, 130 insertions, 69 deletions
diff --git a/MundusTests/ServiceTests/GameEventLogControllerTests.cs b/MundusTests/ServiceTests/GameEventLogControllerTests.cs new file mode 100644 index 0000000..bed1ef9 --- /dev/null +++ b/MundusTests/ServiceTests/GameEventLogControllerTests.cs @@ -0,0 +1,35 @@ +namespace MundusTests.ServiceTests +{ + using System.Linq; + using Mundus.Data; + using Mundus.Service; + using NUnit.Framework; + + [TestFixture] + public static class GameEventLogControllerTests + { + [Test] + [TestCase("Testing")] + public static void AddsCorrectlyMessages(string message) + { + GameEventLogController.AddMessage(message); + + Assert.AreEqual(message, DataBaseContexts.GELContext.GameEventLogs.Single(x => x.ID == DataBaseContexts.GELContext.GameEventLogs.Count()).Message); + } + + [Test] + [TestCase("Testing1")] + public static void GetsCorrectlyMessage(string message) + { + GameEventLogController.AddMessage(message); + + Assert.AreEqual(message, GameEventLogController.GetMessagage(GameEventLogController.GetCount() - 1)); + } + + [Test] + public static void GetsCorrectCount() + { + Assert.AreEqual(DataBaseContexts.GELContext.GetCount(), GameEventLogController.GetCount()); + } + } +} diff --git a/MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs b/MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs index 9ab6418..248adbe 100644 --- a/MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs +++ b/MundusTests/ServiceTests/SuperLayers/ImageControllerTests.cs @@ -3,7 +3,6 @@ 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; @@ -12,7 +11,6 @@ [TestFixture] public static class ImageControllerTests { - [Test] [TestCase(1, 5)] [TestCase(2, 2)] @@ -67,14 +65,17 @@ { Image img = null; - if (DataBaseContexts.LContext.GetStructureLayerStock(yPos, xPos) != null) { + if (DataBaseContexts.LContext.GetStructureLayerStock(yPos, xPos) != null) + { img = new Image(DataBaseContexts.LContext.GetStructureLayerStock(yPos, xPos), IconSize.Dnd); } - if (img == null) { + if (img == null) + { Assert.AreEqual(img, ImageController.GetPlayerScreenImage(yPos, xPos, Layer.Structure), $"Structure image at Y:{yPos}, X:{xPos} should be null"); } - else { + 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}"); } } @@ -115,7 +116,8 @@ [TestCase(0)] [TestCase(1)] [TestCase(2)] - public static void GetsCorrectPlayerAccessoriesImage(int index) { + public static void GetsCorrectPlayerAccessoriesImage(int index) + { Image img = new Image("blank_gear", IconSize.Dnd); if (MI.Player.Inventory.Accessories[index] != null) diff --git a/MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs b/MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs index e0cd66d..5961c72 100644 --- a/MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs +++ b/MundusTests/ServiceTests/Tiles/Crafting/CraftingControllerTests.cs @@ -1,11 +1,9 @@ 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; @@ -17,10 +15,11 @@ { var recipe = DataBaseContexts.CTContext.CraftingRecipes.First(x => x.ResultItem == "wooden_shovel"); - for(int i = 0; i < recipe.Count1; i++) + 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"); diff --git a/MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs b/MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs index 497ccf3..a399e04 100644 --- a/MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs +++ b/MundusTests/ServiceTests/Tiles/Items/ItemControllerTests.cs @@ -1,19 +1,18 @@ -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 +{ + using Mundus.Service.Tiles.Items; + using Mundus.Service.Tiles.Mobs; + using NUnit.Framework; + using static Mundus.Service.Tiles.Mobs.Inventory; -namespace MundusTests.ServiceTests.Tiles.Items { [TestFixture] - public static class ItemControllerTests { + public static class ItemControllerTests + { [Test] [TestCase(InventoryPlace.Accessories, 1)] [TestCase(InventoryPlace.Hotbar, 4)] - public static void SelectsItemProperly(InventoryPlace place, int index) { + public static void SelectsItemProperly(InventoryPlace place, int index) + { ItemController.SelectItem(place, index); Assert.AreEqual(place, ItemController.SelItemPlace, "Item place isn't set correctly"); @@ -22,7 +21,8 @@ namespace MundusTests.ServiceTests.Tiles.Items { [Test] [TestCase(InventoryPlace.Hotbar, 1, InventoryPlace.Items, 1)] - public static void SwitchesDifferentItemsProperly(InventoryPlace origin, int originIndex, InventoryPlace destination, int destinationIndex) { + public static void SwitchesDifferentItemsProperly(InventoryPlace origin, int originIndex, InventoryPlace destination, int destinationIndex) + { ItemController.SelectItem(destination, destinationIndex); var destinationItem = Inventory.GetPlayerItemFromItemSelection(); @@ -32,18 +32,22 @@ namespace MundusTests.ServiceTests.Tiles.Items { ItemController.SwitchItems(destination, destinationIndex); ItemController.SelectItem(origin, originIndex); - if (Inventory.GetPlayerItemFromItemSelection() != null) { + if (Inventory.GetPlayerItemFromItemSelection() != null) + { Assert.AreEqual(destinationItem.stock_id, Inventory.GetPlayerItemFromItemSelection().stock_id); } - else { + else + { Assert.Pass(); } ItemController.SelectItem(destination, destinationIndex); - if (Inventory.GetPlayerItemFromItemSelection() != null) { + if (Inventory.GetPlayerItemFromItemSelection() != null) + { Assert.AreEqual(originItem.stock_id, Inventory.GetPlayerItemFromItemSelection()); } - else { + else + { Assert.Pass(); } } diff --git a/MundusTests/ServiceTests/Tiles/Items/Types/StructureTests.cs b/MundusTests/ServiceTests/Tiles/Items/Types/StructureTests.cs index 0a18a1b..dd9b80b 100644 --- a/MundusTests/ServiceTests/Tiles/Items/Types/StructureTests.cs +++ b/MundusTests/ServiceTests/Tiles/Items/Types/StructureTests.cs @@ -12,7 +12,7 @@ [TestCase("test")] public static void InstantiatesFromStock(string stock_id) { - Structure gt = new Structure(stock_id, "", 0, ToolType.Axe, 0); + Structure gt = new Structure(stock_id, string.Empty, 0, ToolType.Axe, 0); Assert.AreEqual(stock_id, gt.stock_id, "Structure doesn't set stock_id properly"); } @@ -20,7 +20,7 @@ [Test] public static void InstantiatesFromAnotherStructure() { - Structure gt = new Structure("testing", "", 0, ToolType.Axe, 0); + Structure gt = new Structure("testing", string.Empty, 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/Mobs/InventoryTests.cs b/MundusTests/ServiceTests/Tiles/Mobs/InventoryTests.cs index 9f0d687..567bb29 100644 --- a/MundusTests/ServiceTests/Tiles/Mobs/InventoryTests.cs +++ b/MundusTests/ServiceTests/Tiles/Mobs/InventoryTests.cs @@ -1,17 +1,18 @@ -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 +{ + using Mundus.Service.Tiles.Items.Types; + using Mundus.Service.Tiles.Mobs; + using NUnit.Framework; -namespace MundusTests.ServiceTests.Tiles.Mobs { [TestFixture] - public static class InventoryTests { + public static class InventoryTests + { [Test] [TestCase("one", "two")] [TestCase(null, "two")] [TestCase("", "two")] - public static void AddsToHotbar(string stock_id1, string stock_id2) { + public static void AddsToHotbar(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AddToHotbar(new Material(stock_id1), 2); @@ -25,7 +26,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", "two")] [TestCase(null, "two")] [TestCase("", "two")] - public static void AddsToItems(string stock_id1, string stock_id2) { + public static void AddsToItems(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AddToItems(new Material(stock_id1), 2); @@ -39,7 +41,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", "two")] [TestCase(null, "two")] [TestCase("", "two")] - public static void AddsToAccessories(string stock_id1, string stock_id2) { + public static void AddsToAccessories(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AddToAccessories(new Gear(stock_id1), 2); @@ -53,7 +56,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", "two")] [TestCase(null, "two")] [TestCase("", "two")] - public static void AddsToGear(string stock_id1, string stock_id2) { + public static void AddsToGear(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AddToGear(new Gear(stock_id1), 2); @@ -67,7 +71,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", "two")] [TestCase(null, "two")] [TestCase("", "two")] - public static void AppendsToHotbar(string stock_id1, string stock_id2) { + public static void AppendsToHotbar(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AppendToHotbar(new Material(stock_id1)); @@ -81,7 +86,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", "two")] [TestCase(null, "two")] [TestCase("", "two")] - public static void AppendsToItems(string stock_id1, string stock_id2) { + public static void AppendsToItems(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AppendToItems(new Material(stock_id1)); @@ -95,7 +101,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", "two")] [TestCase(null, "two")] [TestCase("", "two")] - public static void AppendsToAccessories(string stock_id1, string stock_id2) { + public static void AppendsToAccessories(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AppendToAccessories(new Gear(stock_id1)); @@ -109,7 +116,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", "two")] [TestCase(null, "two")] [TestCase("", "two")] - public static void AppendsToGear(string stock_id1, string stock_id2) { + public static void AppendsToGear(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AppendToGear(new Gear(stock_id1)); @@ -119,12 +127,12 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { 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) { + public static void DeletesFromHotbar(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AddToHotbar(new Gear(stock_id1), 2); @@ -141,7 +149,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", "two")] [TestCase(null, "two")] [TestCase("", "two")] - public static void DeletesFromItems(string stock_id1, string stock_id2) { + public static void DeletesFromItems(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AddToItems(new Gear(stock_id1), 2); @@ -158,7 +167,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", "two")] [TestCase(null, "two")] [TestCase("", "two")] - public static void DeletesFromAccessories(string stock_id1, string stock_id2) { + public static void DeletesFromAccessories(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AddToAccessories(new Gear(stock_id1), 2); @@ -175,7 +185,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", "two")] [TestCase(null, "two")] [TestCase("", "two")] - public static void DeletesFromGear(string stock_id1, string stock_id2) { + public static void DeletesFromGear(string stock_id1, string stock_id2) + { Inventory inv = new Inventory(5); inv.AddToGear(new Gear(stock_id1), 2); @@ -192,7 +203,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase(1)] [TestCase(5)] [TestCase(10)] - public static void InstantiatesProperly(int size) { + public static void InstantiatesProperly(int size) + { Inventory inv = new Inventory(size); Assert.AreEqual(size, inv.Hotbar.Length, "Hotbar has incorrect size"); @@ -205,7 +217,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", 3)] [TestCase(null, 1)] [TestCase("", 4)] - public static void GetsProperHotbarItemTile(string stock_id, int index) { + public static void GetsProperHotbarItemTile(string stock_id, int index) + { Inventory inv = new Inventory(5); inv.AddToHotbar(new Material(stock_id), index); @@ -217,7 +230,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", 3)] [TestCase(null, 1)] [TestCase("", 4)] - public static void GetsProperItemsItemTile(string stock_id, int index) { + public static void GetsProperItemsItemTile(string stock_id, int index) + { Inventory inv = new Inventory(5); inv.AddToItems(new Material(stock_id), index); @@ -229,7 +243,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", 3)] [TestCase(null, 1)] [TestCase("", 4)] - public static void GetsProperAccessoriesItemTile(string stock_id, int index) { + public static void GetsProperAccessoriesItemTile(string stock_id, int index) + { Inventory inv = new Inventory(5); inv.AddToAccessories(new Gear(stock_id), index); @@ -241,7 +256,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [TestCase("one", 3)] [TestCase(null, 1)] [TestCase("", 4)] - public static void GetsProperGearItemTile(string stock_id, int index) { + public static void GetsProperGearItemTile(string stock_id, int index) + { Inventory inv = new Inventory(5); inv.AddToGear(new Gear(stock_id), index); diff --git a/MundusTests/ServiceTests/Tiles/Mobs/MobTileTests.cs b/MundusTests/ServiceTests/Tiles/Mobs/MobTileTests.cs index b91877c..a4329dc 100644 --- a/MundusTests/ServiceTests/Tiles/Mobs/MobTileTests.cs +++ b/MundusTests/ServiceTests/Tiles/Mobs/MobTileTests.cs @@ -1,15 +1,17 @@ -using System; -using Mundus.Data; -using Mundus.Data.Windows; -using Mundus.Service.Tiles.Items.Types; -using Mundus.Service.Tiles.Mobs; -using NUnit.Framework; - -namespace MundusTests.ServiceTests.Tiles.Mobs { +namespace MundusTests.ServiceTests.Tiles.Mobs +{ + using Mundus.Data; + using Mundus.Data.Windows; + using Mundus.Service.Tiles.Items.Types; + using Mundus.Service.Tiles.Mobs; + using NUnit.Framework; + [TestFixture] - public static class MobTileTests { + public static class MobTileTests + { [Test] - public static void InstantiatesProperly() { + public static void InstantiatesProperly() + { MobTile mob = new MobTile("test", 10, 3, DataBaseContexts.SContext, 7, new Material("test_material"), 9); Assert.AreEqual("test", mob.stock_id); @@ -24,7 +26,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [Test] [TestCase(10, 3)] [TestCase(19, 11)] - public static void AliveAfterTakingSmallDamage(int health, int damage) { + public static void AliveAfterTakingSmallDamage(int health, int damage) + { MobTile mob = new MobTile("test", health, 3, DataBaseContexts.SContext); Assert.IsTrue(mob.TakeDamage(damage)); @@ -33,7 +36,8 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [Test] [TestCase(10, 10)] [TestCase(13, 20)] - public static void DeadAfterTakingBigDamage(int health, int damage) { + public static void DeadAfterTakingBigDamage(int health, int damage) + { MobTile mob = new MobTile("test", health, 3, DataBaseContexts.SContext); Assert.IsFalse(mob.TakeDamage(damage)); @@ -42,19 +46,20 @@ namespace MundusTests.ServiceTests.Tiles.Mobs { [Test] [TestCase(10, 10)] [TestCase(13, 20)] - public static void HealsProperly(int health, int healByPoints) { + public static void HealsProperly(int health, int healByPoints) + { MobTile mob = new MobTile("test", health, 3, DataBaseContexts.SContext); mob.Heal(healByPoints); - if (health + healByPoints > WI.SelWin.Size * 4) { + if (health + healByPoints > WI.SelWin.Size * 4) + { Assert.AreEqual(WI.SelWin.Size, mob.Health); } - else { - + else + { Assert.AreEqual(health + healByPoints, mob.Health); } - } } } |
