Mercurial > repos > IBBoard.WarFoundry.API.Tests
annotate API/Objects/Requirement/RequirementHandlerTests.cs @ 146:8c519a44e699
Re #345: Add failure message to requirements
* Add testing of failure messages for "allows adding"
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 01 May 2011 19:17:11 +0000 |
parents | 0d40d80226b8 |
children |
rev | line source |
---|---|
133 | 1 // This file (RequirementHandlerTests.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 IBBoard.WarFoundry.API.Objects; | |
8 using NUnit.Framework.SyntaxHelpers; | |
9 using IBBoard.WarFoundry.API.Objects.Requirement.Mock; | |
143
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
10 using System.Collections.Generic; |
133 | 11 |
12 namespace IBBoard.WarFoundry.API.Objects.Requirement | |
13 { | |
14 [TestFixture()] | |
15 public class RequirementHandlerTests | |
16 { | |
17 [Test()] | |
18 public void TestArmyWithNoRequirementsValidates() | |
19 { | |
20 MockRace race = new MockRace(); | |
21 Army army = new Army(race, "test", 1000); | |
22 Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed)); | |
23 } | |
24 | |
25 [Test()] | |
26 public void TestArmyWithFailingRequirementFails() | |
27 { | |
28 MockRace race = new MockRace(); | |
29 MockUnitType mockUnitType = new MockUnitType(); | |
30 mockUnitType.AddRequirement(new FailingRequirement()); | |
31 race.AddUnitType(mockUnitType); | |
32 Army army = new Army(race, "test", 1000); | |
33 Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Failed)); | |
34 } | |
35 | |
36 [Test()] | |
37 public void TestArmyWithPassingRequirementPasses() | |
38 { | |
39 MockRace race = new MockRace(); | |
40 MockUnitType mockUnitType = new MockUnitType(); | |
41 mockUnitType.AddRequirement(new PassingRequirement()); | |
42 race.AddUnitType(mockUnitType); | |
43 Army army = new Army(race, "test", 1000); | |
44 Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed)); | |
45 } | |
46 | |
47 [Test()] | |
48 public void TestArmyWithNotApplicableRequirementPasses() | |
49 { | |
50 MockRace race = new MockRace(); | |
51 MockUnitType mockUnitType = new MockUnitType(); | |
52 mockUnitType.AddRequirement(new NotApplicableRequirement()); | |
53 race.AddUnitType(mockUnitType); | |
54 Army army = new Army(race, "test", 1000); | |
55 Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed)); | |
56 } | |
135 | 57 |
58 [Test()] | |
59 public void TestArmyWithMixedRequirementsWithFailFails() | |
60 { | |
61 MockRace race = new MockRace(); | |
62 MockUnitType mockUnitType = new MockUnitType(); | |
63 mockUnitType.AddRequirement(new PassingRequirement()); | |
64 mockUnitType.AddRequirement(new FailingRequirement()); | |
65 race.AddUnitType(mockUnitType); | |
66 Army army = new Army(race, "test", 1000); | |
67 Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Failed)); | |
68 } | |
69 | |
70 [Test()] | |
71 public void TestArmyWithMixedRequirementsWithFailInOtherOrderFails() | |
72 { | |
73 MockRace race = new MockRace(); | |
74 MockUnitType mockUnitType = new MockUnitType(); | |
75 mockUnitType.AddRequirement(new FailingRequirement()); | |
76 mockUnitType.AddRequirement(new PassingRequirement()); | |
77 race.AddUnitType(mockUnitType); | |
78 Army army = new Army(race, "test", 1000); | |
79 Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Failed)); | |
80 } | |
81 | |
82 [Test()] | |
83 public void TestArmyWithMixedRequirementsWithNoFailsPasses() | |
84 { | |
85 MockRace race = new MockRace(); | |
86 MockUnitType mockUnitType = new MockUnitType(); | |
87 mockUnitType.AddRequirement(new PassingRequirement()); | |
88 mockUnitType.AddRequirement(new NotApplicableRequirement()); | |
89 race.AddUnitType(mockUnitType); | |
90 Army army = new Army(race, "test", 1000); | |
91 Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed)); | |
92 } | |
93 | |
94 [Test()] | |
95 public void TestCanAddToArmyWithNoRequirementsValidates() | |
96 { | |
97 MockRace race = new MockRace(); | |
98 Army army = new Army(race, "test", 1000); | |
99 Assert.That(RequirementHandler.AllowsAdding(new MockUnitType(), army), Is.EqualTo(Validation.Passed)); | |
100 } | |
101 | |
102 [Test()] | |
103 public void TestCanAddToArmyWithFailingRequirementFails() | |
104 { | |
105 MockRace race = new MockRace(); | |
106 MockUnitType mockUnitType = new MockUnitType(); | |
107 mockUnitType.AddRequirement(new FailingRequirement()); | |
108 race.AddUnitType(mockUnitType); | |
109 Army army = new Army(race, "test", 1000); | |
110 Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Failed)); | |
111 } | |
112 | |
113 [Test()] | |
114 public void TestCanAddToArmyWithPassingRequirementPasses() | |
115 { | |
116 MockRace race = new MockRace(); | |
117 MockUnitType mockUnitType = new MockUnitType(); | |
118 mockUnitType.AddRequirement(new PassingRequirement()); | |
119 race.AddUnitType(mockUnitType); | |
120 Army army = new Army(race, "test", 1000); | |
121 Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Passed)); | |
122 } | |
123 | |
124 [Test()] | |
125 public void TestCanAddToArmyWithNotApplicableRequirementPasses() | |
126 { | |
127 MockRace race = new MockRace(); | |
128 MockUnitType mockUnitType = new MockUnitType(); | |
129 mockUnitType.AddRequirement(new NotApplicableRequirement()); | |
130 race.AddUnitType(mockUnitType); | |
131 Army army = new Army(race, "test", 1000); | |
132 Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Passed)); | |
133 } | |
134 | |
135 [Test()] | |
136 public void TestCanAddToArmyWithMixedRequirementsWithFailFails() | |
137 { | |
138 MockRace race = new MockRace(); | |
139 MockUnitType mockUnitType = new MockUnitType(); | |
140 mockUnitType.AddRequirement(new PassingRequirement()); | |
141 mockUnitType.AddRequirement(new FailingRequirement()); | |
142 race.AddUnitType(mockUnitType); | |
143 Army army = new Army(race, "test", 1000); | |
144 Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Failed)); | |
145 } | |
146 | |
147 [Test()] | |
148 public void TestCanAddToArmyWithMixedRequirementsWithFailInOtherOrderFails() | |
149 { | |
150 MockRace race = new MockRace(); | |
151 MockUnitType mockUnitType = new MockUnitType(); | |
152 mockUnitType.AddRequirement(new FailingRequirement()); | |
153 mockUnitType.AddRequirement(new PassingRequirement()); | |
154 race.AddUnitType(mockUnitType); | |
155 Army army = new Army(race, "test", 1000); | |
156 Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Failed)); | |
157 } | |
158 | |
159 [Test()] | |
160 public void TestCanAddToArmyWithMixedRequirementsWithNoFailsPasses() | |
161 { | |
162 MockRace race = new MockRace(); | |
163 MockUnitType mockUnitType = new MockUnitType(); | |
164 mockUnitType.AddRequirement(new PassingRequirement()); | |
165 mockUnitType.AddRequirement(new NotApplicableRequirement()); | |
166 race.AddUnitType(mockUnitType); | |
167 Army army = new Army(race, "test", 1000); | |
168 Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Passed)); | |
169 } | |
143
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
170 |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
171 [Test()] |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
172 public void TestArmyWithMixedRequirementsGetsExpectedFailureMessageCount() |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
173 { |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
174 MockRace race = new MockRace(); |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
175 MockUnitType mockUnitType = new MockUnitType(); |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
176 mockUnitType.AddRequirement(new PassingRequirement()); |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
177 mockUnitType.AddRequirement(new NotApplicableRequirement()); |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
178 mockUnitType.AddRequirement(new FailingRequirement()); |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
179 mockUnitType.AddRequirement(new FailingRequirement()); |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
180 race.AddUnitType(mockUnitType); |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
181 Army army = new Army(race, "test", 1000); |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
182 ICollection<string> failureMessages; |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
183 RequirementHandler.ValidateArmy(army, out failureMessages); |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
184 Assert.That(failureMessages, Has.Count(2)); |
6fdb76d48e04
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
135
diff
changeset
|
185 } |
145
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
186 |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
187 [Test()] |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
188 public void TestAddingToArmyWithMixedRequirementsGetsExpectedFailureMessageCount() |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
189 { |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
190 MockRace race = new MockRace(); |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
191 MockUnitType mockUnitType = new MockUnitType(); |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
192 mockUnitType.AddRequirement(new PassingRequirement()); |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
193 mockUnitType.AddRequirement(new NotApplicableRequirement()); |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
194 mockUnitType.AddRequirement(new FailingRequirement()); |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
195 mockUnitType.AddRequirement(new FailingRequirement()); |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
196 race.AddUnitType(mockUnitType); |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
197 Army army = new Army(race, "test", 1000); |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
198 ICollection<string> failureMessages; |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
199 RequirementHandler.AllowsAdding(mockUnitType, army, out failureMessages); |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
200 Assert.That(failureMessages, Has.Count(2)); |
0d40d80226b8
Re #33: Add centralised requirement checker
IBBoard <dev@ibboard.co.uk>
parents:
143
diff
changeset
|
201 } |
133 | 202 } |
203 } | |
204 |