changeset 122:aa37b31976e6

Re #27: Unit requirements * Restructure "check default" tests so that we actually check the default (test before and after) * Add test to make sure requirement checks on each request * Add test to make sure that adding more prohibited units than the limit causes a failure
author IBBoard <dev@ibboard.co.uk>
date Sat, 09 Apr 2011 10:43:01 +0000
parents 6f46fa3c47e5
children dd0ef8526a4e
files API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs
diffstat 2 files changed, 27 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sat Apr 09 10:18:27 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sat Apr 09 10:43:01 2011 +0000
     1.3 @@ -89,9 +89,10 @@
     1.4  		public void TestAddingUnitTypeDefaultsToNoMoreThanZero()
     1.5  		{
     1.6  			Army army = new Army(mockRace, "Test", 1000);
     1.7 -			AddUnitOfTypeToArmy(unitType2, army);
     1.8  			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
     1.9  			req.AddUnitTypeRequirement(unitType2);
    1.10 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    1.11 +			AddUnitOfTypeToArmy(unitType2, army);
    1.12  			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    1.13  		}
    1.14  
     2.1 --- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sat Apr 09 10:18:27 2011 +0000
     2.2 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sat Apr 09 10:43:01 2011 +0000
     2.3 @@ -105,10 +105,10 @@
     2.4  		public void TestAddingUnitTypeDefaultsToNoMoreThanZero()
     2.5  		{
     2.6  			Army army = new Army(mockRace, "Test", 1000);
     2.7 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
     2.8 +			req.AddUnitTypeRequirement(unitType2);
     2.9 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    2.10  			AddUnitOfTypeToArmy(unitType2, army);
    2.11 -			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    2.12 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    2.13 -			req.AddUnitTypeRequirement(unitType2);
    2.14  			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    2.15  		}
    2.16  
    2.17 @@ -122,6 +122,28 @@
    2.18  			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.NotApplicable));
    2.19  		}
    2.20  
    2.21 +		[Test]
    2.22 +		public void TestRequirementBecomesInvalidWhenProhibitedUnitsChange()
    2.23 +		{
    2.24 +			Army army = new Army(mockRace, "Test", 1000);
    2.25 +			AddUnitOfTypeToArmy(unitType1, army);
    2.26 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    2.27 +			req.AddUnitTypeRequirement(unitType2);
    2.28 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
    2.29 +			AddUnitOfTypeToArmy(unitType2, army);
    2.30 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    2.31 +		}
    2.32 +
    2.33 +		[Test()]
    2.34 +		public void TestAddingLimitedUnitTriggersFailure()
    2.35 +		{
    2.36 +			Army army = new Army(mockRace, "Test", 1000);
    2.37 +			AddUnitOfTypeToArmy(unitType1, army);
    2.38 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    2.39 +			req.AddUnitTypeRequirement(unitType2);
    2.40 +			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed));
    2.41 +		}
    2.42 +
    2.43  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    2.44  		{
    2.45  			army.AddUnit(CreateUnitOfType(unitType, army));