view API/Objects/Requirement/RequirementHandlerTests.cs @ 143:6fdb76d48e04

Re #345: Add failure message to requirements * Test return of messages from requirement handler
author IBBoard <dev@ibboard.co.uk>
date Sun, 01 May 2011 14:45:22 +0000
parents 8c3bba80a25e
children 0d40d80226b8
line source
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;
10 using System.Collections.Generic;
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
171 [Test()]
172 public void TestArmyWithMixedRequirementsGetsExpectedFailureMessageCount()
173 {
174 MockRace race = new MockRace();
175 MockUnitType mockUnitType = new MockUnitType();
176 mockUnitType.AddRequirement(new PassingRequirement());
177 mockUnitType.AddRequirement(new NotApplicableRequirement());
178 mockUnitType.AddRequirement(new FailingRequirement());
179 mockUnitType.AddRequirement(new FailingRequirement());
180 race.AddUnitType(mockUnitType);
181 Army army = new Army(race, "test", 1000);
182 ICollection<string> failureMessages;
183 RequirementHandler.ValidateArmy(army, out failureMessages);
184 Assert.That(failureMessages, Has.Count(2));
185 }
186 }
187 }