From 65b1ad12f3874395f5abb80783c0b52ac0d4e721 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 16 May 2020 14:10:55 +0300 Subject: Started working on view layer tests and did a bit of restructuring. --- Mundus.sln | 6 + Mundus/Data/Crafting/CraftingTableContext.cs | 4 +- Mundus/Data/SuperLayers/Mobs/MI.cs | 27 --- Mundus/Data/Tiles/Mobs/LandMobsPresets.cs | 42 +++++ Mundus/Data/Tiles/Mobs/MI.cs | 27 +++ Mundus/Data/Tiles/Presets/GroundPresets.cs | 36 ++++ Mundus/Data/Tiles/Presets/MaterialPresets.cs | 38 ++++ Mundus/Data/Tiles/Presets/StructurePresets.cs | 45 +++++ Mundus/Data/Tiles/Presets/ToolPresets.cs | 64 +++++++ Mundus/Mundus.csproj | 19 +- Mundus/Service/GameGenerator.cs | 2 +- .../Generators/LandSuperLayerGenerator.cs | 5 +- .../Generators/SkySuperLayerGenerator.cs | 2 +- .../Generators/UndergroundSuperLayerGenerator.cs | 2 +- Mundus/Service/SuperLayers/ImageController.cs | 2 +- .../Service/Tiles/Crafting/CraftingController.cs | 4 +- Mundus/Service/Tiles/Items/ItemController.cs | 2 +- .../Service/Tiles/Items/Presets/GroundPresets.cs | 37 ---- .../Service/Tiles/Items/Presets/MaterialPresets.cs | 38 ---- .../Tiles/Items/Presets/StructurePresets.cs | 45 ----- Mundus/Service/Tiles/Items/Presets/ToolPresets.cs | 64 ------- .../Service/Tiles/Mobs/Controllers/MobFighting.cs | 3 +- .../Service/Tiles/Mobs/Controllers/MobMovement.cs | 4 +- .../Tiles/Mobs/Controllers/MobStatsController.cs | 4 +- .../Tiles/Mobs/Controllers/MobTerraforming.cs | 4 +- Mundus/Service/Tiles/Mobs/Inventory.cs | 8 +- .../Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs | 42 ----- Mundus/Service/Windows/Calculate.cs | 4 +- .../Crafting/CraftingTableContextTests.cs | 20 +++ .../GameEventLogs/GameEventLogContextTests.cs | 50 ++++++ .../DataTests/GameEventLogs/GameEventLogTests.cs | 16 ++ .../DataTests/SuperLayers/LandContextTests.cs | 153 ++++++++++++++++ .../DataTests/SuperLayers/SkyContextTests.cs | 153 ++++++++++++++++ .../SuperLayers/UndergroundContextTests.cs | 153 ++++++++++++++++ MundusTests/MundusTests.csproj | 198 +++++++++++++++++++++ MundusTests/packages.config | 44 +++++ 36 files changed, 1080 insertions(+), 287 deletions(-) delete mode 100644 Mundus/Data/SuperLayers/Mobs/MI.cs create mode 100644 Mundus/Data/Tiles/Mobs/LandMobsPresets.cs create mode 100644 Mundus/Data/Tiles/Mobs/MI.cs create mode 100644 Mundus/Data/Tiles/Presets/GroundPresets.cs create mode 100644 Mundus/Data/Tiles/Presets/MaterialPresets.cs create mode 100644 Mundus/Data/Tiles/Presets/StructurePresets.cs create mode 100644 Mundus/Data/Tiles/Presets/ToolPresets.cs delete mode 100644 Mundus/Service/Tiles/Items/Presets/GroundPresets.cs delete mode 100644 Mundus/Service/Tiles/Items/Presets/MaterialPresets.cs delete mode 100644 Mundus/Service/Tiles/Items/Presets/StructurePresets.cs delete mode 100644 Mundus/Service/Tiles/Items/Presets/ToolPresets.cs delete mode 100644 Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs create mode 100644 MundusTests/DataTests/Crafting/CraftingTableContextTests.cs create mode 100644 MundusTests/DataTests/GameEventLogs/GameEventLogContextTests.cs create mode 100644 MundusTests/DataTests/GameEventLogs/GameEventLogTests.cs create mode 100644 MundusTests/DataTests/SuperLayers/LandContextTests.cs create mode 100644 MundusTests/DataTests/SuperLayers/SkyContextTests.cs create mode 100644 MundusTests/DataTests/SuperLayers/UndergroundContextTests.cs create mode 100644 MundusTests/MundusTests.csproj create mode 100644 MundusTests/packages.config diff --git a/Mundus.sln b/Mundus.sln index f48c6c9..9293391 100644 --- a/Mundus.sln +++ b/Mundus.sln @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mundus", "Mundus\Mundus.csproj", "{BED2FBB2-55AC-430D-8126-E75C726DF53D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MundusTests", "MundusTests\MundusTests.csproj", "{F2107038-D6F0-4E37-85E2-287A8C1B3006}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -13,5 +15,9 @@ Global {BED2FBB2-55AC-430D-8126-E75C726DF53D}.Debug|x86.Build.0 = Debug|x86 {BED2FBB2-55AC-430D-8126-E75C726DF53D}.Release|x86.ActiveCfg = Release|x86 {BED2FBB2-55AC-430D-8126-E75C726DF53D}.Release|x86.Build.0 = Release|x86 + {F2107038-D6F0-4E37-85E2-287A8C1B3006}.Debug|x86.ActiveCfg = Debug|Any CPU + {F2107038-D6F0-4E37-85E2-287A8C1B3006}.Debug|x86.Build.0 = Debug|Any CPU + {F2107038-D6F0-4E37-85E2-287A8C1B3006}.Release|x86.ActiveCfg = Release|Any CPU + {F2107038-D6F0-4E37-85E2-287A8C1B3006}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Mundus/Data/Crafting/CraftingTableContext.cs b/Mundus/Data/Crafting/CraftingTableContext.cs index d7ea2d6..820c018 100644 --- a/Mundus/Data/Crafting/CraftingTableContext.cs +++ b/Mundus/Data/Crafting/CraftingTableContext.cs @@ -2,9 +2,9 @@ { using System.Linq; using Microsoft.EntityFrameworkCore; - using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.Tiles.Mobs; + using Mundus.Data.Tiles.Presets; using Mundus.Service.Tiles.Crafting; - using Mundus.Service.Tiles.Items.Presets; /// /// Context for getting the crafting recipes diff --git a/Mundus/Data/SuperLayers/Mobs/MI.cs b/Mundus/Data/SuperLayers/Mobs/MI.cs deleted file mode 100644 index 0a805f8..0000000 --- a/Mundus/Data/SuperLayers/Mobs/MI.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Mundus.Data.Superlayers.Mobs -{ - using Mundus.Service.Tiles.Items.Presets; - using Mundus.Service.Tiles.Mobs.LandMobs; - - /// - /// Used to store universally accessed mob instances (player) - /// - public static class MI - { - /// - /// Gets the mob that is used by the person who plays the game - /// - public static Player Player { get; private set; } - - /// - /// Creates the instances of the universally accessed mobs. - /// Note: player has a health of 4 * inventorySize and gets a wooden axe and a wooden pickaxe - /// - public static void CreateInstances() - { - Player = new Player("player", 5, DataBaseContexts.LContext); - Player.Inventory.AppendToHotbar(ToolPresets.GetAWoodenAxe()); - Player.Inventory.AppendToHotbar(ToolPresets.GetAWoodenPickaxe()); - } - } -} diff --git a/Mundus/Data/Tiles/Mobs/LandMobsPresets.cs b/Mundus/Data/Tiles/Mobs/LandMobsPresets.cs new file mode 100644 index 0000000..7f9edfd --- /dev/null +++ b/Mundus/Data/Tiles/Mobs/LandMobsPresets.cs @@ -0,0 +1,42 @@ +namespace Mundus.Data.Tiles.Mobs +{ + using Mundus.Data; + using Mundus.Data.Tiles.Presets; + using Mundus.Service.Tiles.Mobs; + + public static class LandMobsPresets + { + private static MobTile cow = new MobTile("L_cow", 10, 1, DataBaseContexts.LContext, 1, MaterialPresets.GetALandBeefSteak()); + + private static MobTile sheep = new MobTile("L_sheep", 8, 1, DataBaseContexts.LContext, 1, MaterialPresets.GetALandMuttonSteak()); + + /// + /// Returns a (static) cow MobTile. + /// Do not modify! + /// + public static MobTile GetCow() + { + return cow; + } + + /// + /// Returns a (static) sheep MobTile. + /// Do not modify! + /// + public static MobTile GetSheep() + { + return sheep; + } + + public static MobTile GetFromStock(string stock_id) + { + switch (stock_id) + { + case "L_cow": return GetCow(); + case "L_sheep": return GetSheep(); + case "player": return MI.Player; + default: return null; + } + } + } +} diff --git a/Mundus/Data/Tiles/Mobs/MI.cs b/Mundus/Data/Tiles/Mobs/MI.cs new file mode 100644 index 0000000..8bfa50a --- /dev/null +++ b/Mundus/Data/Tiles/Mobs/MI.cs @@ -0,0 +1,27 @@ +namespace Mundus.Data.Tiles.Mobs +{ + using Mundus.Data.Tiles.Presets; + using Mundus.Service.Tiles.Mobs.LandMobs; + + /// + /// Used to store universally accessed mob instances (player) + /// + public static class MI + { + /// + /// Gets the mob that is used by the person who plays the game + /// + public static Player Player { get; private set; } + + /// + /// Creates the instances of the universally accessed mobs. + /// Note: player has a health of 4 * inventorySize and gets a wooden axe and a wooden pickaxe + /// + public static void CreateInstances() + { + Player = new Player("player", 5, DataBaseContexts.LContext); + Player.Inventory.AppendToHotbar(ToolPresets.GetAWoodenAxe()); + Player.Inventory.AppendToHotbar(ToolPresets.GetAWoodenPickaxe()); + } + } +} diff --git a/Mundus/Data/Tiles/Presets/GroundPresets.cs b/Mundus/Data/Tiles/Presets/GroundPresets.cs new file mode 100644 index 0000000..ac9f422 --- /dev/null +++ b/Mundus/Data/Tiles/Presets/GroundPresets.cs @@ -0,0 +1,36 @@ +namespace Mundus.Data.Tiles.Presets +{ + using Mundus.Service.Tiles.Items.Types; + + public static class GroundPresets + { + private static GroundTile sSky = new GroundTile("S_sky", -1, false); + private static GroundTile lGrass = new GroundTile("L_grass", 1); + private static GroundTile uRoche = new GroundTile("U_roche", 10); + + public static GroundTile GetSSky() + { + return sSky; + } + + public static GroundTile GetLGrass() + { + return lGrass; + } + + public static GroundTile GetURoche() { + return uRoche; + } + + public static GroundTile GetFromStock(string stock_id) + { + switch (stock_id) + { + case "S_sky": return GetSSky(); + case "L_grass": return GetLGrass(); + case "U_roche": return GetURoche(); + default: return null; + } + } + } +} diff --git a/Mundus/Data/Tiles/Presets/MaterialPresets.cs b/Mundus/Data/Tiles/Presets/MaterialPresets.cs new file mode 100644 index 0000000..7298e8f --- /dev/null +++ b/Mundus/Data/Tiles/Presets/MaterialPresets.cs @@ -0,0 +1,38 @@ +namespace Mundus.Data.Tiles.Presets +{ + using Mundus.Service.Tiles.Items.Types; + + public static class MaterialPresets + { + /// New instance + public static Material GetALandRock() + { + return new Material("L_rock"); + } + + /// New instance + public static Material GetALandStick() + { + return new Material("L_stick"); + } + + /// New instance + public static Material GetALandBeefSteak() + { + return new Material("L_beef_steak", 5); + } + + // New instance + public static Material GetALandMuttonSteak() + { + return new Material("L_mutton_steak", 4); + } + + /// + /// TEMPORARY + /// + public static Material GetAStone() { + return new Material("U_stone"); + } + } +} diff --git a/Mundus/Data/Tiles/Presets/StructurePresets.cs b/Mundus/Data/Tiles/Presets/StructurePresets.cs new file mode 100644 index 0000000..28bad22 --- /dev/null +++ b/Mundus/Data/Tiles/Presets/StructurePresets.cs @@ -0,0 +1,45 @@ +namespace Mundus.Data.Tiles.Presets +{ + using Mundus.Service.Tiles.Items.Types; + using static Mundus.Data.Values; + + public static class StructurePresets + { + private static Structure lBoulder = new Structure("L_boulder", "L_boulder_inventory", 7, ToolType.Pickaxe, 1, false, false, MaterialPresets.GetALandRock()); + private static Structure lTree = new Structure("L_tree", "L_tree_inventory", 5, ToolType.Axe, 1, false, false, MaterialPresets.GetALandStick()); + private static Structure uRock = new Structure("U_rock", "U_rock", 10, ToolType.Pickaxe, 2, false, false, MaterialPresets.GetAStone()); + + public static Structure GetLBoulder() + { + return lBoulder; + } + + public static Structure GetLTree() + { + return lTree; + } + + public static Structure GetURock() + { + return uRock; + } + + public static Structure GetAWoodenLadder() + { + return new Structure("L_wooden_ladder", "L_wooden_ladder_inventory", 1, ToolType.Axe, 1, true, true); + } + + public static Structure GetFromStock(string stock_id) + { + switch (stock_id) + { + case "L_boulder": return GetLBoulder(); + case "L_tree": return GetLTree(); + case "U_rock": return GetURock(); + case "L_wooden_ladder_inventory": + case "L_wooden_ladder": return GetAWoodenLadder(); + default: return null; + } + } + } +} diff --git a/Mundus/Data/Tiles/Presets/ToolPresets.cs b/Mundus/Data/Tiles/Presets/ToolPresets.cs new file mode 100644 index 0000000..9c62201 --- /dev/null +++ b/Mundus/Data/Tiles/Presets/ToolPresets.cs @@ -0,0 +1,64 @@ +namespace Mundus.Data.Tiles.Presets +{ + using Mundus.Service.Tiles.Items.Types; + using static Mundus.Data.Values; + + public static class ToolPresets + { + public static Tool GetAWoodenPickaxe() + { + return new Tool("wooden_pickaxe", ToolType.Pickaxe, 1); + } + + public static Tool GetAWoodenAxe() + { + return new Tool("wooden_axe", ToolType.Axe, 1); + } + + public static Tool GetAWoodenShovel() + { + return new Tool("wooden_shovel", ToolType.Shovel, 1); + } + + public static Tool GetAWoodenLongsword() + { + return new Tool("wooden_longsword", ToolType.Sword, 2); + } + + public static Tool GetARockPickaxe() + { + return new Tool("rock_pickaxe", ToolType.Pickaxe, 2); + } + + public static Tool GetARockAxe() + { + return new Tool("rock_axe", ToolType.Axe, 2); + } + + public static Tool GetARockShovel() + { + return new Tool("rock_shovel", ToolType.Shovel, 2); + } + + public static Tool GetARockLongsword() + { + return new Tool("rock_longsword", ToolType.Sword, 4); + } + + public static Tool GetFromStock(string stock_id) + { + switch (stock_id) + { + case "wooden_pickaxe": return GetAWoodenPickaxe(); + case "wooden_axe": return GetAWoodenAxe(); + case "wooden_shovel": return GetAWoodenShovel(); + case "wooden_longsword": return GetAWoodenLongsword(); + case "rock_pickaxe": return GetARockPickaxe(); + case "rock_axe": return GetARockAxe(); + case "rock_shovel": return GetARockShovel(); + case "rock_longsword": return GetARockLongsword(); + default: return null; + } + } + } +} diff --git a/Mundus/Mundus.csproj b/Mundus/Mundus.csproj index ec15c2d..fd4f66d 100644 --- a/Mundus/Mundus.csproj +++ b/Mundus/Mundus.csproj @@ -267,7 +267,6 @@ - @@ -280,16 +279,11 @@ - - - - - @@ -326,12 +320,18 @@ + - + + + + + + @@ -345,7 +345,6 @@ - @@ -353,7 +352,6 @@ - @@ -362,7 +360,10 @@ + + + diff --git a/Mundus/Service/GameGenerator.cs b/Mundus/Service/GameGenerator.cs index 13d43ca..a2038cd 100644 --- a/Mundus/Service/GameGenerator.cs +++ b/Mundus/Service/GameGenerator.cs @@ -2,7 +2,7 @@ { using System; using Mundus.Data; - using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.Tiles.Mobs; using Mundus.Data.Windows; using Mundus.Service.SuperLayers.Generators; diff --git a/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs b/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs index f259ab6..b99cc20 100644 --- a/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs +++ b/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs @@ -2,10 +2,9 @@ { using System; using Mundus.Data; - using Mundus.Data.Superlayers.Mobs; using Mundus.Data.SuperLayers; - using Mundus.Service.Tiles.Items.Presets; - using Mundus.Service.Tiles.Mobs.LandMobs; + using Mundus.Data.Tiles.Mobs; + using Mundus.Data.Tiles.Presets; using static Mundus.Data.Values; /// diff --git a/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs b/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs index c16db26..790dbfa 100644 --- a/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs +++ b/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs @@ -3,7 +3,7 @@ using System; using Mundus.Data; using Mundus.Data.SuperLayers; - using Mundus.Service.Tiles.Items.Presets; + using Mundus.Data.Tiles.Presets; using static Mundus.Data.Values; /// diff --git a/Mundus/Service/SuperLayers/Generators/UndergroundSuperLayerGenerator.cs b/Mundus/Service/SuperLayers/Generators/UndergroundSuperLayerGenerator.cs index 807533f..f4eca86 100644 --- a/Mundus/Service/SuperLayers/Generators/UndergroundSuperLayerGenerator.cs +++ b/Mundus/Service/SuperLayers/Generators/UndergroundSuperLayerGenerator.cs @@ -3,7 +3,7 @@ using System; using Mundus.Data; using Mundus.Data.SuperLayers; - using Mundus.Service.Tiles.Items.Presets; + using Mundus.Data.Tiles.Presets; using static Mundus.Data.Values; /// diff --git a/Mundus/Service/SuperLayers/ImageController.cs b/Mundus/Service/SuperLayers/ImageController.cs index b501091..d5a2bae 100644 --- a/Mundus/Service/SuperLayers/ImageController.cs +++ b/Mundus/Service/SuperLayers/ImageController.cs @@ -2,8 +2,8 @@ { using Gtk; using Mundus.Data; - using Mundus.Data.Superlayers.Mobs; using Mundus.Data.SuperLayers; + using Mundus.Data.Tiles.Mobs; using Mundus.Service.Tiles.Items.Types; using static Mundus.Service.Tiles.Mobs.Inventory; diff --git a/Mundus/Service/Tiles/Crafting/CraftingController.cs b/Mundus/Service/Tiles/Crafting/CraftingController.cs index 4fe0279..ffd31db 100644 --- a/Mundus/Service/Tiles/Crafting/CraftingController.cs +++ b/Mundus/Service/Tiles/Crafting/CraftingController.cs @@ -2,9 +2,9 @@ { using System.Linq; using Mundus.Data; - using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.Tiles.Mobs; + using Mundus.Data.Tiles.Presets; using Mundus.Service.Tiles.Items; - using Mundus.Service.Tiles.Items.Presets; using Mundus.Service.Tiles.Mobs; public static class CraftingController diff --git a/Mundus/Service/Tiles/Items/ItemController.cs b/Mundus/Service/Tiles/Items/ItemController.cs index 172b622..17debc9 100644 --- a/Mundus/Service/Tiles/Items/ItemController.cs +++ b/Mundus/Service/Tiles/Items/ItemController.cs @@ -1,6 +1,6 @@ namespace Mundus.Service.Tiles.Items { - using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.Tiles.Mobs; using Mundus.Data.Windows; using Mundus.Service.Tiles.Items.Types; using static Mundus.Service.Tiles.Mobs.Inventory; diff --git a/Mundus/Service/Tiles/Items/Presets/GroundPresets.cs b/Mundus/Service/Tiles/Items/Presets/GroundPresets.cs deleted file mode 100644 index f763309..0000000 --- a/Mundus/Service/Tiles/Items/Presets/GroundPresets.cs +++ /dev/null @@ -1,37 +0,0 @@ - -namespace Mundus.Service.Tiles.Items.Presets -{ - using Mundus.Service.Tiles.Items.Types; - - public static class GroundPresets - { - private static GroundTile sSky = new GroundTile("S_sky", -1, false); - private static GroundTile lGrass = new GroundTile("L_grass", 1); - private static GroundTile uRoche = new GroundTile("U_roche", 10); - - public static GroundTile GetSSky() - { - return sSky; - } - - public static GroundTile GetLGrass() - { - return lGrass; - } - - public static GroundTile GetURoche() { - return uRoche; - } - - public static GroundTile GetFromStock(string stock_id) - { - switch (stock_id) - { - case "S_sky": return GetSSky(); - case "L_grass": return GetLGrass(); - case "U_roche": return GetURoche(); - default: return null; - } - } - } -} diff --git a/Mundus/Service/Tiles/Items/Presets/MaterialPresets.cs b/Mundus/Service/Tiles/Items/Presets/MaterialPresets.cs deleted file mode 100644 index 9b5ac1e..0000000 --- a/Mundus/Service/Tiles/Items/Presets/MaterialPresets.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace Mundus.Service.Tiles.Items.Presets -{ - using Mundus.Service.Tiles.Items.Types; - - public static class MaterialPresets - { - /// New instance - public static Material GetALandRock() - { - return new Material("L_rock"); - } - - /// New instance - public static Material GetALandStick() - { - return new Material("L_stick"); - } - - /// New instance - public static Material GetALandBeefSteak() - { - return new Material("L_beef_steak", 5); - } - - // New instance - public static Material GetALandMuttonSteak() - { - return new Material("L_mutton_steak", 4); - } - - /// - /// TEMPORARY - /// - public static Material GetAStone() { - return new Material("U_stone"); - } - } -} diff --git a/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs b/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs deleted file mode 100644 index b16a952..0000000 --- a/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace Mundus.Service.Tiles.Items.Presets -{ - using Mundus.Service.Tiles.Items.Types; - using static Mundus.Data.Values; - - public static class StructurePresets - { - private static Structure lBoulder = new Structure("L_boulder", "L_boulder_inventory", 7, ToolType.Pickaxe, 1, false, false, MaterialPresets.GetALandRock()); - private static Structure lTree = new Structure("L_tree", "L_tree_inventory", 5, ToolType.Axe, 1, false, false, MaterialPresets.GetALandStick()); - private static Structure uRock = new Structure("U_rock", "U_rock", 10, ToolType.Pickaxe, 2, false, false, MaterialPresets.GetAStone()); - - public static Structure GetLBoulder() - { - return lBoulder; - } - - public static Structure GetLTree() - { - return lTree; - } - - public static Structure GetURock() - { - return uRock; - } - - public static Structure GetAWoodenLadder() - { - return new Structure("L_wooden_ladder", "L_wooden_ladder_inventory", 1, ToolType.Axe, 1, true, true); - } - - public static Structure GetFromStock(string stock_id) - { - switch (stock_id) - { - case "L_boulder": return GetLBoulder(); - case "L_tree": return GetLTree(); - case "U_rock": return GetURock(); - case "L_wooden_ladder_inventory": - case "L_wooden_ladder": return GetAWoodenLadder(); - default: return null; - } - } - } -} diff --git a/Mundus/Service/Tiles/Items/Presets/ToolPresets.cs b/Mundus/Service/Tiles/Items/Presets/ToolPresets.cs deleted file mode 100644 index 04d6798..0000000 --- a/Mundus/Service/Tiles/Items/Presets/ToolPresets.cs +++ /dev/null @@ -1,64 +0,0 @@ -namespace Mundus.Service.Tiles.Items.Presets -{ - using Mundus.Service.Tiles.Items.Types; - using static Mundus.Data.Values; - - public static class ToolPresets - { - public static Tool GetAWoodenPickaxe() - { - return new Tool("wooden_pickaxe", ToolType.Pickaxe, 1); - } - - public static Tool GetAWoodenAxe() - { - return new Tool("wooden_axe", ToolType.Axe, 1); - } - - public static Tool GetAWoodenShovel() - { - return new Tool("wooden_shovel", ToolType.Shovel, 1); - } - - public static Tool GetAWoodenLongsword() - { - return new Tool("wooden_longsword", ToolType.Sword, 2); - } - - public static Tool GetARockPickaxe() - { - return new Tool("rock_pickaxe", ToolType.Pickaxe, 2); - } - - public static Tool GetARockAxe() - { - return new Tool("rock_axe", ToolType.Axe, 2); - } - - public static Tool GetARockShovel() - { - return new Tool("rock_shovel", ToolType.Shovel, 2); - } - - public static Tool GetARockLongsword() - { - return new Tool("rock_longsword", ToolType.Sword, 4); - } - - public static Tool GetFromStock(string stock_id) - { - switch (stock_id) - { - case "wooden_pickaxe": return GetAWoodenPickaxe(); - case "wooden_axe": return GetAWoodenAxe(); - case "wooden_shovel": return GetAWoodenShovel(); - case "wooden_longsword": return GetAWoodenLongsword(); - case "rock_pickaxe": return GetARockPickaxe(); - case "rock_axe": return GetARockAxe(); - case "rock_shovel": return GetARockShovel(); - case "rock_longsword": return GetARockLongsword(); - default: return null; - } - } - } -} diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs index d1e8744..a903218 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs @@ -3,9 +3,8 @@ using System; using System.Linq; using Mundus.Data; - using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.Tiles.Mobs; using Mundus.Service.Tiles.Items.Types; - using Mundus.Service.Tiles.Mobs.LandMobs; using static Mundus.Data.Values; public static class MobFighting diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs index 0e63928..c5ed2ac 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs @@ -2,9 +2,9 @@ { using System; using Mundus.Data; - using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.Tiles.Mobs; + using Mundus.Data.Tiles.Presets; using Mundus.Service.SuperLayers; - using Mundus.Service.Tiles.Items.Presets; using Mundus.Service.Tiles.Mobs.LandMobs; using static Mundus.Data.Values; diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs index 13140b2..d431ba8 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs @@ -1,8 +1,8 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { - using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.Tiles.Mobs; + using Mundus.Data.Tiles.Presets; using Mundus.Service.SuperLayers; - using Mundus.Service.Tiles.Items.Presets; public static class MobStatsController { diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs index f85a142..fa70f34 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs @@ -2,10 +2,10 @@ { using System.Linq; using Mundus.Data; - using Mundus.Data.Superlayers.Mobs; using Mundus.Data.SuperLayers; + using Mundus.Data.Tiles.Mobs; + using Mundus.Data.Tiles.Presets; using Mundus.Service.SuperLayers; - using Mundus.Service.Tiles.Items.Presets; using Mundus.Service.Tiles.Items.Types; using static Mundus.Data.Values; diff --git a/Mundus/Service/Tiles/Mobs/Inventory.cs b/Mundus/Service/Tiles/Mobs/Inventory.cs index 358666e..b97a0cc 100644 --- a/Mundus/Service/Tiles/Mobs/Inventory.cs +++ b/Mundus/Service/Tiles/Mobs/Inventory.cs @@ -2,6 +2,7 @@ { using System; using System.Linq; + using Mundus.Data.Tiles.Mobs; using Mundus.Service.Tiles.Items; using Mundus.Service.Tiles.Items.Types; @@ -32,7 +33,8 @@ this.SetSizes(screenInvSize); } - public enum InventoryPlace { + public enum InventoryPlace + { Hotbar, Items, Accessories, @@ -143,7 +145,7 @@ /// public static void DeletePlayerItemTileFromItemSelection() { - Data.Superlayers.Mobs.MI.Player.Inventory.DeleteItem(ItemController.SelItemPlace, ItemController.SelItemIndex); + MI.Player.Inventory.DeleteItem(ItemController.SelItemPlace, ItemController.SelItemIndex); } /// @@ -152,7 +154,7 @@ /// public static ItemTile GetPlayerItemFromItemSelection() { - return Data.Superlayers.Mobs.MI.Player.Inventory.GetItemTile(ItemController.SelItemPlace, ItemController.SelItemIndex); + return MI.Player.Inventory.GetItemTile(ItemController.SelItemPlace, ItemController.SelItemIndex); } } } \ No newline at end of file diff --git a/Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs b/Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs deleted file mode 100644 index e19cf7c..0000000 --- a/Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs +++ /dev/null @@ -1,42 +0,0 @@ -namespace Mundus.Service.Tiles.Mobs.LandMobs -{ - using Mundus.Data; - using Mundus.Data.Superlayers.Mobs; - using Mundus.Service.Tiles.Items.Presets; - - public static class LandMobsPresets - { - private static MobTile cow = new MobTile("L_cow", 10, 1, DataBaseContexts.LContext, 1, MaterialPresets.GetALandBeefSteak()); - - private static MobTile sheep = new MobTile("L_sheep", 8, 1, DataBaseContexts.LContext, 1, MaterialPresets.GetALandMuttonSteak()); - - /// - /// Returns a (static) cow MobTile. - /// Do not modify! - /// - public static MobTile GetCow() - { - return cow; - } - - /// - /// Returns a (static) sheep MobTile. - /// Do not modify! - /// - public static MobTile GetSheep() - { - return sheep; - } - - public static MobTile GetFromStock(string stock_id) - { - switch (stock_id) - { - case "L_cow": return GetCow(); - case "L_sheep": return GetSheep(); - case "player": return MI.Player; - default: return null; - } - } - } -} diff --git a/Mundus/Service/Windows/Calculate.cs b/Mundus/Service/Windows/Calculate.cs index 55220ec..8bc1823 100644 --- a/Mundus/Service/Windows/Calculate.cs +++ b/Mundus/Service/Windows/Calculate.cs @@ -2,8 +2,8 @@ { using System; using Mundus.Data; - using Mundus.Data.Superlayers.Mobs; - + using Mundus.Data.Tiles.Mobs; + /// /// Used to calculate values, related to the buttons on the game windows /// diff --git a/MundusTests/DataTests/Crafting/CraftingTableContextTests.cs b/MundusTests/DataTests/Crafting/CraftingTableContextTests.cs new file mode 100644 index 0000000..224e250 --- /dev/null +++ b/MundusTests/DataTests/Crafting/CraftingTableContextTests.cs @@ -0,0 +1,20 @@ +using System; +using System.Linq; +using Mundus.Data.Crafting; +using Mundus.Data.Superlayers.Mobs; +using Mundus.Data.Windows; +using Mundus.Service; +using Mundus.Service.Tiles.Mobs.LandMobs; +using NUnit.Framework; + +namespace MundusTests.DataTests.Crafting { + [TestFixture] + public static class CraftingTableContextTests { + [Test] + public static void AddsRecipesUponInitialization() { + CraftingTableContext craftingTC = new CraftingTableContext(); + + Assert.Less(0, craftingTC.CraftingRecipes.Count(), "CraftingTableContext doesn't add any recipes upon initialization"); + } + } +} diff --git a/MundusTests/DataTests/GameEventLogs/GameEventLogContextTests.cs b/MundusTests/DataTests/GameEventLogs/GameEventLogContextTests.cs new file mode 100644 index 0000000..c801c7d --- /dev/null +++ b/MundusTests/DataTests/GameEventLogs/GameEventLogContextTests.cs @@ -0,0 +1,50 @@ +using System.Linq; +using Mundus.Data.GameEventLogs; +using NUnit.Framework; + +namespace MundusTests.DataTests.GameEventLogs { + [TestFixture] + public static class GameEventLogContextTests { + [Test] + public static void TableGetsResetOnInitialization() { + GameEventLogContext gelc = new GameEventLogContext(); + + Assert.AreEqual(0, gelc.GameEventLogs.Count(), "GameEventLogContext doesn't remove all values from table after being initialized."); + } + + [Test] + [TestCase("Test message one.", "Test message two.")] + public static void AddsMessageToTable(string message1, string message2) { + GameEventLogContext gelc = new GameEventLogContext(); + + gelc.AddMessage(message1); + gelc.AddMessage(message2); + + Assert.AreEqual(message1, gelc.GetMessage(1), "First message isn't properly added or can't get it from table."); + Assert.AreEqual(message2, gelc.GetMessage(2), "Second message isn't properly added or can't get it from table."); + } + + [Test] + [TestCase("Test message 1.", "Test message 2.")] + public static void AddsMessagesToTable(string message1, string message2) { + GameEventLogContext gelc = new GameEventLogContext(); + + gelc.AddMessage(message1); + gelc.AddMessage(message2); + + Assert.AreEqual(message1, gelc.GameEventLogs.Find(1).Message, "Didn't get the first message"); + Assert.AreEqual(message2, gelc.GameEventLogs.Find(2).Message, "Didn't get the second message"); + } + + [Test] + [TestCase("Test message 1.", "Test message 2.")] + public static void CountsProperAmmountOfMessages(string message1, string message2) { + GameEventLogContext gelc = new GameEventLogContext(); + + gelc.AddMessage(message1); + gelc.AddMessage(message2); + + Assert.AreEqual(2, gelc.GetCount(), "Count of messages is wrong"); + } + } +} diff --git a/MundusTests/DataTests/GameEventLogs/GameEventLogTests.cs b/MundusTests/DataTests/GameEventLogs/GameEventLogTests.cs new file mode 100644 index 0000000..b6d75cd --- /dev/null +++ b/MundusTests/DataTests/GameEventLogs/GameEventLogTests.cs @@ -0,0 +1,16 @@ +using System; +using Mundus.Data.GameEventLogs; +using NUnit.Framework; + +namespace MundusTests.DataTests.GameEventLogs { + [TestFixture] + public static class GameEventLogTests { + [Test] + [TestCase("Testing message")] + public static void InitializesWithProperMessageValue(string message) { + GameEventLog log = new GameEventLog(message); + + Assert.AreEqual(message, log.Message, "GameEventLog doesn't properly set message on initialization"); + } + } +} diff --git a/MundusTests/DataTests/SuperLayers/LandContextTests.cs b/MundusTests/DataTests/SuperLayers/LandContextTests.cs new file mode 100644 index 0000000..f083841 --- /dev/null +++ b/MundusTests/DataTests/SuperLayers/LandContextTests.cs @@ -0,0 +1,153 @@ +using System; +using System.Linq; +using Mundus.Data.SuperLayers; +using Mundus.Data.SuperLayers.DBTables; +using NUnit.Framework; + +namespace MundusTests.DataTests.SuperLayers { + [TestFixture] + public static class LandContextTests { + [Test] + public static void AddsCorrectValues() { + var mob = new LMPlacedTile("mob_stock", 0, 1, 1); + var structure = new LSPlacedTile("structure_stock", 0, 2, 1); + var ground = new LGPlacedTile("ground_stock", 3, 4); + + LandContext lc = new LandContext(); + + lc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + lc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + lc.AddGroundAtPosition(ground.stock_id, ground.YPos, ground.XPos); + lc.SaveChanges(); + + Assert.AreEqual(mob.stock_id, lc.GetMobLayerStock(mob.YPos, mob.XPos), "Didn't add the mob correctly"); + Assert.AreEqual(structure.stock_id, lc.GetStructureLayerStock(structure.YPos, structure.XPos), "Didn't add the structure correctly"); + Assert.AreEqual(ground.stock_id, lc.GetGroundLayerStock(ground.YPos, ground.XPos), "Didn't add the ground correctly"); + } + + [Test] + public static void ConsideredAliveAfterSmallDamage() { + var mob = new LMPlacedTile("mob_stock", 10, 1, 1); + var structure = new LSPlacedTile("structure_stock", 4, 2, 1); + + LandContext lc = new LandContext(); + + lc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + lc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + lc.SaveChanges(); + + Assert.IsTrue(lc.TakeDamageMobAtPosition(mob.YPos, mob.XPos, 3), "Mob is considered dead (health <= 0), but it shouldnt be"); + Assert.IsTrue(lc.TakeDamageStructureAtPosition(structure.YPos, structure.XPos, 2), "Structure is considered dead (health <= 0), but it shouldn't be"); + } + + [Test] + public static void ConsideredDeadAfterBigDamage() { + var mob = new LMPlacedTile("mob_stock", 10, 1, 1); + var structure = new LSPlacedTile("structure_stock", 4, 2, 1); + + LandContext lc = new LandContext(); + + lc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + lc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + lc.SaveChanges(); + + Assert.IsFalse(lc.TakeDamageMobAtPosition(mob.YPos, mob.XPos, 20), "Mob is considered alive (health > 0), but it shouldnt be"); + Assert.IsFalse(lc.TakeDamageStructureAtPosition(structure.YPos, structure.XPos, 20), "Structure is considered alive (health > 0), but it shouldn't be"); + } + + [Test] + public static void DamagesCorrectly() { + var mob = new LMPlacedTile("mob_stock", 10, 1, 1); + var structure = new LSPlacedTile("structure_stock", 4, 2, 1); + + LandContext lc = new LandContext(); + + lc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + lc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + lc.SaveChanges(); + + lc.TakeDamageMobAtPosition(mob.YPos, mob.XPos, 3); + lc.TakeDamageStructureAtPosition(structure.YPos, structure.XPos, 1); + + Assert.AreEqual(7, lc.LMobLayer.First(x => x.YPos == mob.YPos && x.XPos == mob.XPos).Health, "Mobs recieve incorrect amount of damage"); + Assert.AreEqual(3, lc.LStructureLayer.First(x => x.YPos == structure.YPos && x.XPos == structure.XPos).Health, "Structures recieve incorrect amount of damage"); + } + + [Test] + public static void GetsCorrectStocks() { + var mob = new LMPlacedTile("mob_stock", 0, 1, 1); + var structure = new LSPlacedTile("structure_stock", 0, 2, 1); + var ground = new LGPlacedTile("ground_stock", 3, 4); + + LandContext lc = new LandContext(); + + lc.LMobLayer.Add(mob); + lc.LStructureLayer.Add(structure); + lc.LGroundLayer.Add(ground); + lc.SaveChanges(); + + Assert.AreEqual(mob.stock_id, lc.GetMobLayerStock(mob.YPos, mob.XPos), "Doesn't get the correct mob layer stock"); + Assert.AreEqual(structure.stock_id, lc.GetStructureLayerStock(structure.YPos,structure.XPos), "Doesn't get the correct structure layer stock"); + Assert.AreEqual(ground.stock_id, lc.GetGroundLayerStock(ground.YPos, ground.XPos), "Doesn't get the correct ground layer stock"); + } + + [Test] + public static void RemovesCorrectValues() { + var mob = new LMPlacedTile("mob_stock", 0, 1, 1); + var structure = new LSPlacedTile("structure_stock", 0, 2, 1); + var ground = new LGPlacedTile("ground_stock", 3, 4); + + LandContext lc = new LandContext(); + + lc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + lc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + lc.AddGroundAtPosition(ground.stock_id, ground.YPos, ground.XPos); + lc.SaveChanges(); + + lc.RemoveMobFromPosition(mob.YPos, mob.XPos); + lc.RemoveStructureFromPosition(structure.YPos, structure.XPos); + lc.RemoveGroundFromPosition(ground.YPos, ground.XPos); + lc.SaveChanges(); + + Assert.AreEqual(null, lc.GetMobLayerStock(mob.YPos, mob.XPos), "Didn't remove the mob correctly"); + Assert.AreEqual(null, lc.GetStructureLayerStock(structure.YPos, structure.XPos), "Didn't remove the structure correctly"); + Assert.AreEqual(null, lc.GetGroundLayerStock(ground.YPos, ground.XPos), "Didn't remove the ground correctly"); + } + + + [Test] + public static void SetsCorrectValues() { + var mob = new LMPlacedTile("mob_stock", 0, 1, 1); + var newMob = new LMPlacedTile("new_mob_stock", 1, 1, 1); + var structure = new LSPlacedTile("structure_stock", 0, 2, 1); + var newStructure = new LSPlacedTile("new_structure_stock", 1, 2, 1); + var ground = new LGPlacedTile("ground_stock", 3, 4); + var newGround = new LGPlacedTile("new_ground_stock", 3, 4); + + LandContext lc = new LandContext(); + + lc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + lc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + lc.AddGroundAtPosition(ground.stock_id, ground.YPos, ground.XPos); + lc.SaveChanges(); + + lc.SetMobAtPosition(newMob.stock_id, newMob.Health, newMob.YPos, newMob.XPos); + lc.SetStructureAtPosition(newStructure.stock_id, newStructure.Health, newStructure.YPos, newStructure.XPos); + lc.SetGroundAtPosition(newGround.stock_id, newGround.YPos, newGround.XPos); + lc.SaveChanges(); + + Assert.AreEqual(newMob.stock_id, lc.GetMobLayerStock(mob.YPos, mob.XPos), "Didn't set the mob correctly"); + Assert.AreEqual(newStructure.stock_id, lc.GetStructureLayerStock(structure.YPos, structure.XPos), "Didn't set the structure correctly"); + Assert.AreEqual(newGround.stock_id, lc.GetGroundLayerStock(ground.YPos, ground.XPos), "Didn't set the ground correctly"); + } + + [Test] + public static void TruncatesTablesOnInitialization() { + LandContext lc = new LandContext(); + + Assert.AreEqual(0, lc.LMobLayer.Count(), "LMobLayer table isn't properly truncated upon LandContext initialization"); + Assert.AreEqual(0, lc.LStructureLayer.Count(), "LStructureLayer table isn't properly truncated upon LandContext initialization"); + Assert.AreEqual(0, lc.LGroundLayer.Count(), "LGroungLayer table isn't properly truncated upon LandContext initialization"); + } + } +} diff --git a/MundusTests/DataTests/SuperLayers/SkyContextTests.cs b/MundusTests/DataTests/SuperLayers/SkyContextTests.cs new file mode 100644 index 0000000..91a05b2 --- /dev/null +++ b/MundusTests/DataTests/SuperLayers/SkyContextTests.cs @@ -0,0 +1,153 @@ +using System; +using System.Linq; +using Mundus.Data.SuperLayers; +using Mundus.Data.SuperLayers.DBTables; +using NUnit.Framework; + +namespace MundusTests.DataTests.SuperLayers { + [TestFixture] + public static class SkyContextTests { + [Test] + public static void AddsCorrectValues() { + var mob = new SMPlacedTile("mob_stock", 0, 1, 1); + var structure = new SSPlacedTile("structure_stock", 0, 2, 1); + var ground = new SGPlacedTile("ground_stock", 3, 4); + + SkyContext sc = new SkyContext(); + + sc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + sc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + sc.AddGroundAtPosition(ground.stock_id, ground.YPos, ground.XPos); + sc.SaveChanges(); + + Assert.AreEqual(mob.stock_id, sc.GetMobLayerStock(mob.YPos, mob.XPos), "Didn't add the mob correctly"); + Assert.AreEqual(structure.stock_id, sc.GetStructureLayerStock(structure.YPos, structure.XPos), "Didn't add the structure correctly"); + Assert.AreEqual(ground.stock_id, sc.GetGroundLayerStock(ground.YPos, ground.XPos), "Didn't add the ground correctly"); + } + + [Test] + public static void ConsideredAliveAfterSmallDamage() { + var mob = new SMPlacedTile("mob_stock", 10, 1, 1); + var structure = new SSPlacedTile("structure_stock", 4, 2, 1); + + SkyContext sc = new SkyContext(); + + sc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + sc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + sc.SaveChanges(); + + Assert.IsTrue(sc.TakeDamageMobAtPosition(mob.YPos, mob.XPos, 3), "Mob is considered dead (health <= 0), but it shouldnt be"); + Assert.IsTrue(sc.TakeDamageStructureAtPosition(structure.YPos, structure.XPos, 2), "Structure is considered dead (health <= 0), but it shouldn't be"); + } + + [Test] + public static void ConsideredDeadAfterBigDamage() { + var mob = new SMPlacedTile("mob_stock", 10, 1, 1); + var structure = new SSPlacedTile("structure_stock", 4, 2, 1); + + SkyContext sc = new SkyContext(); + + sc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + sc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + sc.SaveChanges(); + + Assert.IsFalse(sc.TakeDamageMobAtPosition(mob.YPos, mob.XPos, 20), "Mob is considered alive (health > 0), but it shouldnt be"); + Assert.IsFalse(sc.TakeDamageStructureAtPosition(structure.YPos, structure.XPos, 20), "Structure is considered alive (health > 0), but it shouldn't be"); + } + + [Test] + public static void DamagesCorrectly() { + var mob = new SMPlacedTile("mob_stock", 10, 1, 1); + var structure = new SSPlacedTile("structure_stock", 4, 2, 1); + + SkyContext sc = new SkyContext(); + + sc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + sc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + sc.SaveChanges(); + + sc.TakeDamageMobAtPosition(mob.YPos, mob.XPos, 3); + sc.TakeDamageStructureAtPosition(structure.YPos, structure.XPos, 1); + + Assert.AreEqual(7, sc.SMobLayer.First(x => x.YPos == mob.YPos && x.XPos == mob.XPos).Health, "Mobs recieve incorrect amount of damage"); + Assert.AreEqual(3, sc.SStructureLayer.First(x => x.YPos == structure.YPos && x.XPos == structure.XPos).Health, "Structures recieve incorrect amount of damage"); + } + + [Test] + public static void GetsCorrectStocks() { + var mob = new SMPlacedTile("mob_stock", 0, 1, 1); + var structure = new SSPlacedTile("structure_stock", 0, 2, 1); + var ground = new SGPlacedTile("ground_stock", 3, 4); + + SkyContext sc = new SkyContext(); + + sc.SMobLayer.Add(mob); + sc.SStructureLayer.Add(structure); + sc.SGroundLayer.Add(ground); + sc.SaveChanges(); + + Assert.AreEqual(mob.stock_id, sc.GetMobLayerStock(mob.YPos, mob.XPos), "Doesn't get the correct mob layer stock"); + Assert.AreEqual(structure.stock_id, sc.GetStructureLayerStock(structure.YPos, structure.XPos), "Doesn't get the correct structure layer stock"); + Assert.AreEqual(ground.stock_id, sc.GetGroundLayerStock(ground.YPos, ground.XPos), "Doesn't get the correct ground layer stock"); + } + + [Test] + public static void RemovesCorrectValues() { + var mob = new SMPlacedTile("mob_stock", 0, 1, 1); + var structure = new SSPlacedTile("structure_stock", 0, 2, 1); + var ground = new SGPlacedTile("ground_stock", 3, 4); + + SkyContext sc = new SkyContext(); + + sc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + sc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + sc.AddGroundAtPosition(ground.stock_id, ground.YPos, ground.XPos); + sc.SaveChanges(); + + sc.RemoveMobFromPosition(mob.YPos, mob.XPos); + sc.RemoveStructureFromPosition(structure.YPos, structure.XPos); + sc.RemoveGroundFromPosition(ground.YPos, ground.XPos); + sc.SaveChanges(); + + Assert.AreEqual(null, sc.GetMobLayerStock(mob.YPos, mob.XPos), "Didn't remove the mob correctly"); + Assert.AreEqual(null, sc.GetStructureLayerStock(structure.YPos, structure.XPos), "Didn't remove the structure correctly"); + Assert.AreEqual(null, sc.GetGroundLayerStock(ground.YPos, ground.XPos), "Didn't remove the ground correctly"); + } + + + [Test] + public static void SetsCorrectValues() { + var mob = new SMPlacedTile("mob_stock", 0, 1, 1); + var newMob = new SMPlacedTile("new_mob_stock", 1, 1, 1); + var structure = new SSPlacedTile("structure_stock", 0, 2, 1); + var newStructure = new SSPlacedTile("new_structure_stock", 1, 2, 1); + var ground = new SGPlacedTile("ground_stock", 3, 4); + var newGround = new SGPlacedTile("new_ground_stock", 3, 4); + + SkyContext sc = new SkyContext(); + + sc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + sc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + sc.AddGroundAtPosition(ground.stock_id, ground.YPos, ground.XPos); + sc.SaveChanges(); + + sc.SetMobAtPosition(newMob.stock_id, newMob.Health, newMob.YPos, newMob.XPos); + sc.SetStructureAtPosition(newStructure.stock_id, newStructure.Health, newStructure.YPos, newStructure.XPos); + sc.SetGroundAtPosition(newGround.stock_id, newGround.YPos, newGround.XPos); + sc.SaveChanges(); + + Assert.AreEqual(newMob.stock_id, sc.GetMobLayerStock(mob.YPos, mob.XPos), "Didn't set the mob correctly"); + Assert.AreEqual(newStructure.stock_id, sc.GetStructureLayerStock(structure.YPos, structure.XPos), "Didn't set the structure correctly"); + Assert.AreEqual(newGround.stock_id, sc.GetGroundLayerStock(ground.YPos, ground.XPos), "Didn't set the ground correctly"); + } + + [Test] + public static void TruncatesTablesOnInitialization() { + SkyContext sc = new SkyContext(); + + Assert.AreEqual(0, sc.SMobLayer.Count(), "SMobLayer table isn't properly truncated upon SkyContext initialization"); + Assert.AreEqual(0, sc.SStructureLayer.Count(), "SStructureLayer table isn't properly truncated upon SkyContext initialization"); + Assert.AreEqual(0, sc.SGroundLayer.Count(), "LGroungLayer table isn't properly truncated upon SkyContext initialization"); + } + } +} diff --git a/MundusTests/DataTests/SuperLayers/UndergroundContextTests.cs b/MundusTests/DataTests/SuperLayers/UndergroundContextTests.cs new file mode 100644 index 0000000..98d7679 --- /dev/null +++ b/MundusTests/DataTests/SuperLayers/UndergroundContextTests.cs @@ -0,0 +1,153 @@ +using System; +using System.Linq; +using Mundus.Data.SuperLayers; +using Mundus.Data.SuperLayers.DBTables; +using NUnit.Framework; + +namespace MundusTests.DataTests.SuperLayers { + [TestFixture] + public static class UndergroundContextTests { + [Test] + public static void AddsCorrectValues() { + var mob = new UMPlacedTile("mob_stock", 0, 1, 1); + var structure = new USPlacedTile("structure_stock", 0, 2, 1); + var ground = new UGPlacedTile("ground_stock", 3, 4); + + UndergroundContext uc = new UndergroundContext(); + + uc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + uc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + uc.AddGroundAtPosition(ground.stock_id, ground.YPos, ground.XPos); + uc.SaveChanges(); + + Assert.AreEqual(mob.stock_id, uc.GetMobLayerStock(mob.YPos, mob.XPos), "Didn't add the mob correctly"); + Assert.AreEqual(structure.stock_id, uc.GetStructureLayerStock(structure.YPos, structure.XPos), "Didn't add the structure correctly"); + Assert.AreEqual(ground.stock_id, uc.GetGroundLayerStock(ground.YPos, ground.XPos), "Didn't add the ground correctly"); + } + + [Test] + public static void ConsideredAliveAfterSmallDamage() { + var mob = new UMPlacedTile("mob_stock", 10, 1, 1); + var structure = new USPlacedTile("structure_stock", 4, 2, 1); + + UndergroundContext uc = new UndergroundContext(); + + uc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + uc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + uc.SaveChanges(); + + Assert.IsTrue(uc.TakeDamageMobAtPosition(mob.YPos, mob.XPos, 3), "Mob is considered dead (health <= 0), but it shouldnt be"); + Assert.IsTrue(uc.TakeDamageStructureAtPosition(structure.YPos, structure.XPos, 2), "Structure is considered dead (health <= 0), but it shouldn't be"); + } + + [Test] + public static void ConsideredDeadAfterBigDamage() { + var mob = new UMPlacedTile("mob_stock", 10, 1, 1); + var structure = new USPlacedTile("structure_stock", 4, 2, 1); + + UndergroundContext uc = new UndergroundContext(); + + uc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + uc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + uc.SaveChanges(); + + Assert.IsFalse(uc.TakeDamageMobAtPosition(mob.YPos, mob.XPos, 20), "Mob is considered alive (health > 0), but it shouldnt be"); + Assert.IsFalse(uc.TakeDamageStructureAtPosition(structure.YPos, structure.XPos, 20), "Structure is considered alive (health > 0), but it shouldn't be"); + } + + [Test] + public static void DamagesCorrectly() { + var mob = new UMPlacedTile("mob_stock", 10, 1, 1); + var structure = new USPlacedTile("structure_stock", 4, 2, 1); + + UndergroundContext uc = new UndergroundContext(); + + uc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + uc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + uc.SaveChanges(); + + uc.TakeDamageMobAtPosition(mob.YPos, mob.XPos, 3); + uc.TakeDamageStructureAtPosition(structure.YPos, structure.XPos, 1); + + Assert.AreEqual(7, uc.UMobLayer.First(x => x.YPos == mob.YPos && x.XPos == mob.XPos).Health, "Mobs recieve incorrect amount of damage"); + Assert.AreEqual(3, uc.UStructureLayer.First(x => x.YPos == structure.YPos && x.XPos == structure.XPos).Health, "Structures recieve incorrect amount of damage"); + } + + [Test] + public static void GetsCorrectStocks() { + var mob = new UMPlacedTile("mob_stock", 0, 1, 1); + var structure = new USPlacedTile("structure_stock", 0, 2, 1); + var ground = new UGPlacedTile("ground_stock", 3, 4); + + UndergroundContext uc = new UndergroundContext(); + + uc.UMobLayer.Add(mob); + uc.UStructureLayer.Add(structure); + uc.UGroundLayer.Add(ground); + uc.SaveChanges(); + + Assert.AreEqual(mob.stock_id, uc.GetMobLayerStock(mob.YPos, mob.XPos), "Doesn't get the correct mob layer stock"); + Assert.AreEqual(structure.stock_id, uc.GetStructureLayerStock(structure.YPos, structure.XPos), "Doesn't get the correct structure layer stock"); + Assert.AreEqual(ground.stock_id, uc.GetGroundLayerStock(ground.YPos, ground.XPos), "Doesn't get the correct ground layer stock"); + } + + [Test] + public static void RemovesCorrectValues() { + var mob = new UMPlacedTile("mob_stock", 0, 1, 1); + var structure = new USPlacedTile("structure_stock", 0, 2, 1); + var ground = new UGPlacedTile("ground_stock", 3, 4); + + UndergroundContext uc = new UndergroundContext(); + + uc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + uc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + uc.AddGroundAtPosition(ground.stock_id, ground.YPos, ground.XPos); + uc.SaveChanges(); + + uc.RemoveMobFromPosition(mob.YPos, mob.XPos); + uc.RemoveStructureFromPosition(structure.YPos, structure.XPos); + uc.RemoveGroundFromPosition(ground.YPos, ground.XPos); + uc.SaveChanges(); + + Assert.AreEqual(null, uc.GetMobLayerStock(mob.YPos, mob.XPos), "Didn't remove the mob correctly"); + Assert.AreEqual(null, uc.GetStructureLayerStock(structure.YPos, structure.XPos), "Didn't remove the structure correctly"); + Assert.AreEqual(null, uc.GetGroundLayerStock(ground.YPos, ground.XPos), "Didn't remove the ground correctly"); + } + + + [Test] + public static void SetsCorrectValues() { + var mob = new UMPlacedTile("mob_stock", 0, 1, 1); + var newMob = new UMPlacedTile("new_mob_stock", 1, 1, 1); + var structure = new USPlacedTile("structure_stock", 0, 2, 1); + var newStructure = new USPlacedTile("new_structure_stock", 1, 2, 1); + var ground = new UGPlacedTile("ground_stock", 3, 4); + var newGround = new UGPlacedTile("new_ground_stock", 3, 4); + + UndergroundContext uc = new UndergroundContext(); + + uc.AddMobAtPosition(mob.stock_id, mob.Health, mob.YPos, mob.XPos); + uc.AddStructureAtPosition(structure.stock_id, structure.Health, structure.YPos, structure.XPos); + uc.AddGroundAtPosition(ground.stock_id, ground.YPos, ground.XPos); + uc.SaveChanges(); + + uc.SetMobAtPosition(newMob.stock_id, newMob.Health, newMob.YPos, newMob.XPos); + uc.SetStructureAtPosition(newStructure.stock_id, newStructure.Health, newStructure.YPos, newStructure.XPos); + uc.SetGroundAtPosition(newGround.stock_id, newGround.YPos, newGround.XPos); + uc.SaveChanges(); + + Assert.AreEqual(newMob.stock_id, uc.GetMobLayerStock(mob.YPos, mob.XPos), "Didn't set the mob correctly"); + Assert.AreEqual(newStructure.stock_id, uc.GetStructureLayerStock(structure.YPos, structure.XPos), "Didn't set the structure correctly"); + Assert.AreEqual(newGround.stock_id, uc.GetGroundLayerStock(ground.YPos, ground.XPos), "Didn't set the ground correctly"); + } + + [Test] + public static void TruncatesTablesOnInitialization() { + UndergroundContext uc = new UndergroundContext(); + + Assert.AreEqual(0, uc.UMobLayer.Count(), "UMobLayer table isn't properly truncated upon UndergroundContext initialization"); + Assert.AreEqual(0, uc.UStructureLayer.Count(), "UStructureLayer table isn't properly truncated upon UndergroundContext initialization"); + Assert.AreEqual(0, uc.UGroundLayer.Count(), "LGroungLayer table isn't properly truncated upon UndergroundContext initialization"); + } + } +} diff --git a/MundusTests/MundusTests.csproj b/MundusTests/MundusTests.csproj new file mode 100644 index 0000000..75aab6b --- /dev/null +++ b/MundusTests/MundusTests.csproj @@ -0,0 +1,198 @@ + + + + Debug + AnyCPU + {F2107038-D6F0-4E37-85E2-287A8C1B3006} + Library + MundusTests + MundusTests + v4.7 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + + + true + bin\Release + prompt + 4 + + + + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + + ..\packages\Microsoft.Bcl.HashCode.1.1.0\lib\net461\Microsoft.Bcl.HashCode.dll + + + + ..\packages\Microsoft.EntityFrameworkCore.Abstractions.3.1.4\lib\netstandard2.0\Microsoft.EntityFrameworkCore.Abstractions.dll + + + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.3.1.4\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Logging.Abstractions.3.1.4\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.ComponentModel.Annotations.4.7.0\lib\net461\System.ComponentModel.Annotations.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + + ..\packages\Microsoft.Extensions.Primitives.3.1.4\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll + + + ..\packages\Microsoft.Extensions.Caching.Abstractions.3.1.4\lib\netstandard2.0\Microsoft.Extensions.Caching.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Configuration.Abstractions.3.1.4\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Configuration.3.1.4\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll + + + ..\packages\Microsoft.Extensions.Configuration.Binder.3.1.4\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll + + + ..\packages\Microsoft.Extensions.Options.3.1.4\lib\netstandard2.0\Microsoft.Extensions.Options.dll + + + ..\packages\Microsoft.Extensions.Caching.Memory.3.1.4\lib\netstandard2.0\Microsoft.Extensions.Caching.Memory.dll + + + ..\packages\System.Collections.Immutable.1.7.1\lib\net461\System.Collections.Immutable.dll + + + + ..\packages\System.Diagnostics.DiagnosticSource.4.7.1\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.1\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + + ..\packages\Microsoft.Extensions.DependencyInjection.3.1.4\lib\net461\Microsoft.Extensions.DependencyInjection.dll + + + ..\packages\Microsoft.Extensions.Logging.3.1.4\lib\netstandard2.0\Microsoft.Extensions.Logging.dll + + + ..\packages\Microsoft.EntityFrameworkCore.3.1.4\lib\netstandard2.0\Microsoft.EntityFrameworkCore.dll + + + ..\packages\CairoSharp.3.22.25.74\lib\netstandard2.0\CairoSharp.dll + + + ..\packages\GLibSharp.3.22.25.74\lib\netstandard2.0\GLibSharp.dll + + + ..\packages\AtkSharp.3.22.25.74\lib\netstandard2.0\AtkSharp.dll + + + ..\packages\GioSharp.3.22.25.74\lib\netstandard2.0\GioSharp.dll + + + ..\packages\PangoSharp.3.22.25.74\lib\netstandard2.0\PangoSharp.dll + + + ..\packages\GdkSharp.3.22.25.74\lib\netstandard2.0\GdkSharp.dll + + + ..\packages\GtkSharp.3.22.25.74\lib\netstandard2.0\GtkSharp.dll + + + + + + ..\packages\Microsoft.EntityFrameworkCore.Relational.3.1.4\lib\netstandard2.0\Microsoft.EntityFrameworkCore.Relational.dll + + + ..\packages\BouncyCastle.1.8.3.1\lib\BouncyCastle.Crypto.dll + + + ..\packages\Google.Protobuf.3.6.1\lib\net45\Google.Protobuf.dll + + + ..\packages\SSH.NET.2016.1.0\lib\net40\Renci.SshNet.dll + + + ..\packages\K4os.Compression.LZ4.1.1.11\lib\net46\K4os.Compression.LZ4.dll + + + ..\packages\K4os.Hash.xxHash.1.0.6\lib\net46\K4os.Hash.xxHash.dll + + + ..\packages\K4os.Compression.LZ4.Streams.1.1.11\lib\net46\K4os.Compression.LZ4.Streams.dll + + + ..\packages\MySql.Data.8.0.20\lib\net452\MySql.Data.dll + + + ..\packages\MySql.Data.8.0.20\lib\net452\Ubiety.Dns.Core.dll + + + ..\packages\MySql.Data.8.0.20\lib\net452\Zstandard.Net.dll + + + + + + + + + + + + + ..\packages\MySql.Data.EntityFrameworkCore.8.0.20\lib\netstandard2.0\MySql.Data.EntityFrameworkCore.dll + + + + + + + + + + + + + + + + + + + + + + {BED2FBB2-55AC-430D-8126-E75C726DF53D} + Mundus + + + + + \ No newline at end of file diff --git a/MundusTests/packages.config b/MundusTests/packages.config new file mode 100644 index 0000000..f3e0a41 --- /dev/null +++ b/MundusTests/packages.config @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3