Mercurial > repos > IBBoard.WarFoundry.API.Tests
annotate API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs @ 103:c6562eb62d04
Re #27: Define unit requirements
* Refactor out common code
* Simplify tests to try with one unit type required at first
* Add test where requirement is satisfied
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 26 Mar 2011 21:02:18 +0000 |
parents | a3bc8174299f |
children | 782494137b58 |
rev | line source |
---|---|
102 | 1 // This file (UnitRequiresAtLeastNUnitsRequirement.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 NUnit.Framework.SyntaxHelpers; | |
8 | |
9 namespace IBBoard.WarFoundry.API.Objects.Requirements | |
10 { | |
11 [TestFixture()] | |
12 public class UnitRequiresAtLeastNUnitsRequirementTest | |
103
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
13 { |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
14 private MockRace mockRace; |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
15 private UnitType unitType1; |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
16 private UnitType unitType2; |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
17 |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
18 [TestFixtureSetUp()] |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
19 public void SetupRace() |
102 | 20 { |
103
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
21 mockRace = MockRace.GetMockRace(); |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
22 unitType1 = new MockUnitType("type1", "Unit Type 1"); |
102 | 23 mockRace.AddUnitType(unitType1); |
103
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
24 unitType2 = new MockUnitType("type2", "Unit Type 2"); |
102 | 25 mockRace.AddUnitType(unitType2); |
103
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
26 } |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
27 |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
28 [Test()] |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
29 public void TestWithNoUnitsAndOneUnitTypeRequired() |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
30 { |
102 | 31 Army army = new Army(mockRace, "Test", 1000); |
103
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
32 Unit unit = CreateUnitOfType(unitType1, army); |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
33 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2); |
102 | 34 Assert.That(req.CanAddToArmy(unit, army), Is.False); |
103
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
35 } |
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()] |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
38 public void TestWithOneUnitAndOneUnitTypeRequired() |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
39 { |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
40 Army army = new Army(mockRace, "Test", 1000); |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
41 AddUnitOfTypeToArmy(unitType2, army); |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
42 Unit unit = CreateUnitOfType(unitType1, army); |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
43 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2); |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
44 Assert.That(req.CanAddToArmy(unit, army), Is.True); |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
45 } |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
46 |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
47 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
48 { |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
49 army.AddUnit(CreateUnitOfType(unitType, army)); |
102 | 50 } |
103
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
51 |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
52 private static Unit CreateUnitOfType(UnitType unitType, Army army) |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
53 { |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
54 return new Unit(unitType, army.GetCategory(unitType.MainCategory)); |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
55 } |
102 | 56 } |
57 } | |
58 |