Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
annotate API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs @ 138:11faab6c712a
Re #140: Add equality methods
* Add equality method tests for RequiresAtLeastNUnitsRequirement
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 26 Apr 2011 19:14:34 +0000 |
parents | 7fa4d5215afe |
children | 2ae80631ec9c |
rev | line source |
---|---|
138 | 1 // This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard |
102 | 2 // |
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. | |
4 using System; | |
138 | 5 using NUnit.Framework; |
6 using IBBoard.WarFoundry.API.Objects.Mock; | |
102 | 7 using NUnit.Framework.SyntaxHelpers; |
138 | 8 using System.Reflection; |
9 using IBBoard.NUnit; | |
10 using IBBoard.WarFoundry.API.Factories; | |
102 | 11 |
107
e2ea6562ef08
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
106
diff
changeset
|
12 namespace IBBoard.WarFoundry.API.Objects.Requirement |
102 | 13 { |
14 [TestFixture()] | |
138 | 15 public class RequiresAtLeastNUnitsRequirementTest : AbstractEqualityTest<RequiresAtLeastNUnitsRequirement> |
16 { | |
17 //FIXME We shouldn't duplicate these tests, but it is broken at the moment | |
18 [Test] | |
19 public void TestEquality() | |
20 { | |
21 Assert.AreEqual(GetObject(), GetSameObject()); | |
22 Assert.AreEqual(GetSameObject(), GetObject()); | |
23 } | |
24 | |
25 [Test] | |
26 public void TestInequality() | |
27 { | |
28 Assert.AreNotEqual(GetObject(), GetDifferentObject()); | |
29 Assert.AreNotEqual(GetSameObject(), GetDifferentObject()); | |
30 Assert.AreNotEqual(GetDifferentObject(), GetObject()); | |
31 Assert.AreNotEqual(GetDifferentObject(), GetSameObject()); | |
32 } | |
33 | |
34 [Test] | |
35 public void TestReflexiveEquality() | |
36 { | |
37 Assert.AreEqual(GetObject(), GetObject()); | |
38 Assert.AreEqual(GetSameObject(), GetSameObject()); | |
39 Assert.AreEqual(GetDifferentObject(), GetDifferentObject()); | |
40 } | |
41 | |
42 [Test] | |
43 public void TestOtherInequality() | |
44 { | |
45 MethodInfo[] methodInfo = GetType().GetMethods(); | |
46 RequiresAtLeastNUnitsRequirement obj = GetObject(); | |
47 | |
48 foreach (MethodInfo method in methodInfo) | |
49 { | |
50 if (method.Name.StartsWith("GetOtherDifferent")) | |
51 { | |
52 RequiresAtLeastNUnitsRequirement otherObj = (RequiresAtLeastNUnitsRequirement)method.Invoke(this, new object[0]); | |
53 Assert.AreNotEqual(obj, otherObj, "Objects equal for "+method.Name); | |
54 Assert.AreNotEqual(otherObj, obj, "Objects equal for "+method.Name); | |
55 } | |
56 } | |
57 } | |
58 | |
59 | |
60 | |
61 | |
62 private MockRace mockRace; | |
63 private UnitType unitType1; | |
64 private UnitType unitType2; | |
65 private UnitType unitType3; | |
66 | |
67 [TestFixtureSetUp()] | |
68 public void SetupRace() | |
69 { | |
70 mockRace = MockRace.GetMockRace(); | |
71 unitType1 = new MockUnitType("type1", "Unit Type 1"); | |
72 mockRace.AddUnitType(unitType1); | |
73 unitType2 = new MockUnitType("type2", "Unit Type 2"); | |
74 mockRace.AddUnitType(unitType2); | |
75 unitType3 = new MockUnitType("type3", "Unit Type 3"); | |
76 mockRace.AddUnitType(unitType3); | |
77 } | |
103
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
78 |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
79 [Test()] |
130 | 80 public void TestAddingUnrelatedUnitWithNoUnitsAndOneUnitTypeRequired() |
138 | 81 { |
82 Army army = new Army(mockRace, "Test", 1000); | |
83 Unit unit = CreateUnitOfType(unitType1, army); | |
84 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); | |
130 | 85 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); |
138 | 86 } |
87 | |
88 [Test()] | |
89 public void TestAddingOneUnitWithOneUnitTypeRequired() | |
90 { | |
91 Army army = new Army(mockRace, "Test", 1000); | |
92 Unit unit = CreateUnitOfType(unitType1, army); | |
93 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); | |
94 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
95 } | |
96 | |
97 [Test()] | |
98 public void TestAddingUnitWithOneUnitAndTwoOfUnitTypeRequired() | |
99 { | |
100 Army army = new Army(mockRace, "Test", 1000); | |
101 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); | |
102 req.AddUnitTypeRequirement(unitType1, 2); | |
103 AddUnitOfTypeToArmy(unitType1, army); | |
104 Unit unit = CreateUnitOfType(unitType1, army); | |
105 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
106 } | |
107 | |
108 [Test()] | |
109 public void TestAddingUnrelatedUnitTypeWithNoUnitsAndOneUnitTypeRequired() | |
110 { | |
111 Army army = new Army(mockRace, "Test", 1000); | |
112 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); | |
113 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.NotApplicable)); | |
114 } | |
115 | |
116 [Test()] | |
117 public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired() | |
118 { | |
119 Army army = new Army(mockRace, "Test", 1000); | |
120 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); | |
121 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
122 } | |
123 | |
124 [Test()] | |
125 public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired() | |
126 { | |
127 Army army = new Army(mockRace, "Test", 1000); | |
128 AddUnitOfTypeToArmy(unitType1, army); | |
129 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); | |
130 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
131 } | |
132 | |
133 [Test()] | |
134 public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired() | |
135 { | |
136 Army army = new Army(mockRace, "Test", 1000); | |
137 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); | |
138 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); | |
139 } | |
140 | |
141 [Test()] | |
142 public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired() | |
143 { | |
144 Army army = new Army(mockRace, "Test", 1000); | |
145 AddUnitOfTypeToArmy(unitType3, army); | |
146 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); | |
147 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); | |
148 } | |
149 | |
150 [Test()] | |
151 public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired() | |
152 { | |
153 Army army = new Army(mockRace, "Test", 1000); | |
154 AddUnitOfTypeToArmy(unitType2, army); | |
155 AddUnitOfTypeToArmy(unitType3, army); | |
156 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); | |
157 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); | |
158 } | |
159 | |
160 [Test()] | |
161 public void TestAddingOneOfUnitTypeWithTwoOfOneUnitTypeRequired() | |
162 { | |
163 Army army = new Army(mockRace, "Test", 1000); | |
164 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); | |
165 req.AddUnitTypeRequirement(unitType1, 2); | |
166 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
167 } | |
168 | |
169 [Test()] | |
170 public void TestAddingOneUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired() | |
171 { | |
172 Army army = new Army(mockRace, "Test", 1000); | |
173 AddUnitOfTypeToArmy(unitType1, army); | |
174 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); | |
175 req.AddUnitTypeRequirement(unitType1, 2); | |
176 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
177 } | |
178 | |
179 [Test()] | |
180 public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne() | |
181 { | |
182 Army army = new Army(mockRace, "Test", 1000); | |
183 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); | |
184 req.AddUnitTypeRequirement(unitType1); | |
185 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
186 } | |
187 | |
188 [Test()] | |
189 public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired() | |
190 { | |
191 Army army = new Army(mockRace, "Test", 1000); | |
192 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); | |
193 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); | |
194 } | |
195 | |
196 [Test()] | |
197 public void TestValidityOfArmyWithOneUnitAndOneUnitTypeRequired() | |
198 { | |
199 Army army = new Army(mockRace, "Test", 1000); | |
200 AddUnitOfTypeToArmy(unitType1, army); | |
201 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); | |
202 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); | |
203 } | |
204 | |
205 [Test] | |
206 public void TestAddingMinNumberUnitTypePassesRequirement() | |
207 { | |
208 Army army = new Army(mockRace, "Test", 1000); | |
209 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); | |
210 req.AddUnitTypeRequirement(unitType1, 2); | |
211 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
212 AddUnitOfTypeToArmy(unitType1, army); | |
213 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
214 } | |
215 | |
216 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) | |
217 { | |
218 army.AddUnit(CreateUnitOfType(unitType, army)); | |
219 } | |
220 | |
221 private static Unit CreateUnitOfType(UnitType unitType, Army army) | |
222 { | |
223 return new Unit(unitType, army.GetCategory(unitType.MainCategory)); | |
106
4dad874f4862
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
105
diff
changeset
|
224 } |
4dad874f4862
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
105
diff
changeset
|
225 |
138 | 226 public override RequiresAtLeastNUnitsRequirement GetObject () |
106
4dad874f4862
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
105
diff
changeset
|
227 { |
107
e2ea6562ef08
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
106
diff
changeset
|
228 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
130 | 229 req.AddUnitTypeRequirement(unitType1, 2); |
138 | 230 return req; |
110
788ef54f5b5a
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
109
diff
changeset
|
231 } |
788ef54f5b5a
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
109
diff
changeset
|
232 |
138 | 233 public override RequiresAtLeastNUnitsRequirement GetSameObject () |
109
f5f66483032a
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
234 { |
138 | 235 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
236 req.AddUnitTypeRequirement(unitType1, 2); | |
237 return req; | |
109
f5f66483032a
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
238 } |
f5f66483032a
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
239 |
138 | 240 public override RequiresAtLeastNUnitsRequirement GetDifferentObject () |
124 | 241 { |
242 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); | |
138 | 243 DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); |
244 GameSystem gameSystem = new GameSystem("system", "system", factory); | |
245 Race race = new Race("race", "race", gameSystem, factory); | |
246 req.AddUnitTypeRequirement(new UnitType("id2", "Type 2", race), 2); | |
247 return req; | |
102 | 248 } |
249 } | |
250 } | |
251 |