diff API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs @ 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 8c519a44e699
line wrap: on
line diff
--- 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));