comparison 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
comparison
equal deleted inserted replaced
102:a3bc8174299f 103:c6562eb62d04
9 namespace IBBoard.WarFoundry.API.Objects.Requirements 9 namespace IBBoard.WarFoundry.API.Objects.Requirements
10 { 10 {
11 [TestFixture()] 11 [TestFixture()]
12 public class UnitRequiresAtLeastNUnitsRequirementTest 12 public class UnitRequiresAtLeastNUnitsRequirementTest
13 { 13 {
14 private MockRace mockRace;
15 private UnitType unitType1;
16 private UnitType unitType2;
17
18 [TestFixtureSetUp()]
19 public void SetupRace()
20 {
21 mockRace = MockRace.GetMockRace();
22 unitType1 = new MockUnitType("type1", "Unit Type 1");
23 mockRace.AddUnitType(unitType1);
24 unitType2 = new MockUnitType("type2", "Unit Type 2");
25 mockRace.AddUnitType(unitType2);
26 }
27
14 [Test()] 28 [Test()]
15 public void TestWithNoUnits() 29 public void TestWithNoUnitsAndOneUnitTypeRequired()
16 { 30 {
17 MockRace mockRace = MockRace.GetMockRace();
18 UnitType unitType1 = new MockUnitType("type1", "Unit Type 1");
19 mockRace.AddUnitType(unitType1);
20 UnitType unitType2 = new MockUnitType("type2", "Unit Type 2");
21 mockRace.AddUnitType(unitType2);
22 Army army = new Army(mockRace, "Test", 1000); 31 Army army = new Army(mockRace, "Test", 1000);
23 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1, unitType2); 32 Unit unit = CreateUnitOfType(unitType1, army);
24 Unit unit = new Unit(unitType1, army.GetCategory(unitType1.MainCategory)); 33 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
25 Assert.That(req.CanAddToArmy(unit, army), Is.False); 34 Assert.That(req.CanAddToArmy(unit, army), Is.False);
35 }
36
37 [Test()]
38 public void TestWithOneUnitAndOneUnitTypeRequired()
39 {
40 Army army = new Army(mockRace, "Test", 1000);
41 AddUnitOfTypeToArmy(unitType2, army);
42 Unit unit = CreateUnitOfType(unitType1, army);
43 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
44 Assert.That(req.CanAddToArmy(unit, army), Is.True);
45 }
46
47 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
48 {
49 army.AddUnit(CreateUnitOfType(unitType, army));
50 }
51
52 private static Unit CreateUnitOfType(UnitType unitType, Army army)
53 {
54 return new Unit(unitType, army.GetCategory(unitType.MainCategory));
26 } 55 }
27 } 56 }
28 } 57 }
29 58