changeset 146:8c519a44e699

Re #345: Add failure message to requirements * Add testing of failure messages for "allows adding"
author IBBoard <dev@ibboard.co.uk>
date Sun, 01 May 2011 19:17:11 +0000
parents 0d40d80226b8
children 1de37b5c8107
files API/Objects/Requirement/Mock/AbstractFixedRequirement.cs API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs
diffstat 5 files changed, 272 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Sun May 01 19:14:38 2011 +0000
+++ b/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Sun May 01 19:17:11 2011 +0000
@@ -28,6 +28,11 @@
 		{
 			return (result.Equals(Validation.Failed)) ? "Validation failed" : "";
 		}
+
+		public string GetAllowsAddingMessage (UnitType toAdd, Army toArmy)
+		{
+			return (result.Equals(Validation.Failed)) ? "Validation failed" : "";
+		}
 	}
 }
 
--- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 19:14:38 2011 +0000
+++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 19:17:11 2011 +0000
@@ -204,6 +204,88 @@
 			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0); 1 × " + unitType2.Name + " (have 0)."));
 		}
 
+		[Test]
+		public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
+			req.AddUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (have 0)."));
+		}
+
+		[Test]
+		public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			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)."));
+		}
+
+		[Test]
+		public void TestAllowsAddingMessageIsBlankForPass()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1);
+			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.Empty);
+		}
+
+		[Test]
+		public void TestAllowsAddingMessageIsCorrectForFailWithTwoOfOneUnitRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
+			req.AddUnitTypeRequirement(unitType1, 2);
+			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 2 × " + unitType1.Name + " (would have 1)."));
+		}
+
+		[Test]
+		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
+			req.AddUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0)."));
+		}
+
+		[Test]
+		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredOtherUnit()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
+			req.AddUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (would have 0)."));
+		}
+
+		[Test]
+		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
+			req.AddUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0)."));
+		}
+
+		[Test]
+		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
+			req.AddUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (would have 0)."));
+		}
+
 		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
 		{
 			army.AddUnit(CreateUnitOfType(unitType, army));
--- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sun May 01 19:14:38 2011 +0000
+++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sun May 01 19:17:11 2011 +0000
@@ -173,6 +173,65 @@
 			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1)."));
 		}
 
+		[Test]
+		public void TestAllowsAddMessageIsBlankForPass()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.Empty);
+		}
+
+		[Test]
+		public void TestAllowsAddMessageIsCorrectForFailWithOneUnitProhibited()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (would have 1)."));
+		}
+
+		[Test]
+		public void TestAllowsAddMessageIsCorrectForFailWithTwoOfOneUnitLimit()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
+			req.AddUnitTypeRequirement(unitType1, 2);
+			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType1.Name + " (would have 3)."));
+		}
+
+		[Test]
+		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
+			req.AddUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (would have 1)."));
+		}
+
+		[Test]
+		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
+			req.AddUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (would have 1); 0 × " + unitType2.Name + " (would have 1)."));
+		}
+
+		[Test]
+		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
+			req.AddUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (would have 1); 0 × " + unitType2.Name + " (would have 1)."));
+		}
+
 		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
 		{
 			army.AddUnit(CreateUnitOfType(unitType, army));
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 19:14:38 2011 +0000
+++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 19:17:11 2011 +0000
@@ -262,6 +262,66 @@
 			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)."));
 		}
 
+		[Test]
+		public void TestAllowsAddingMessageIsBlankForPass()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.Empty);
+		}
+
+		[Test]
+		public void TestAllowsAddingMessageIsCorrectForFailWithTwoOfOneUnitRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2, 2);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 2 × " + unitType2.Name + " (would have 1)."));
+		}
+
+		[Test]
+		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType3.Name + " (would have 0)."));
+		}
+
+		[Test]
+		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredOtherUnit()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (would have 0)."));
+		}
+
+		[Test]
+		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType3.Name + " (would have 0)."));
+		}
+
+		[Test]
+		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType3, army);
+			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (would have 0)."));
+		}
+
 		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
 		{
 			army.AddUnit(CreateUnitOfType(unitType, army));
--- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sun May 01 19:14:38 2011 +0000
+++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sun May 01 19:17:11 2011 +0000
@@ -214,6 +214,72 @@
 			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army contains " + unitType1.Name + " and so cannot contain more than: 0 × " + unitType2.Name + " (have 1); 0 × " + unitType3.Name + " (have 1)."));
 		}
 
+		[Test]
+		public void TestAllowsAddMessageIsBlankForPass()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.Empty);
+		}
+
+		[Test]
+		public void TestAllowsAddMessageIsCorrectForFailWithOneUnitProhibited()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so cannot contain more than: 0 × " + unitType2.Name + " (would have 1)."));
+		}
+
+		[Test]
+		public void TestAllowsAddMessageIsCorrectForFailWithTwoOfOneUnitLimit()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			AddUnitOfTypeToArmy(unitType2, army);
+			AddUnitOfTypeToArmy(unitType2, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2, 2);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so cannot contain more than: 2 × " + unitType2.Name + " (would have 3)."));
+		}
+
+		[Test]
+		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so cannot contain more than: 0 × " + unitType2.Name + " (would have 1)."));
+		}
+
+		[Test]
+		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			AddUnitOfTypeToArmy(unitType2, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army contains " + unitType1.Name + " and so cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1)."));
+		}
+
+		[Test]
+		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			AddUnitOfTypeToArmy(unitType3, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1)."));
+		}
+
 		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
 		{
 			army.AddUnit(CreateUnitOfType(unitType, army));