changeset 195:8e95ccb8e9d5

Re #350: Add requirement to allow N of unit for specific other units * Add tests for multiple failures
author IBBoard <dev@ibboard.co.uk>
date Sat, 03 Dec 2011 20:09:25 +0000
parents f1f4df654a91
children 498396c77601
files API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs
diffstat 1 files changed, 56 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Sat Dec 03 19:56:58 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Sat Dec 03 20:09:25 2011 +0000
     1.3 @@ -116,6 +116,34 @@
     1.4  		}
     1.5  
     1.6  		[Test()]
     1.7 +		public void TestAddingSecondUnitsWithOneAllowedForTwoTypesFails()
     1.8 +		{
     1.9 +			Army army = new Army(mockRace, "Test", 1000);
    1.10 +			AddUnitOfTypeToArmy(unitType2, army);
    1.11 +			AddUnitOfTypeToArmy(unitType3, army);
    1.12 +			AddUnitOfTypeToArmy(unitType1, army);
    1.13 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.14 +			req.AddUnitTypeRequirement(unitType2, 1, 1);
    1.15 +			req.AddUnitTypeRequirement(unitType3, 1, 1);
    1.16 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.17 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    1.18 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (would have 1 for 2); 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 1 for 2)."));
    1.19 +		}
    1.20 +
    1.21 +		[Test()]
    1.22 +		public void TestAddingSecondUnitsWithOneAllowedForTwoTypesFails_ShorthandMethod()
    1.23 +		{
    1.24 +			Army army = new Army(mockRace, "Test", 1000);
    1.25 +			AddUnitOfTypeToArmy(unitType2, army);
    1.26 +			AddUnitOfTypeToArmy(unitType3, army);
    1.27 +			AddUnitOfTypeToArmy(unitType1, army);
    1.28 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2, unitType3);
    1.29 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.30 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    1.31 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (would have 1 for 2); 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 1 for 2)."));
    1.32 +		}
    1.33 +
    1.34 +		[Test()]
    1.35  		public void TestAddingThreeUnitsWithTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails()
    1.36  		{
    1.37  			Army army = new Army(mockRace, "Test", 1000);
    1.38 @@ -213,6 +241,34 @@
    1.39  		}
    1.40  
    1.41  		[Test()]
    1.42 +		public void TestValidatingArmyWithTwoUnitsWithOneAllowedForTwoTypesFails()
    1.43 +		{
    1.44 +			Army army = new Army(mockRace, "Test", 1000);
    1.45 +			AddUnitOfTypeToArmy(unitType2, army);
    1.46 +			AddUnitOfTypeToArmy(unitType3, army);
    1.47 +			AddUnitOfTypeToArmy(unitType1, army);
    1.48 +			AddUnitOfTypeToArmy(unitType1, army);
    1.49 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.50 +			req.AddUnitTypeRequirement(unitType2, 1, 1);
    1.51 +			req.AddUnitTypeRequirement(unitType3, 1, 1);
    1.52 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.53 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (have 1 for 2); 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (have 1 for 2)."));
    1.54 +		}
    1.55 +
    1.56 +		[Test()]
    1.57 +		public void TestValidatingArmyWithTwoUnitsWithOneAllowedForTwoTypesFails_ShorthandMethod()
    1.58 +		{
    1.59 +			Army army = new Army(mockRace, "Test", 1000);
    1.60 +			AddUnitOfTypeToArmy(unitType2, army);
    1.61 +			AddUnitOfTypeToArmy(unitType3, army);
    1.62 +			AddUnitOfTypeToArmy(unitType1, army);
    1.63 +			AddUnitOfTypeToArmy(unitType1, army);
    1.64 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2, unitType3);
    1.65 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.66 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (have 1 for 2); 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (have 1 for 2)."));
    1.67 +		}
    1.68 +
    1.69 +		[Test()]
    1.70  		public void TestValidatingArmyWithThreeUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails()
    1.71  		{
    1.72  			Army army = new Army(mockRace, "Test", 1000);