1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
namespace MundusTests.DataTests.SuperLayers
{
using System.Linq;
using Mundus.Data.SuperLayers;
using Mundus.Data.SuperLayers.DBTables;
using NUnit.Framework;
[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");
}
}
}
|