changeset 141:cd95fc6400b2

Re #345: Add failure message to requirements * Implement new method from requirement interface * Add first tests for "at least" requirement
author IBBoard <dev@ibboard.co.uk>
date Sun, 01 May 2011 14:21:58 +0000
parents 2ae80631ec9c
children f36b5e5e51e6
files API/Objects/Requirement/Mock/AbstractFixedRequirement.cs API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs
diffstat 2 files changed, 41 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Thu Apr 28 13:36:16 2011 +0000
     1.2 +++ b/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Sun May 01 14:21:58 2011 +0000
     1.3 @@ -23,6 +23,11 @@
     1.4  		{
     1.5  			return result;
     1.6  		}
     1.7 +
     1.8 +		public string GetValidationMessage (Army army)
     1.9 +		{
    1.10 +			return (result.Equals(Validation.Failed)) ? "Validation failed" : "";
    1.11 +		}
    1.12  	}
    1.13  }
    1.14  
     2.1 --- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Thu Apr 28 13:36:16 2011 +0000
     2.2 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 14:21:58 2011 +0000
     2.3 @@ -168,6 +168,42 @@
     2.4  			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
     2.5  		}
     2.6  
     2.7 +		[Test]
     2.8 +		public void TestValidationMessageIsBlankForPass()
     2.9 +		{
    2.10 +			Army army = new Army(mockRace, "Test", 1000);
    2.11 +			AddUnitOfTypeToArmy(unitType1, army);
    2.12 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1);
    2.13 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    2.14 +		}
    2.15 +
    2.16 +		[Test]
    2.17 +		public void TestValidationMessageIsCorrectForFailWithOneUnitRequired()
    2.18 +		{
    2.19 +			Army army = new Army(mockRace, "Test", 1000);
    2.20 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1);
    2.21 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0)."));
    2.22 +		}
    2.23 +
    2.24 +		[Test]
    2.25 +		public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitRequired()
    2.26 +		{
    2.27 +			Army army = new Army(mockRace, "Test", 1000);
    2.28 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    2.29 +			req.AddUnitTypeRequirement(unitType1, 2);
    2.30 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 × " + unitType1.Name + " (have 0)."));
    2.31 +		}
    2.32 +
    2.33 +		[Test]
    2.34 +		public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequired()
    2.35 +		{
    2.36 +			Army army = new Army(mockRace, "Test", 1000);
    2.37 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    2.38 +			req.AddUnitTypeRequirement(unitType1);
    2.39 +			req.AddUnitTypeRequirement(unitType2);
    2.40 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0); 1 × " + unitType2.Name + " (have 0)."));
    2.41 +		}
    2.42 +
    2.43  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    2.44  		{
    2.45  			army.AddUnit(CreateUnitOfType(unitType, army));