Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
annotate API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs @ 205:d39682a98adf
Re #379: Fix validation of requirements to check for unit
* Add unit tests for army object
* Update tests that check the message
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 29 Jan 2012 19:40:19 +0000 |
parents | 8c519a44e699 |
children | 27f163bf884a |
rev | line source |
---|---|
132 | 1 // This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard |
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; | |
5 using NUnit.Framework; | |
6 using IBBoard.WarFoundry.API.Objects.Mock; | |
7 using NUnit.Framework.SyntaxHelpers; | |
8 | |
9 namespace IBBoard.WarFoundry.API.Objects.Requirement | |
10 { | |
11 [TestFixture()] | |
12 public class UnitRequiresAtLeastNUnitsRequirementTest | |
13 { | |
14 private MockRace mockRace; | |
15 private UnitType unitType1; | |
16 private UnitType unitType2; | |
17 private UnitType unitType3; | |
18 | |
19 [TestFixtureSetUp()] | |
20 public void SetupRace() | |
21 { | |
22 mockRace = new MockRace(); | |
23 unitType1 = new MockUnitType("type1", "Unit Type 1"); | |
24 mockRace.AddUnitType(unitType1); | |
25 unitType2 = new MockUnitType("type2", "Unit Type 2"); | |
26 mockRace.AddUnitType(unitType2); | |
27 unitType3 = new MockUnitType("type3", "Unit Type 3"); | |
28 mockRace.AddUnitType(unitType3); | |
29 } | |
30 | |
31 [Test()] | |
32 public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired() | |
33 { | |
34 Army army = new Army(mockRace, "Test", 1000); | |
35 Unit unit = CreateUnitOfType(unitType1, army); | |
36 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
37 req.AddUnitTypeRequirement(unitType2); | |
38 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); | |
39 } | |
40 | |
41 [Test()] | |
42 public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired() | |
43 { | |
44 Army army = new Army(mockRace, "Test", 1000); | |
45 AddUnitOfTypeToArmy(unitType2, army); | |
46 Unit unit = CreateUnitOfType(unitType1, army); | |
47 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
48 req.AddUnitTypeRequirement(unitType2); | |
49 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
50 } | |
51 | |
52 [Test()] | |
53 public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired() | |
54 { | |
55 Army army = new Army(mockRace, "Test", 1000); | |
56 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
57 req.AddUnitTypeRequirement(unitType2); | |
58 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
59 } | |
60 | |
61 [Test()] | |
62 public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired() | |
63 { | |
64 Army army = new Army(mockRace, "Test", 1000); | |
65 AddUnitOfTypeToArmy(unitType2, army); | |
66 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
67 req.AddUnitTypeRequirement(unitType2); | |
68 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
69 } | |
70 | |
71 [Test()] | |
72 public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired() | |
73 { | |
74 Army army = new Army(mockRace, "Test", 1000); | |
75 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
76 req.AddUnitTypeRequirement(unitType2); | |
77 req.AddUnitTypeRequirement(unitType3); | |
78 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
79 } | |
80 | |
81 [Test()] | |
82 public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired() | |
83 { | |
84 Army army = new Army(mockRace, "Test", 1000); | |
85 AddUnitOfTypeToArmy(unitType2, army); | |
86 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
87 req.AddUnitTypeRequirement(unitType2); | |
88 req.AddUnitTypeRequirement(unitType3); | |
89 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
90 } | |
91 | |
92 [Test()] | |
93 public void TestAddingUnitTypeWithOtherOneUnitAndTwoUnitTypesRequired() | |
94 { | |
95 Army army = new Army(mockRace, "Test", 1000); | |
96 AddUnitOfTypeToArmy(unitType3, army); | |
97 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
98 req.AddUnitTypeRequirement(unitType2); | |
99 req.AddUnitTypeRequirement(unitType3); | |
100 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
101 } | |
102 | |
103 [Test()] | |
104 public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired() | |
105 { | |
106 Army army = new Army(mockRace, "Test", 1000); | |
107 AddUnitOfTypeToArmy(unitType2, army); | |
108 AddUnitOfTypeToArmy(unitType3, army); | |
109 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
110 req.AddUnitTypeRequirement(unitType2); | |
111 req.AddUnitTypeRequirement(unitType3); | |
112 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
113 } | |
114 | |
115 [Test()] | |
116 public void TestAddingUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired() | |
117 { | |
118 Army army = new Army(mockRace, "Test", 1000); | |
119 AddUnitOfTypeToArmy(unitType2, army); | |
120 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
121 req.AddUnitTypeRequirement(unitType2, 2); | |
122 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
123 } | |
124 | |
125 [Test()] | |
126 public void TestAddingUnrelatedUnitTypeIsAllowedWhenRequirementsNotMet() | |
127 { | |
128 Army army = new Army(mockRace, "Test", 1000); | |
129 AddUnitOfTypeToArmy(unitType2, army); | |
130 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
131 req.AddUnitTypeRequirement(unitType2, 2); | |
132 Assert.That(req.AllowsAdding(unitType3, army), Is.EqualTo(Validation.NotApplicable)); | |
133 } | |
134 | |
135 [Test()] | |
136 public void TestAddingUnitTypeWithTwoUnitsAndTwoOfOneUnitTypeRequired() | |
137 { | |
138 Army army = new Army(mockRace, "Test", 1000); | |
139 AddUnitOfTypeToArmy(unitType2, army); | |
140 AddUnitOfTypeToArmy(unitType2, army); | |
141 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
142 req.AddUnitTypeRequirement(unitType2, 2); | |
143 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
144 } | |
145 | |
146 [Test()] | |
147 public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne() | |
148 { | |
149 Army army = new Army(mockRace, "Test", 1000); | |
150 AddUnitOfTypeToArmy(unitType2, army); | |
151 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
152 req.AddUnitTypeRequirement(unitType2); | |
153 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
154 } | |
155 | |
156 [Test()] | |
157 public void TestAddingUnitTypeMakesRequirementPass() | |
158 { | |
159 Army army = new Army(mockRace, "Test", 1000); | |
160 AddUnitOfTypeToArmy(unitType2, army); | |
161 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
162 req.AddUnitTypeRequirement(unitType2, 2); | |
163 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
164 AddUnitOfTypeToArmy(unitType2, army); | |
165 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
166 } | |
167 | |
168 [Test()] | |
169 public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired() | |
170 { | |
171 Army army = new Army(mockRace, "Test", 1000); | |
172 AddUnitOfTypeToArmy(unitType1, army); | |
173 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
174 req.AddUnitTypeRequirement(unitType2); | |
175 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); | |
176 } | |
177 | |
178 [Test()] | |
179 public void TestValidityOfArmyWithOneUnitAndOneUnitTypeRequired() | |
180 { | |
181 Army army = new Army(mockRace, "Test", 1000); | |
182 AddUnitOfTypeToArmy(unitType2, army); | |
183 AddUnitOfTypeToArmy(unitType1, army); | |
184 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
185 req.AddUnitTypeRequirement(unitType2); | |
186 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); | |
187 } | |
188 | |
189 [Test()] | |
190 public void TestValidityOfArmyWhenNoRequireeAndRequirementNotMet() | |
191 { | |
192 Army army = new Army(mockRace, "Test", 1000); | |
193 AddUnitOfTypeToArmy(unitType2, army); | |
194 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
195 req.AddUnitTypeRequirement(unitType2, 2); | |
196 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable)); | |
197 } | |
198 | |
199 [Test] | |
200 public void TestSatisfyingRequirementChangesResult() | |
201 { | |
202 Army army = new Army(mockRace, "Test", 1000); | |
203 AddUnitOfTypeToArmy(unitType1, army); | |
204 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
205 req.AddUnitTypeRequirement(unitType2); | |
206 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); | |
207 AddUnitOfTypeToArmy(unitType2, army); | |
208 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); | |
209 } | |
210 | |
211 [Test] | |
212 public void TestAddingMinNumberUnitTypePassesRequirement() | |
213 { | |
214 Army army = new Army(mockRace, "Test", 1000); | |
215 AddUnitOfTypeToArmy(unitType1, army); | |
216 RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); | |
217 req.AddUnitTypeRequirement(unitType2, 2); | |
218 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); | |
219 AddUnitOfTypeToArmy(unitType2, army); | |
220 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); | |
221 } | |
222 | |
142
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
223 [Test] |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
224 public void TestValidationMessageIsBlankForPass() |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
225 { |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
226 Army army = new Army(mockRace, "Test", 1000); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
227 AddUnitOfTypeToArmy(unitType1, army); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
228 AddUnitOfTypeToArmy(unitType2, army); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
229 RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
230 req.AddUnitTypeRequirement(unitType2); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
231 Assert.That(req.GetValidationMessage(army), Is.Empty); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
232 } |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
233 |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
234 [Test] |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
235 public void TestValidationMessageIsCorrectForFailWithOneUnitRequired() |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
236 { |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
237 Army army = new Army(mockRace, "Test", 1000); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
238 AddUnitOfTypeToArmy(unitType1, army); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
239 RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
240 req.AddUnitTypeRequirement(unitType2); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
241 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (have 0).")); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
242 } |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
243 |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
244 [Test] |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
245 public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitRequired() |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
246 { |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
247 Army army = new Army(mockRace, "Test", 1000); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
248 AddUnitOfTypeToArmy(unitType1, army); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
249 RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
250 req.AddUnitTypeRequirement(unitType2, 2); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
251 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 2 × " + unitType2.Name + " (have 0).")); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
252 } |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
253 |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
254 [Test] |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
255 public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequired() |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
256 { |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
257 Army army = new Army(mockRace, "Test", 1000); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
258 AddUnitOfTypeToArmy(unitType1, army); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
259 RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
260 req.AddUnitTypeRequirement(unitType2); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
261 req.AddUnitTypeRequirement(unitType3); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
262 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (have 0); 1 × " + unitType3.Name + " (have 0).")); |
f36b5e5e51e6
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
132
diff
changeset
|
263 } |
132 | 264 |
146
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
265 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
266 public void TestAllowsAddingMessageIsBlankForPass() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
267 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
268 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
269 AddUnitOfTypeToArmy(unitType1, army); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
270 RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
271 Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.Empty); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
272 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
273 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
274 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
275 public void TestAllowsAddingMessageIsCorrectForFailWithTwoOfOneUnitRequired() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
276 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
277 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
278 RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
279 req.AddUnitTypeRequirement(unitType2, 2); |
205
d39682a98adf
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
146
diff
changeset
|
280 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army would contain " + unitType1.Name + " and so must contain: 2 × " + unitType2.Name + " (would have 1).")); |
146
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
281 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
282 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
283 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
284 public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequired() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
285 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
286 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
287 RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
288 req.AddUnitTypeRequirement(unitType2); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
289 req.AddUnitTypeRequirement(unitType3); |
205
d39682a98adf
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
146
diff
changeset
|
290 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army would contain " + unitType1.Name + " and so must contain: 1 × " + unitType3.Name + " (would have 0).")); |
146
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
291 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
292 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
293 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
294 public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredOtherUnit() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
295 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
296 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
297 RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
298 req.AddUnitTypeRequirement(unitType2); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
299 req.AddUnitTypeRequirement(unitType3); |
205
d39682a98adf
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
146
diff
changeset
|
300 Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army would contain " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (would have 0).")); |
146
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
301 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
302 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
303 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
304 public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
305 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
306 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
307 AddUnitOfTypeToArmy(unitType2, army); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
308 RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
309 req.AddUnitTypeRequirement(unitType2); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
310 req.AddUnitTypeRequirement(unitType3); |
205
d39682a98adf
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
146
diff
changeset
|
311 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army would contain " + unitType1.Name + " and so must contain: 1 × " + unitType3.Name + " (would have 0).")); |
146
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
312 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
313 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
314 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
315 public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
316 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
317 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
318 AddUnitOfTypeToArmy(unitType3, army); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
319 RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
320 req.AddUnitTypeRequirement(unitType2); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
321 req.AddUnitTypeRequirement(unitType3); |
205
d39682a98adf
Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
146
diff
changeset
|
322 Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army would contain " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (would have 0).")); |
146
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
323 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
142
diff
changeset
|
324 |
132 | 325 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) |
326 { | |
327 army.AddUnit(CreateUnitOfType(unitType, army)); | |
328 } | |
329 | |
330 private static Unit CreateUnitOfType(UnitType unitType, Army army) | |
331 { | |
332 return new Unit(unitType, army.GetCategory(unitType.MainCategory)); | |
333 } | |
334 } | |
335 } | |
336 |