diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-16 14:10:55 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-16 14:10:55 +0300 |
| commit | 65b1ad12f3874395f5abb80783c0b52ac0d4e721 (patch) | |
| tree | 053c23318f7d1b698660479f556f362674148b97 /MundusTests/DataTests | |
| parent | fe663e73be099a06bb5c164d543e86fcb953d0d0 (diff) | |
| download | Mundus-65b1ad12f3874395f5abb80783c0b52ac0d4e721.tar Mundus-65b1ad12f3874395f5abb80783c0b52ac0d4e721.tar.gz Mundus-65b1ad12f3874395f5abb80783c0b52ac0d4e721.zip | |
Started working on view layer tests and did a bit of restructuring.
Diffstat (limited to 'MundusTests/DataTests')
6 files changed, 545 insertions, 0 deletions
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"); + } + } +} |
