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 wrap: on
line diff
--- a/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Thu Apr 28 13:36:16 2011 +0000
+++ b/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Sun May 01 14:21:58 2011 +0000
@@ -23,6 +23,11 @@
 		{
 			return result;
 		}
+
+		public string GetValidationMessage (Army army)
+		{
+			return (result.Equals(Validation.Failed)) ? "Validation failed" : "";
+		}
 	}
 }
 
--- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Thu Apr 28 13:36:16 2011 +0000
+++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 14:21:58 2011 +0000
@@ -168,6 +168,42 @@
 			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
 		}
 
+		[Test]
+		public void TestValidationMessageIsBlankForPass()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1);
+			Assert.That(req.GetValidationMessage(army), Is.Empty);
+		}
+
+		[Test]
+		public void TestValidationMessageIsCorrectForFailWithOneUnitRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1);
+			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0)."));
+		}
+
+		[Test]
+		public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
+			req.AddUnitTypeRequirement(unitType1, 2);
+			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 × " + unitType1.Name + " (have 0)."));
+		}
+
+		[Test]
+		public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
+			req.AddUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0); 1 × " + unitType2.Name + " (have 0)."));
+		}
+
 		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
 		{
 			army.AddUnit(CreateUnitOfType(unitType, army));