changeset 212:325943cb1db0

Re #379: Fix validation of requirements to check for unit * Create common base class for requirement testing with helper methods * Rework unit adding tests in UnitRequiresNoMoreThanNOfUnitTypeRequirementTest to new structure
author IBBoard <dev@ibboard.co.uk>
date Sun, 26 Feb 2012 15:20:48 +0000
parents bc782a0d47bf
children 0416df2ab39b
files API/Objects/Requirement/AbstractUnitRequirementTest.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 5 files changed, 134 insertions(+), 223 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Requirement/AbstractUnitRequirementTest.cs	Sun Feb 26 15:20:48 2012 +0000
@@ -0,0 +1,80 @@
+// This file (AbstractUnitRequirementTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard
+// 
+// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using NUnit.Framework;
+using NUnit.Framework.SyntaxHelpers;
+
+namespace IBBoard.WarFoundry.API.Objects.Requirement
+{
+	/// <summary>
+	/// Base class of helper methods for checking unit requirements
+	/// </summary>
+	public abstract class AbstractUnitRequirementTest<OBJECT_TYPE> where OBJECT_TYPE : IWarFoundryObject
+	{
+		protected static void Assert_That__PassesAdding(AbstractUnitRequirement<OBJECT_TYPE> req, UnitType unitType, Army army)
+		{
+			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Passed));
+			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty);
+		}
+
+		protected static void Assert_That__PassesAdding(AbstractUnitRequirement<OBJECT_TYPE> req, Unit unit, Army army)
+		{
+			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
+			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty);
+		}
+
+		protected static void Assert_That__AddingNotApplicable(AbstractUnitRequirement<OBJECT_TYPE> req, UnitType unitType, Army army)
+		{
+			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.NotApplicable));
+			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty);
+		}
+
+		protected static void Assert_That__AddingNotApplicable(AbstractUnitRequirement<OBJECT_TYPE> req, Unit unit, Army army)
+		{
+			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable));
+			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty);
+		}
+
+		protected static void Assert_That__FailsAdding(AbstractUnitRequirement<OBJECT_TYPE> req, UnitType unitType, Army army, string message)
+		{
+			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Failed));
+			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.EqualTo(message));
+		}
+
+		protected static void Assert_That__FailsAdding(AbstractUnitRequirement<OBJECT_TYPE> req, Unit unit, Army army, string message)
+		{
+			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
+			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.EqualTo(message));
+		}
+
+		protected static void Assert_That__ValidationPasses(AbstractUnitRequirement<OBJECT_TYPE> req, Army army)
+		{
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
+			Assert.That(req.GetValidationMessage(army), Is.Empty);
+		}
+
+		protected static void Assert_That__NotApplicable(AbstractUnitRequirement<OBJECT_TYPE> req, Army army)
+		{
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable));
+			Assert.That(req.GetValidationMessage(army), Is.Empty);
+		}
+
+		protected static void Assert_That__ValidationFails(AbstractUnitRequirement<OBJECT_TYPE> req, Army army, string message)
+		{
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
+			Assert.That(req.GetValidationMessage(army), Is.EqualTo(message));
+		}
+
+		protected static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
+		{
+			army.AddUnit(CreateUnitOfType(unitType, army));
+		}
+
+		protected static Unit CreateUnitOfType(UnitType unitType, Army army)
+		{
+			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
+		}
+	}
+}
+
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sat Feb 25 17:02:38 2012 +0000
+++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun Feb 26 15:20:48 2012 +0000
@@ -9,7 +9,7 @@
 namespace IBBoard.WarFoundry.API.Objects.Requirement
 {
 	[TestFixture()]
-	public class UnitRequiresAtLeastNUnitsRequirementTest
+	public class UnitRequiresAtLeastNUnitsRequirementTest : AbstractUnitRequirementTest<UnitType>
 	{
 		private MockRace mockRace;
 		private UnitType unitType1;
@@ -321,16 +321,6 @@
 			req.AddUnitTypeRequirement(unitType3);
 			Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0)."));
 		}
-
-		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
-		{
-			army.AddUnit(CreateUnitOfType(unitType, army));
-		}
-
-		private static Unit CreateUnitOfType(UnitType unitType, Army army)
-		{
-			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
-		}
 	}
 }
 
--- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Sat Feb 25 17:02:38 2012 +0000
+++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Sun Feb 26 15:20:48 2012 +0000
@@ -9,7 +9,7 @@
 namespace IBBoard.WarFoundry.API.Objects.Requirement
 {
 	[TestFixture()]
-	public class UnitRequiresNUnitsForMUnitsRequirementTests
+	public class UnitRequiresNUnitsForMUnitsRequirementTests : AbstractUnitRequirementTest<UnitType>
 	{
 		private MockRace mockRace;
 		private UnitType unitType1;
@@ -343,70 +343,6 @@
 			AddUnitOfTypeToArmy(unitType1, army);
 			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2).");
 		}
-
-		private static void Assert_That__PassesAdding(UnitRequiresNUnitsForMUnitsRequirement req, UnitType unitType, Army army)
-		{
-			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Passed));
-			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty);
-		}
-
-		private static void Assert_That__PassesAdding(UnitRequiresNUnitsForMUnitsRequirement req, Unit unit, Army army)
-		{
-			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
-			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty);
-		}
-
-		private static void Assert_That__AddingNotApplicable(UnitRequiresNUnitsForMUnitsRequirement req, UnitType unitType, Army army)
-		{
-			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.NotApplicable));
-			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty);
-		}
-
-		private static void Assert_That__AddingNotApplicable(UnitRequiresNUnitsForMUnitsRequirement req, Unit unit, Army army)
-		{
-			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable));
-			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty);
-		}
-
-		private static void Assert_That__FailsAdding(UnitRequiresNUnitsForMUnitsRequirement req, UnitType unitType, Army army, string message)
-		{
-			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Failed));
-			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.EqualTo(message));
-		}
-
-		private static void Assert_That__FailsAdding(UnitRequiresNUnitsForMUnitsRequirement req, Unit unit, Army army, string message)
-		{
-			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
-			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.EqualTo(message));
-		}
-
-		private static void Assert_That__ValidationPasses(UnitRequiresNUnitsForMUnitsRequirement req, Army army)
-		{
-			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
-			Assert.That(req.GetValidationMessage(army), Is.Empty);
-		}
-
-		private static void Assert_That__NotApplicable(UnitRequiresNUnitsForMUnitsRequirement req, Army army)
-		{
-			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable));
-			Assert.That(req.GetValidationMessage(army), Is.Empty);
-		}
-
-		private static void Assert_That__ValidationFails(UnitRequiresNUnitsForMUnitsRequirement req, Army army, string message)
-		{
-			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
-			Assert.That(req.GetValidationMessage(army), Is.EqualTo(message));
-		}
-
-		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
-		{
-			army.AddUnit(CreateUnitOfType(unitType, army));
-		}
-
-		private static Unit CreateUnitOfType(UnitType unitType, Army army)
-		{
-			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
-		}
 	}
 }
 
--- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sat Feb 25 17:02:38 2012 +0000
+++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sun Feb 26 15:20:48 2012 +0000
@@ -9,7 +9,7 @@
 namespace IBBoard.WarFoundry.API.Objects.Requirement
 {
 	[TestFixture()]
-	public class UnitRequiresNoMoreThanNOfUnitTypeRequirementTest
+	public class UnitRequiresNoMoreThanNOfUnitTypeRequirementTest : AbstractUnitRequirementTest<UnitType>
 	{
 		private MockRace mockRace;
 		private UnitType unitType1;
@@ -35,7 +35,16 @@
 			Unit unit = CreateUnitOfType(unitType1, army);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
+			Assert_That__PassesAdding(req, unit, army);
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert_That__PassesAdding(req, unitType1, army);
 		}
 
 		[Test()]
@@ -46,16 +55,7 @@
 			Unit unit = CreateUnitOfType(unitType1, army);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
+			Assert_That__FailsAdding(req, unit, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).");
 		}
 
 		[Test()]
@@ -65,7 +65,7 @@
 			AddUnitOfTypeToArmy(unitType2, army);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
+			Assert_That__FailsAdding(req, unitType1, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).");
 		}
 
 		[Test()]
@@ -75,7 +75,7 @@
 			AddUnitOfTypeToArmy(unitType2, army);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2, 1);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
+			Assert_That__PassesAdding(req, unitType1, army);
 		}
 
 		[Test()]
@@ -86,7 +86,7 @@
 			AddUnitOfTypeToArmy(unitType2, army);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2, 1);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
+			Assert_That__FailsAdding(req, unitType1, army, "Army cannot contain more than: 1 × " + unitType2.Name + " (would have 2).");
 		}
 
 		[Test()]
@@ -96,9 +96,9 @@
 			AddUnitOfTypeToArmy(unitType2, army);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2, 1);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
+			Assert_That__PassesAdding(req, unitType1, army);
 			AddUnitOfTypeToArmy(unitType2, army);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
+			Assert_That__FailsAdding(req, unitType1, army, "Army cannot contain more than: 1 × " + unitType2.Name + " (would have 2).");
 		}
 
 		[Test()]
@@ -107,169 +107,83 @@
 			Army army = new Army(mockRace, "Test", 1000);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
+			Assert_That__PassesAdding(req, unitType1, army);
 			AddUnitOfTypeToArmy(unitType2, army);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
+			Assert_That__FailsAdding(req, unitType1, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).");
 		}
 
 		[Test]
-		public void TestRequirementNotApplicableWhenLimitedUnitNotIncluded()
+		public void TestRequirementNotApplicableWhenAddingWithLimitedUnitNotIncluded()
 		{
 			Army army = new Army(mockRace, "Test", 1000);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unitType3, army), Is.EqualTo(Validation.NotApplicable));
-			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.NotApplicable));
+			Assert_That__AddingNotApplicable(req, unitType3, army);
+			Assert_That__AddingNotApplicable(req, CreateUnitOfType(unitType3, army), army);
+			Assert_That__AddingNotApplicable(req, unitType2, army);
+			Assert_That__AddingNotApplicable(req, CreateUnitOfType(unitType2, army), army);
 		}
 
 		[Test]
-		public void TestRequirementBecomesInvalidWhenProhibitedUnitsChange()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType1, army);
-			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
-			AddUnitOfTypeToArmy(unitType2, army);
-			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
-		}
-
-		[Test()]
-		public void TestAddingLimitedUnitTriggersFailure()
+		public void TestRequirementNotApplicableWhenAddingUnrelatedType()
 		{
 			Army army = new Army(mockRace, "Test", 1000);
 			AddUnitOfTypeToArmy(unitType1, army);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed));
-		}
-
-		[Test]
-		public void TestValidationMessageIsBlankForPass()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.GetValidationMessage(army), Is.Empty);
-		}
-
-		[Test]
-		public void TestValidationMessageIsCorrectForFailWithOneUnitProhibited()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType1, army);
+			Assert_That__AddingNotApplicable(req, unitType3, army);
 			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1)."));
-		}
-
-		[Test]
-		public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitLimit()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType1, army);
-			AddUnitOfTypeToArmy(unitType2, army);
-			AddUnitOfTypeToArmy(unitType2, army);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2, 2);
-			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (have 3)."));
+			Assert_That__AddingNotApplicable(req, unitType3, army);
 		}
 
-		[Test]
-		public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibited()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType1, army);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			req.AddUnitTypeRequirement(unitType3);
-			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1)."));
-		}
-
-		[Test]
-		public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType1, army);
-			AddUnitOfTypeToArmy(unitType3, army);
-			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			req.AddUnitTypeRequirement(unitType3);
-			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType3.Name + " (have 1)."));
-		}
-
-		[Test]
-		public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndBothUnitsInArmy()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType1, army);
-			AddUnitOfTypeToArmy(unitType2, army);
-			AddUnitOfTypeToArmy(unitType3, army);
-			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			req.AddUnitTypeRequirement(unitType3);
-			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1); 0 × " + unitType3.Name + " (have 1)."));
-		}
-
-		[Test]
-		public void TestAllowsAddMessageIsBlankForPass()
+		[Test()]
+		public void TestAddingRequirementUnitTriggersFailure()
 		{
 			Army army = new Army(mockRace, "Test", 1000);
 			AddUnitOfTypeToArmy(unitType1, army);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement 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);
-			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1)."));
+			req.AddUnitTypeRequirement(unitType2, 1);
+			Assert_That__PassesAdding(req, unitType2, army);
+			AddUnitOfTypeToArmy(unitType2, army);
+			Assert_That__FailsAdding(req, unitType2, army, "Army cannot contain more than: 1 × " + unitType2.Name + " (would have 2).");
 		}
 
 		[Test]
-		public void TestAllowsAddMessageIsCorrectForFailWithTwoOfOneUnitLimit()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType1, army);
-			AddUnitOfTypeToArmy(unitType2, army);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2, 2);
-			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (would have 3)."));
-		}
-
-		[Test]
-		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited()
+		public void TestAddingRequirementUnitFailsWithTwoUnitTypesProhibited()
 		{
 			Army army = new Army(mockRace, "Test", 1000);
 			AddUnitOfTypeToArmy(unitType1, army);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2);
 			req.AddUnitTypeRequirement(unitType3);
-			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1)."));
+			Assert_That__FailsAdding(req, unitType2, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).");
 		}
 
 		[Test]
-		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy()
+		public void TestAddingOtherRequirementUnitFailsWithTwoUnitTypesProhibited()
 		{
 			Army army = new Army(mockRace, "Test", 1000);
 			AddUnitOfTypeToArmy(unitType1, army);
-			AddUnitOfTypeToArmy(unitType2, army);
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2);
 			req.AddUnitTypeRequirement(unitType3);
-			Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1)."));
+			Assert_That__FailsAdding(req, unitType3, army, "Army cannot contain more than: 0 × " + unitType3.Name + " (would have 1).");
+		}
+
+		[Test]
+		public void TestAddingRequirementUnitFailsWithTwoUnitTypesProhibitedAndOneUnitTypeAlreadyInArmy()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			AddUnitOfTypeToArmy(unitType2, army);
+			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert_That__FailsAdding(req, unitType3, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1).");
 		}
 
 		[Test]
-		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy()
+		public void TestAddingRequirementUnitFailsWithTwoUnitTypesProhibitedAndOtherUnitTypeAlreadyInArmy()
 		{
 			Army army = new Army(mockRace, "Test", 1000);
 			AddUnitOfTypeToArmy(unitType1, army);
@@ -277,17 +191,7 @@
 			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
 			req.AddUnitTypeRequirement(unitType2);
 			req.AddUnitTypeRequirement(unitType3);
-			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army 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));
-		}
-
-		private static Unit CreateUnitOfType(UnitType unitType, Army army)
-		{
-			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
+			Assert_That__FailsAdding(req, unitType2, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1).");
 		}
 	}
 }
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Feb 25 17:02:38 2012 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Feb 26 15:20:48 2012 +0000
@@ -119,6 +119,7 @@
     <Compile Include="API\Objects\Requirement\UnitRequiresNUnitsForMUnitsRequirementTests.cs" />
     <Compile Include="API\Objects\Requirement\RequiresNUnitsForMObjectsRequirementTest.cs" />
     <Compile Include="API\Objects\Requirement\Mock\MockRequiresNUnitsForMObjectsRequirement.cs" />
+    <Compile Include="API\Objects\Requirement\AbstractUnitRequirementTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />