Mercurial > repos > IBBoard.WarFoundry.API.Tests
annotate API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs @ 105:9163bd04a3db
Re #27: Define unit requirements
* Update method name for a more "natural language" approach of "if (req.AllowsAdding(...))"
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 27 Mar 2011 19:15:22 +0000 |
parents | 782494137b58 |
children | 4dad874f4862 |
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()] |
104
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
29 public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired() |
103
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); |
105
9163bd04a3db
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
34 Assert.That(req.AllowsAdding(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()] |
104
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
38 public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired() |
103
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); |
105
9163bd04a3db
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
44 Assert.That(req.AllowsAdding(unit, army), Is.True); |
103
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 |
104
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
47 [Test()] |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
48 public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired() |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
49 { |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
50 Army army = new Army(mockRace, "Test", 1000); |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
51 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2); |
105
9163bd04a3db
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
52 Assert.That(req.AllowsAdding(unitType1, army), Is.False); |
104
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
53 } |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
54 |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
55 [Test()] |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
56 public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired() |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
57 { |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
58 Army army = new Army(mockRace, "Test", 1000); |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
59 AddUnitOfTypeToArmy(unitType2, army); |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
60 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2); |
105
9163bd04a3db
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
61 Assert.That(req.AllowsAdding(unitType1, army), Is.True); |
104
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
62 } |
782494137b58
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
103
diff
changeset
|
63 |
103
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
64 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
65 { |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
66 army.AddUnit(CreateUnitOfType(unitType, army)); |
102 | 67 } |
103
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
68 |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
69 private static Unit CreateUnitOfType(UnitType unitType, Army army) |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
70 { |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
71 return new Unit(unitType, army.GetCategory(unitType.MainCategory)); |
c6562eb62d04
Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
72 } |
102 | 73 } |
74 } | |
75 |