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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
102
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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.
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System;
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using NUnit.Framework;
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.WarFoundry.API.Objects.Mock;
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using NUnit.Framework.SyntaxHelpers;
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 namespace IBBoard.WarFoundry.API.Objects.Requirements
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 {
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 [TestFixture()]
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 }
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 }
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58