Mercurial > repos > IBBoard.WarFoundry.API.Tests
comparison API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs @ 208:c323770e61c2
Re #379: Fix validation of requirements to check for unit
* Rename classes in tests to match API changes
* Alter tests to match new API (all classes require at least one UnitType that they're relevant to now)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 22 Feb 2012 20:48:40 +0000 |
parents | |
children | fc9a90d29ae0 |
comparison
equal
deleted
inserted
replaced
207:27f163bf884a | 208:c323770e61c2 |
---|---|
1 // This file (UnitRequiresNUnitsForMUnitsRequirementTest.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 UnitRequiresNUnitsForMUnitsRequirementTests | |
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 TestAddingUnitWithNoUnitsAndOneUnitTypeRequiredIsAllowed() | |
33 { | |
34 Army army = new Army(mockRace, "Test", 1000); | |
35 Unit unit = CreateUnitOfType(unitType1, army); | |
36 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
37 req.AddUnitTypeRequirement(unitType2); | |
38 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
39 } | |
40 | |
41 [Test()] | |
42 public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredIsNotAllowed() | |
43 { | |
44 Army army = new Army(mockRace, "Test", 1000); | |
45 AddUnitOfTypeToArmy(unitType2, army); | |
46 Unit unit = CreateUnitOfType(unitType1, army); | |
47 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
48 req.AddUnitTypeRequirement(unitType2); | |
49 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); | |
50 } | |
51 | |
52 [Test()] | |
53 public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed() | |
54 { | |
55 Army army = new Army(mockRace, "Test", 1000); | |
56 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
57 req.AddUnitTypeRequirement(unitType2); | |
58 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
59 } | |
60 | |
61 [Test()] | |
62 public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequiredIsNotAllowed() | |
63 { | |
64 Army army = new Army(mockRace, "Test", 1000); | |
65 AddUnitOfTypeToArmy(unitType2, army); | |
66 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
67 req.AddUnitTypeRequirement(unitType2); | |
68 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
69 } | |
70 | |
71 [Test()] | |
72 public void TestAddingUnitTypeSetsLimit() | |
73 { | |
74 Army army = new Army(mockRace, "Test", 1000); | |
75 AddUnitOfTypeToArmy(unitType2, army); | |
76 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
77 req.AddUnitTypeRequirement(unitType2, 1); | |
78 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
79 } | |
80 | |
81 [Test()] | |
82 public void TestAddingUnitTypeSetsLimitForFailure() | |
83 { | |
84 Army army = new Army(mockRace, "Test", 1000); | |
85 AddUnitOfTypeToArmy(unitType2, army); | |
86 AddUnitOfTypeToArmy(unitType2, army); | |
87 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
88 req.AddUnitTypeRequirement(unitType2, 1); | |
89 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
90 } | |
91 | |
92 [Test()] | |
93 public void TestAddingUnitTriggersFailure() | |
94 { | |
95 Army army = new Army(mockRace, "Test", 1000); | |
96 AddUnitOfTypeToArmy(unitType2, army); | |
97 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
98 req.AddUnitTypeRequirement(unitType2, 1); | |
99 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
100 AddUnitOfTypeToArmy(unitType2, army); | |
101 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
102 } | |
103 | |
104 [Test()] | |
105 public void TestAddingUnitTypeDefaultsToNoMoreThanZero() | |
106 { | |
107 Army army = new Army(mockRace, "Test", 1000); | |
108 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
109 req.AddUnitTypeRequirement(unitType2); | |
110 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
111 AddUnitOfTypeToArmy(unitType2, army); | |
112 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
113 } | |
114 | |
115 [Test] | |
116 public void TestRequirementNotApplicableWhenLimitedUnitNotIncluded() | |
117 { | |
118 Army army = new Army(mockRace, "Test", 1000); | |
119 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
120 req.AddUnitTypeRequirement(unitType2); | |
121 Assert.That(req.AllowsAdding(unitType3, army), Is.EqualTo(Validation.NotApplicable)); | |
122 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.NotApplicable)); | |
123 } | |
124 | |
125 [Test] | |
126 public void TestRequirementBecomesInvalidWhenProhibitedUnitsChange() | |
127 { | |
128 Army army = new Army(mockRace, "Test", 1000); | |
129 AddUnitOfTypeToArmy(unitType1, army); | |
130 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
131 req.AddUnitTypeRequirement(unitType2); | |
132 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); | |
133 AddUnitOfTypeToArmy(unitType2, army); | |
134 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); | |
135 } | |
136 | |
137 [Test()] | |
138 public void TestAddingLimitedUnitTriggersFailure() | |
139 { | |
140 Army army = new Army(mockRace, "Test", 1000); | |
141 AddUnitOfTypeToArmy(unitType1, army); | |
142 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
143 req.AddUnitTypeRequirement(unitType2); | |
144 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); | |
145 } | |
146 | |
147 [Test] | |
148 public void TestValidationMessageIsBlankForPass() | |
149 { | |
150 Army army = new Army(mockRace, "Test", 1000); | |
151 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
152 req.AddUnitTypeRequirement(unitType2); | |
153 Assert.That(req.GetValidationMessage(army), Is.Empty); | |
154 } | |
155 | |
156 [Test] | |
157 public void TestValidationMessageIsCorrectForFailWithOneUnitProhibited() | |
158 { | |
159 Army army = new Army(mockRace, "Test", 1000); | |
160 AddUnitOfTypeToArmy(unitType1, army); | |
161 AddUnitOfTypeToArmy(unitType2, army); | |
162 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
163 req.AddUnitTypeRequirement(unitType2); | |
164 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1).")); | |
165 } | |
166 | |
167 [Test] | |
168 public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitLimit() | |
169 { | |
170 Army army = new Army(mockRace, "Test", 1000); | |
171 AddUnitOfTypeToArmy(unitType1, army); | |
172 AddUnitOfTypeToArmy(unitType2, army); | |
173 AddUnitOfTypeToArmy(unitType2, army); | |
174 AddUnitOfTypeToArmy(unitType2, army); | |
175 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
176 req.AddUnitTypeRequirement(unitType2, 2); | |
177 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (have 3).")); | |
178 } | |
179 | |
180 [Test] | |
181 public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibited() | |
182 { | |
183 Army army = new Army(mockRace, "Test", 1000); | |
184 AddUnitOfTypeToArmy(unitType1, army); | |
185 AddUnitOfTypeToArmy(unitType2, army); | |
186 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
187 req.AddUnitTypeRequirement(unitType2); | |
188 req.AddUnitTypeRequirement(unitType3); | |
189 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1).")); | |
190 } | |
191 | |
192 [Test] | |
193 public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy() | |
194 { | |
195 Army army = new Army(mockRace, "Test", 1000); | |
196 AddUnitOfTypeToArmy(unitType1, army); | |
197 AddUnitOfTypeToArmy(unitType3, army); | |
198 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
199 req.AddUnitTypeRequirement(unitType2); | |
200 req.AddUnitTypeRequirement(unitType3); | |
201 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType3.Name + " (have 1).")); | |
202 } | |
203 | |
204 [Test] | |
205 public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndBothUnitsInArmy() | |
206 { | |
207 Army army = new Army(mockRace, "Test", 1000); | |
208 AddUnitOfTypeToArmy(unitType1, army); | |
209 AddUnitOfTypeToArmy(unitType2, army); | |
210 AddUnitOfTypeToArmy(unitType3, army); | |
211 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
212 req.AddUnitTypeRequirement(unitType2); | |
213 req.AddUnitTypeRequirement(unitType3); | |
214 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1); 0 × " + unitType3.Name + " (have 1).")); | |
215 } | |
216 | |
217 [Test] | |
218 public void TestAllowsAddMessageIsBlankForPass() | |
219 { | |
220 Army army = new Army(mockRace, "Test", 1000); | |
221 AddUnitOfTypeToArmy(unitType1, army); | |
222 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
223 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.Empty); | |
224 } | |
225 | |
226 [Test] | |
227 public void TestAllowsAddMessageIsCorrectForFailWithOneUnitProhibited() | |
228 { | |
229 Army army = new Army(mockRace, "Test", 1000); | |
230 AddUnitOfTypeToArmy(unitType1, army); | |
231 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
232 req.AddUnitTypeRequirement(unitType2); | |
233 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).")); | |
234 } | |
235 | |
236 [Test] | |
237 public void TestAllowsAddMessageIsCorrectForFailWithTwoOfOneUnitLimit() | |
238 { | |
239 Army army = new Army(mockRace, "Test", 1000); | |
240 AddUnitOfTypeToArmy(unitType1, army); | |
241 AddUnitOfTypeToArmy(unitType2, army); | |
242 AddUnitOfTypeToArmy(unitType2, army); | |
243 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
244 req.AddUnitTypeRequirement(unitType2, 2); | |
245 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (would have 3).")); | |
246 } | |
247 | |
248 [Test] | |
249 public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited() | |
250 { | |
251 Army army = new Army(mockRace, "Test", 1000); | |
252 AddUnitOfTypeToArmy(unitType1, army); | |
253 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
254 req.AddUnitTypeRequirement(unitType2); | |
255 req.AddUnitTypeRequirement(unitType3); | |
256 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).")); | |
257 } | |
258 | |
259 [Test] | |
260 public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy() | |
261 { | |
262 Army army = new Army(mockRace, "Test", 1000); | |
263 AddUnitOfTypeToArmy(unitType1, army); | |
264 AddUnitOfTypeToArmy(unitType2, army); | |
265 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
266 req.AddUnitTypeRequirement(unitType2); | |
267 req.AddUnitTypeRequirement(unitType3); | |
268 Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1).")); | |
269 } | |
270 | |
271 [Test] | |
272 public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy() | |
273 { | |
274 Army army = new Army(mockRace, "Test", 1000); | |
275 AddUnitOfTypeToArmy(unitType1, army); | |
276 AddUnitOfTypeToArmy(unitType3, army); | |
277 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); | |
278 req.AddUnitTypeRequirement(unitType2); | |
279 req.AddUnitTypeRequirement(unitType3); | |
280 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1).")); | |
281 } | |
282 | |
283 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) | |
284 { | |
285 army.AddUnit(CreateUnitOfType(unitType, army)); | |
286 } | |
287 | |
288 private static Unit CreateUnitOfType(UnitType unitType, Army army) | |
289 { | |
290 return new Unit(unitType, army.GetCategory(unitType.MainCategory)); | |
291 } | |
292 } | |
293 } | |
294 |