changeset 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
files API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs
diffstat 1 files changed, 38 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sat Mar 26 17:04:09 2011 +0000
     1.2 +++ b/API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sat Mar 26 21:02:18 2011 +0000
     1.3 @@ -10,20 +10,49 @@
     1.4  {
     1.5  	[TestFixture()]
     1.6  	public class UnitRequiresAtLeastNUnitsRequirementTest
     1.7 -	{
     1.8 +	{
     1.9 +		private MockRace mockRace;
    1.10 +		private UnitType unitType1;
    1.11 +		private UnitType unitType2;
    1.12 +
    1.13 +		[TestFixtureSetUp()]
    1.14 +		public void SetupRace()
    1.15 +		{
    1.16 +			mockRace = MockRace.GetMockRace();
    1.17 +			unitType1 = new MockUnitType("type1", "Unit Type 1");
    1.18 +			mockRace.AddUnitType(unitType1);
    1.19 +			unitType2 = new MockUnitType("type2", "Unit Type 2");
    1.20 +			mockRace.AddUnitType(unitType2);
    1.21 +		}
    1.22 +
    1.23  		[Test()]
    1.24 -		public void TestWithNoUnits()
    1.25 +		public void TestWithNoUnitsAndOneUnitTypeRequired()
    1.26  		{
    1.27 -			MockRace mockRace = MockRace.GetMockRace();
    1.28 -			UnitType unitType1 = new MockUnitType("type1", "Unit Type 1");
    1.29 -			mockRace.AddUnitType(unitType1);
    1.30 -			UnitType unitType2 = new MockUnitType("type2", "Unit Type 2");
    1.31 -			mockRace.AddUnitType(unitType2);
    1.32  			Army army = new Army(mockRace, "Test", 1000);
    1.33 -			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1, unitType2);
    1.34 -			Unit unit = new Unit(unitType1, army.GetCategory(unitType1.MainCategory));
    1.35 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.36 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
    1.37  			Assert.That(req.CanAddToArmy(unit, army), Is.False);
    1.38 +		}
    1.39 +
    1.40 +		[Test()]
    1.41 +		public void TestWithOneUnitAndOneUnitTypeRequired()
    1.42 +		{
    1.43 +			Army army = new Army(mockRace, "Test", 1000);
    1.44 +			AddUnitOfTypeToArmy(unitType2, army);
    1.45 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.46 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
    1.47 +			Assert.That(req.CanAddToArmy(unit, army), Is.True);
    1.48 +		}
    1.49 +
    1.50 +		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    1.51 +		{
    1.52 +			army.AddUnit(CreateUnitOfType(unitType, army));
    1.53  		}
    1.54 +
    1.55 +		private static Unit CreateUnitOfType(UnitType unitType, Army army)
    1.56 +		{
    1.57 +			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
    1.58 +		}
    1.59  	}
    1.60  }
    1.61