Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
comparison API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs @ 190:702a0957f9e4
Re #350: Add requirement to allow N of unit for specific other units
* Add army validation tests
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 30 Nov 2011 21:05:54 +0000 |
parents | eea440e5891b |
children | 2b19d6f18f3a |
comparison
equal
deleted
inserted
replaced
189:eea440e5891b | 190:702a0957f9e4 |
---|---|
99 Unit unit = CreateUnitOfType(unitType1, army); | 99 Unit unit = CreateUnitOfType(unitType1, army); |
100 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); | 100 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); |
101 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 2 " + unitType1.Name + " (have 1 for 3).")); | 101 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 2 " + unitType1.Name + " (have 1 for 3).")); |
102 } | 102 } |
103 | 103 |
104 [Test()] | |
105 public void TestValidatingArmyWithNoUnitsAndOneUnitTypeRequiredIsNA() | |
106 { | |
107 Army army = new Army(mockRace, "Test", 1000); | |
108 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); | |
109 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable)); | |
110 Assert.That(req.GetValidationMessage(army), Is.Empty); | |
111 } | |
112 | |
113 [Test()] | |
114 public void TestValidatingArmyWithOneUnitTypeRequiredAndOneUnitOfTypePasses() | |
115 { | |
116 Army army = new Army(mockRace, "Test", 1000); | |
117 AddUnitOfTypeToArmy(unitType2, army); | |
118 AddUnitOfTypeToArmy(unitType1, army); | |
119 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); | |
120 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); | |
121 Assert.That(req.GetValidationMessage(army), Is.Empty); | |
122 } | |
123 | |
124 [Test()] | |
125 public void TestValidatingArmyWithOneUnitTypeRequiredAndNoUnitOfTypeFails() | |
126 { | |
127 Army army = new Army(mockRace, "Test", 1000); | |
128 AddUnitOfTypeToArmy(unitType1, army); | |
129 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); | |
130 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); | |
131 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (have 0 for 1).")); | |
132 } | |
133 | |
134 [Test()] | |
135 public void TestValidatingArmyWithTwoUnitsAndOneUnitTypeRequiredAndOneUnitOfTypeFails() | |
136 { | |
137 Army army = new Army(mockRace, "Test", 1000); | |
138 AddUnitOfTypeToArmy(unitType2, army); | |
139 AddUnitOfTypeToArmy(unitType1, army); | |
140 AddUnitOfTypeToArmy(unitType1, army); | |
141 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); | |
142 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); | |
143 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (have 1 for 2).")); | |
144 } | |
145 | |
146 [Test()] | |
147 public void TestValidatingArmyWithTwoUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypePasses() | |
148 { | |
149 Army army = new Army(mockRace, "Test", 1000); | |
150 AddUnitOfTypeToArmy(unitType2, army); | |
151 AddUnitOfTypeToArmy(unitType1, army); | |
152 AddUnitOfTypeToArmy(unitType1, army); | |
153 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
154 req.AddUnitTypeRequirement(unitType2, 1, 2); | |
155 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); | |
156 Assert.That(req.GetValidationMessage(army), Is.Empty); | |
157 } | |
158 | |
159 [Test()] | |
160 public void TestValidatingArmyWithThreeUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails() | |
161 { | |
162 Army army = new Army(mockRace, "Test", 1000); | |
163 AddUnitOfTypeToArmy(unitType2, army); | |
164 AddUnitOfTypeToArmy(unitType1, army); | |
165 AddUnitOfTypeToArmy(unitType1, army); | |
166 AddUnitOfTypeToArmy(unitType1, army); | |
167 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
168 req.AddUnitTypeRequirement(unitType2, 1, 2); | |
169 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); | |
170 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 2 " + unitType1.Name + " (have 1 for 3).")); | |
171 } | |
172 | |
104 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) | 173 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) |
105 { | 174 { |
106 army.AddUnit(CreateUnitOfType(unitType, army)); | 175 army.AddUnit(CreateUnitOfType(unitType, army)); |
107 } | 176 } |
108 | 177 |