changeset 142:f36b5e5e51e6

Re #345: Add failure message to requirements * Add tests for "unit at least" requirement
author IBBoard <dev@ibboard.co.uk>
date Sun, 01 May 2011 14:32:24 +0000
parents cd95fc6400b2
children 6fdb76d48e04
files API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs
diffstat 1 files changed, 41 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 14:21:58 2011 +0000
     1.2 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 14:32:24 2011 +0000
     1.3 @@ -220,13 +220,53 @@
     1.4  			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed));
     1.5  		}
     1.6  
     1.7 +		[Test]
     1.8 +		public void TestValidationMessageIsBlankForPass()
     1.9 +		{
    1.10 +			Army army = new Army(mockRace, "Test", 1000);
    1.11 +			AddUnitOfTypeToArmy(unitType1, army);
    1.12 +			AddUnitOfTypeToArmy(unitType2, army);
    1.13 +			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.14 +			req.AddUnitTypeRequirement(unitType2);
    1.15 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.16 +		}
    1.17 +
    1.18 +		[Test]
    1.19 +		public void TestValidationMessageIsCorrectForFailWithOneUnitRequired()
    1.20 +		{
    1.21 +			Army army = new Army(mockRace, "Test", 1000);
    1.22 +			AddUnitOfTypeToArmy(unitType1, army);
    1.23 +			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.24 +			req.AddUnitTypeRequirement(unitType2);
    1.25 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (have 0)."));
    1.26 +		}
    1.27 +
    1.28 +		[Test]
    1.29 +		public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitRequired()
    1.30 +		{
    1.31 +			Army army = new Army(mockRace, "Test", 1000);
    1.32 +			AddUnitOfTypeToArmy(unitType1, army);
    1.33 +			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.34 +			req.AddUnitTypeRequirement(unitType2, 2);
    1.35 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 2 × " + unitType2.Name + " (have 0)."));
    1.36 +		}
    1.37 +
    1.38 +		[Test]
    1.39 +		public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequired()
    1.40 +		{
    1.41 +			Army army = new Army(mockRace, "Test", 1000);
    1.42 +			AddUnitOfTypeToArmy(unitType1, army);
    1.43 +			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.44 +			req.AddUnitTypeRequirement(unitType2);
    1.45 +			req.AddUnitTypeRequirement(unitType3);
    1.46 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (have 0); 1 × " + unitType3.Name + " (have 0)."));
    1.47 +		}
    1.48  
    1.49  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    1.50  		{
    1.51  			army.AddUnit(CreateUnitOfType(unitType, army));
    1.52  		}
    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));