Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
annotate API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs @ 188:0762766bd3f2
Re #350: Add requirement to allow N of unit for specific other units
* Remove static access to mock race - it broke tests
* Add first tests for new requirement
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 29 Nov 2011 20:56:34 +0000 |
parents | 8c519a44e699 |
children | c323770e61c2 |
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 private MockRace mockRace; | |
18 private UnitType unitType1; | |
19 private UnitType unitType2; | |
20 private UnitType unitType3; | |
21 | |
22 [TestFixtureSetUp()] | |
23 public void SetupRace() | |
24 { | |
188
0762766bd3f2
Re #350: Add requirement to allow N of unit for specific other units
IBBoard <dev@ibboard.co.uk>
parents:
146
diff
changeset
|
25 mockRace = new MockRace(); |
138 | 26 unitType1 = new MockUnitType("type1", "Unit Type 1"); |
27 mockRace.AddUnitType(unitType1); | |
28 unitType2 = new MockUnitType("type2", "Unit Type 2"); | |
29 mockRace.AddUnitType(unitType2); | |
30 unitType3 = new MockUnitType("type3", "Unit Type 3"); | |
31 mockRace.AddUnitType(unitType3); | |
32 } | |
103
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
33 |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
34 [Test()] |
130 | 35 public void TestAddingUnrelatedUnitWithNoUnitsAndOneUnitTypeRequired() |
138 | 36 { |
37 Army army = new Army(mockRace, "Test", 1000); | |
38 Unit unit = CreateUnitOfType(unitType1, army); | |
39 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); | |
130 | 40 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); |
138 | 41 } |
42 | |
43 [Test()] | |
44 public void TestAddingOneUnitWithOneUnitTypeRequired() | |
45 { | |
46 Army army = new Army(mockRace, "Test", 1000); | |
47 Unit unit = CreateUnitOfType(unitType1, army); | |
48 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); | |
49 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
50 } | |
51 | |
52 [Test()] | |
53 public void TestAddingUnitWithOneUnitAndTwoOfUnitTypeRequired() | |
54 { | |
55 Army army = new Army(mockRace, "Test", 1000); | |
56 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); | |
57 req.AddUnitTypeRequirement(unitType1, 2); | |
58 AddUnitOfTypeToArmy(unitType1, army); | |
59 Unit unit = CreateUnitOfType(unitType1, army); | |
60 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
61 } | |
62 | |
63 [Test()] | |
64 public void TestAddingUnrelatedUnitTypeWithNoUnitsAndOneUnitTypeRequired() | |
65 { | |
66 Army army = new Army(mockRace, "Test", 1000); | |
67 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); | |
68 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.NotApplicable)); | |
69 } | |
70 | |
71 [Test()] | |
72 public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired() | |
73 { | |
74 Army army = new Army(mockRace, "Test", 1000); | |
75 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); | |
76 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
77 } | |
78 | |
79 [Test()] | |
80 public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired() | |
81 { | |
82 Army army = new Army(mockRace, "Test", 1000); | |
83 AddUnitOfTypeToArmy(unitType1, army); | |
84 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); | |
85 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
86 } | |
87 | |
88 [Test()] | |
89 public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired() | |
90 { | |
91 Army army = new Army(mockRace, "Test", 1000); | |
92 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); | |
93 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); | |
94 } | |
95 | |
96 [Test()] | |
97 public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired() | |
98 { | |
99 Army army = new Army(mockRace, "Test", 1000); | |
100 AddUnitOfTypeToArmy(unitType3, army); | |
101 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); | |
102 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); | |
103 } | |
104 | |
105 [Test()] | |
106 public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired() | |
107 { | |
108 Army army = new Army(mockRace, "Test", 1000); | |
109 AddUnitOfTypeToArmy(unitType2, army); | |
110 AddUnitOfTypeToArmy(unitType3, army); | |
111 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); | |
112 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); | |
113 } | |
114 | |
115 [Test()] | |
116 public void TestAddingOneOfUnitTypeWithTwoOfOneUnitTypeRequired() | |
117 { | |
118 Army army = new Army(mockRace, "Test", 1000); | |
119 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); | |
120 req.AddUnitTypeRequirement(unitType1, 2); | |
121 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); | |
122 } | |
123 | |
124 [Test()] | |
125 public void TestAddingOneUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired() | |
126 { | |
127 Army army = new Army(mockRace, "Test", 1000); | |
128 AddUnitOfTypeToArmy(unitType1, army); | |
129 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); | |
130 req.AddUnitTypeRequirement(unitType1, 2); | |
131 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
132 } | |
133 | |
134 [Test()] | |
135 public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne() | |
136 { | |
137 Army army = new Army(mockRace, "Test", 1000); | |
138 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); | |
139 req.AddUnitTypeRequirement(unitType1); | |
140 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
141 } | |
142 | |
143 [Test()] | |
144 public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired() | |
145 { | |
146 Army army = new Army(mockRace, "Test", 1000); | |
147 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); | |
148 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); | |
149 } | |
150 | |
151 [Test()] | |
152 public void TestValidityOfArmyWithOneUnitAndOneUnitTypeRequired() | |
153 { | |
154 Army army = new Army(mockRace, "Test", 1000); | |
155 AddUnitOfTypeToArmy(unitType1, army); | |
156 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); | |
157 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); | |
158 } | |
159 | |
160 [Test] | |
161 public void TestAddingMinNumberUnitTypePassesRequirement() | |
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 AddUnitOfTypeToArmy(unitType1, army); | |
168 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); | |
169 } | |
170 | |
141
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
171 [Test] |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
172 public void TestValidationMessageIsBlankForPass() |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
173 { |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
174 Army army = new Army(mockRace, "Test", 1000); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
175 AddUnitOfTypeToArmy(unitType1, army); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
176 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
177 Assert.That(req.GetValidationMessage(army), Is.Empty); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
178 } |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
179 |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
180 [Test] |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
181 public void TestValidationMessageIsCorrectForFailWithOneUnitRequired() |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
182 { |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
183 Army army = new Army(mockRace, "Test", 1000); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
184 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
185 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0).")); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
186 } |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
187 |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
188 [Test] |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
189 public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitRequired() |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
190 { |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
191 Army army = new Army(mockRace, "Test", 1000); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
192 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
193 req.AddUnitTypeRequirement(unitType1, 2); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
194 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 × " + unitType1.Name + " (have 0).")); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
195 } |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
196 |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
197 [Test] |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
198 public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequired() |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
199 { |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
200 Army army = new Army(mockRace, "Test", 1000); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
201 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
202 req.AddUnitTypeRequirement(unitType1); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
203 req.AddUnitTypeRequirement(unitType2); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
204 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0); 1 × " + unitType2.Name + " (have 0).")); |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
205 } |
cd95fc6400b2
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
140
diff
changeset
|
206 |
146
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
207 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
208 public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
209 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
210 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
211 AddUnitOfTypeToArmy(unitType1, army); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
212 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
213 req.AddUnitTypeRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
214 req.AddUnitTypeRequirement(unitType2); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
215 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (have 0).")); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
216 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
217 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
218 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
219 public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
220 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
221 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
222 AddUnitOfTypeToArmy(unitType2, army); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
223 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
224 req.AddUnitTypeRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
225 req.AddUnitTypeRequirement(unitType2); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
226 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0).")); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
227 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
228 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
229 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
230 public void TestAllowsAddingMessageIsBlankForPass() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
231 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
232 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
233 AddUnitOfTypeToArmy(unitType1, army); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
234 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
235 Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.Empty); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
236 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
237 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
238 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
239 public void TestAllowsAddingMessageIsCorrectForFailWithTwoOfOneUnitRequired() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
240 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
241 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
242 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
243 req.AddUnitTypeRequirement(unitType1, 2); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
244 Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 2 × " + unitType1.Name + " (would have 1).")); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
245 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
246 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
247 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
248 public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequired() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
249 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
250 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
251 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
252 req.AddUnitTypeRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
253 req.AddUnitTypeRequirement(unitType2); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
254 Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0).")); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
255 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
256 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
257 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
258 public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredOtherUnit() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
259 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
260 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
261 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
262 req.AddUnitTypeRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
263 req.AddUnitTypeRequirement(unitType2); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
264 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (would have 0).")); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
265 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
266 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
267 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
268 public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
269 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
270 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
271 AddUnitOfTypeToArmy(unitType1, army); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
272 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
273 req.AddUnitTypeRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
274 req.AddUnitTypeRequirement(unitType2); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
275 Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0).")); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
276 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
277 |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
278 [Test] |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
279 public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit() |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
280 { |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
281 Army army = new Army(mockRace, "Test", 1000); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
282 AddUnitOfTypeToArmy(unitType2, army); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
283 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
284 req.AddUnitTypeRequirement(unitType1); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
285 req.AddUnitTypeRequirement(unitType2); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
286 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (would have 0).")); |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
287 } |
8c519a44e699
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
141
diff
changeset
|
288 |
138 | 289 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) |
290 { | |
291 army.AddUnit(CreateUnitOfType(unitType, army)); | |
292 } | |
293 | |
294 private static Unit CreateUnitOfType(UnitType unitType, Army army) | |
295 { | |
296 return new Unit(unitType, army.GetCategory(unitType.MainCategory)); | |
106
4dad874f4862
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
105
diff
changeset
|
297 } |
4dad874f4862
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
105
diff
changeset
|
298 |
138 | 299 public override RequiresAtLeastNUnitsRequirement GetObject () |
106
4dad874f4862
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
105
diff
changeset
|
300 { |
107
e2ea6562ef08
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
106
diff
changeset
|
301 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
130 | 302 req.AddUnitTypeRequirement(unitType1, 2); |
138 | 303 return req; |
110
788ef54f5b5a
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
109
diff
changeset
|
304 } |
788ef54f5b5a
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
109
diff
changeset
|
305 |
138 | 306 public override RequiresAtLeastNUnitsRequirement GetSameObject () |
109
f5f66483032a
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
307 { |
138 | 308 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); |
309 req.AddUnitTypeRequirement(unitType1, 2); | |
310 return req; | |
109
f5f66483032a
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
311 } |
f5f66483032a
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
312 |
138 | 313 public override RequiresAtLeastNUnitsRequirement GetDifferentObject () |
124 | 314 { |
315 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); | |
138 | 316 DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); |
317 GameSystem gameSystem = new GameSystem("system", "system", factory); | |
318 Race race = new Race("race", "race", gameSystem, factory); | |
319 req.AddUnitTypeRequirement(new UnitType("id2", "Type 2", race), 2); | |
320 return req; | |
102 | 321 } |
322 } | |
323 } | |
324 |