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