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, 133 insertions(+), 222 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Objects/Requirement/AbstractUnitRequirementTest.cs	Sun Feb 26 15:20:48 2012 +0000
     1.3 @@ -0,0 +1,80 @@
     1.4 +// This file (AbstractUnitRequirementTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard
     1.5 +// 
     1.6 +// 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.
     1.7 +using System;
     1.8 +using NUnit.Framework;
     1.9 +using NUnit.Framework.SyntaxHelpers;
    1.10 +
    1.11 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    1.12 +{
    1.13 +	/// <summary>
    1.14 +	/// Base class of helper methods for checking unit requirements
    1.15 +	/// </summary>
    1.16 +	public abstract class AbstractUnitRequirementTest<OBJECT_TYPE> where OBJECT_TYPE : IWarFoundryObject
    1.17 +	{
    1.18 +		protected static void Assert_That__PassesAdding(AbstractUnitRequirement<OBJECT_TYPE> req, UnitType unitType, Army army)
    1.19 +		{
    1.20 +			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Passed));
    1.21 +			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty);
    1.22 +		}
    1.23 +
    1.24 +		protected static void Assert_That__PassesAdding(AbstractUnitRequirement<OBJECT_TYPE> req, Unit unit, Army army)
    1.25 +		{
    1.26 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.27 +			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty);
    1.28 +		}
    1.29 +
    1.30 +		protected static void Assert_That__AddingNotApplicable(AbstractUnitRequirement<OBJECT_TYPE> req, UnitType unitType, Army army)
    1.31 +		{
    1.32 +			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.NotApplicable));
    1.33 +			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty);
    1.34 +		}
    1.35 +
    1.36 +		protected static void Assert_That__AddingNotApplicable(AbstractUnitRequirement<OBJECT_TYPE> req, Unit unit, Army army)
    1.37 +		{
    1.38 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable));
    1.39 +			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty);
    1.40 +		}
    1.41 +
    1.42 +		protected static void Assert_That__FailsAdding(AbstractUnitRequirement<OBJECT_TYPE> req, UnitType unitType, Army army, string message)
    1.43 +		{
    1.44 +			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Failed));
    1.45 +			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.EqualTo(message));
    1.46 +		}
    1.47 +
    1.48 +		protected static void Assert_That__FailsAdding(AbstractUnitRequirement<OBJECT_TYPE> req, Unit unit, Army army, string message)
    1.49 +		{
    1.50 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    1.51 +			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.EqualTo(message));
    1.52 +		}
    1.53 +
    1.54 +		protected static void Assert_That__ValidationPasses(AbstractUnitRequirement<OBJECT_TYPE> req, Army army)
    1.55 +		{
    1.56 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
    1.57 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.58 +		}
    1.59 +
    1.60 +		protected static void Assert_That__NotApplicable(AbstractUnitRequirement<OBJECT_TYPE> req, Army army)
    1.61 +		{
    1.62 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable));
    1.63 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.64 +		}
    1.65 +
    1.66 +		protected static void Assert_That__ValidationFails(AbstractUnitRequirement<OBJECT_TYPE> req, Army army, string message)
    1.67 +		{
    1.68 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.69 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo(message));
    1.70 +		}
    1.71 +
    1.72 +		protected static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    1.73 +		{
    1.74 +			army.AddUnit(CreateUnitOfType(unitType, army));
    1.75 +		}
    1.76 +
    1.77 +		protected static Unit CreateUnitOfType(UnitType unitType, Army army)
    1.78 +		{
    1.79 +			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
    1.80 +		}
    1.81 +	}
    1.82 +}
    1.83 +
     2.1 --- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sat Feb 25 17:02:38 2012 +0000
     2.2 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun Feb 26 15:20:48 2012 +0000
     2.3 @@ -9,7 +9,7 @@
     2.4  namespace IBBoard.WarFoundry.API.Objects.Requirement
     2.5  {
     2.6  	[TestFixture()]
     2.7 -	public class UnitRequiresAtLeastNUnitsRequirementTest
     2.8 +	public class UnitRequiresAtLeastNUnitsRequirementTest : AbstractUnitRequirementTest<UnitType>
     2.9  	{
    2.10  		private MockRace mockRace;
    2.11  		private UnitType unitType1;
    2.12 @@ -321,16 +321,6 @@
    2.13  			req.AddUnitTypeRequirement(unitType3);
    2.14  			Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0)."));
    2.15  		}
    2.16 -
    2.17 -		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    2.18 -		{
    2.19 -			army.AddUnit(CreateUnitOfType(unitType, army));
    2.20 -		}
    2.21 -
    2.22 -		private static Unit CreateUnitOfType(UnitType unitType, Army army)
    2.23 -		{
    2.24 -			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
    2.25 -		}
    2.26  	}
    2.27  }
    2.28  
     3.1 --- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Sat Feb 25 17:02:38 2012 +0000
     3.2 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Sun Feb 26 15:20:48 2012 +0000
     3.3 @@ -9,7 +9,7 @@
     3.4  namespace IBBoard.WarFoundry.API.Objects.Requirement
     3.5  {
     3.6  	[TestFixture()]
     3.7 -	public class UnitRequiresNUnitsForMUnitsRequirementTests
     3.8 +	public class UnitRequiresNUnitsForMUnitsRequirementTests : AbstractUnitRequirementTest<UnitType>
     3.9  	{
    3.10  		private MockRace mockRace;
    3.11  		private UnitType unitType1;
    3.12 @@ -343,70 +343,6 @@
    3.13  			AddUnitOfTypeToArmy(unitType1, army);
    3.14  			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2).");
    3.15  		}
    3.16 -
    3.17 -		private static void Assert_That__PassesAdding(UnitRequiresNUnitsForMUnitsRequirement req, UnitType unitType, Army army)
    3.18 -		{
    3.19 -			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Passed));
    3.20 -			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty);
    3.21 -		}
    3.22 -
    3.23 -		private static void Assert_That__PassesAdding(UnitRequiresNUnitsForMUnitsRequirement req, Unit unit, Army army)
    3.24 -		{
    3.25 -			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    3.26 -			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty);
    3.27 -		}
    3.28 -
    3.29 -		private static void Assert_That__AddingNotApplicable(UnitRequiresNUnitsForMUnitsRequirement req, UnitType unitType, Army army)
    3.30 -		{
    3.31 -			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.NotApplicable));
    3.32 -			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty);
    3.33 -		}
    3.34 -
    3.35 -		private static void Assert_That__AddingNotApplicable(UnitRequiresNUnitsForMUnitsRequirement req, Unit unit, Army army)
    3.36 -		{
    3.37 -			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable));
    3.38 -			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty);
    3.39 -		}
    3.40 -
    3.41 -		private static void Assert_That__FailsAdding(UnitRequiresNUnitsForMUnitsRequirement req, UnitType unitType, Army army, string message)
    3.42 -		{
    3.43 -			Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Failed));
    3.44 -			Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.EqualTo(message));
    3.45 -		}
    3.46 -
    3.47 -		private static void Assert_That__FailsAdding(UnitRequiresNUnitsForMUnitsRequirement req, Unit unit, Army army, string message)
    3.48 -		{
    3.49 -			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    3.50 -			Assert.That(req.GetAllowsAddingMessage(unit, army), Is.EqualTo(message));
    3.51 -		}
    3.52 -
    3.53 -		private static void Assert_That__ValidationPasses(UnitRequiresNUnitsForMUnitsRequirement req, Army army)
    3.54 -		{
    3.55 -			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
    3.56 -			Assert.That(req.GetValidationMessage(army), Is.Empty);
    3.57 -		}
    3.58 -
    3.59 -		private static void Assert_That__NotApplicable(UnitRequiresNUnitsForMUnitsRequirement req, Army army)
    3.60 -		{
    3.61 -			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable));
    3.62 -			Assert.That(req.GetValidationMessage(army), Is.Empty);
    3.63 -		}
    3.64 -
    3.65 -		private static void Assert_That__ValidationFails(UnitRequiresNUnitsForMUnitsRequirement req, Army army, string message)
    3.66 -		{
    3.67 -			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    3.68 -			Assert.That(req.GetValidationMessage(army), Is.EqualTo(message));
    3.69 -		}
    3.70 -
    3.71 -		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    3.72 -		{
    3.73 -			army.AddUnit(CreateUnitOfType(unitType, army));
    3.74 -		}
    3.75 -
    3.76 -		private static Unit CreateUnitOfType(UnitType unitType, Army army)
    3.77 -		{
    3.78 -			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
    3.79 -		}
    3.80  	}
    3.81  }
    3.82  
     4.1 --- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sat Feb 25 17:02:38 2012 +0000
     4.2 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sun Feb 26 15:20:48 2012 +0000
     4.3 @@ -9,7 +9,7 @@
     4.4  namespace IBBoard.WarFoundry.API.Objects.Requirement
     4.5  {
     4.6  	[TestFixture()]
     4.7 -	public class UnitRequiresNoMoreThanNOfUnitTypeRequirementTest
     4.8 +	public class UnitRequiresNoMoreThanNOfUnitTypeRequirementTest : AbstractUnitRequirementTest<UnitType>
     4.9  	{
    4.10  		private MockRace mockRace;
    4.11  		private UnitType unitType1;
    4.12 @@ -35,7 +35,16 @@
    4.13  			Unit unit = CreateUnitOfType(unitType1, army);
    4.14  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    4.15  			req.AddUnitTypeRequirement(unitType2);
    4.16 -			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    4.17 +			Assert_That__PassesAdding(req, unit, army);
    4.18 +		}
    4.19 +
    4.20 +		[Test()]
    4.21 +		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
    4.22 +		{
    4.23 +			Army army = new Army(mockRace, "Test", 1000);
    4.24 +			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    4.25 +			req.AddUnitTypeRequirement(unitType2);
    4.26 +			Assert_That__PassesAdding(req, unitType1, army);
    4.27  		}
    4.28  
    4.29  		[Test()]
    4.30 @@ -46,16 +55,7 @@
    4.31  			Unit unit = CreateUnitOfType(unitType1, army);
    4.32  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    4.33  			req.AddUnitTypeRequirement(unitType2);
    4.34 -			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    4.35 -		}
    4.36 -
    4.37 -		[Test()]
    4.38 -		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
    4.39 -		{
    4.40 -			Army army = new Army(mockRace, "Test", 1000);
    4.41 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    4.42 -			req.AddUnitTypeRequirement(unitType2);
    4.43 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    4.44 +			Assert_That__FailsAdding(req, unit, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).");
    4.45  		}
    4.46  
    4.47  		[Test()]
    4.48 @@ -65,7 +65,7 @@
    4.49  			AddUnitOfTypeToArmy(unitType2, army);
    4.50  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    4.51  			req.AddUnitTypeRequirement(unitType2);
    4.52 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    4.53 +			Assert_That__FailsAdding(req, unitType1, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).");
    4.54  		}
    4.55  
    4.56  		[Test()]
    4.57 @@ -75,7 +75,7 @@
    4.58  			AddUnitOfTypeToArmy(unitType2, army);
    4.59  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    4.60  			req.AddUnitTypeRequirement(unitType2, 1);
    4.61 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    4.62 +			Assert_That__PassesAdding(req, unitType1, army);
    4.63  		}
    4.64  
    4.65  		[Test()]
    4.66 @@ -86,7 +86,7 @@
    4.67  			AddUnitOfTypeToArmy(unitType2, army);
    4.68  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    4.69  			req.AddUnitTypeRequirement(unitType2, 1);
    4.70 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    4.71 +			Assert_That__FailsAdding(req, unitType1, army, "Army cannot contain more than: 1 × " + unitType2.Name + " (would have 2).");
    4.72  		}
    4.73  
    4.74  		[Test()]
    4.75 @@ -96,9 +96,9 @@
    4.76  			AddUnitOfTypeToArmy(unitType2, army);
    4.77  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    4.78  			req.AddUnitTypeRequirement(unitType2, 1);
    4.79 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    4.80 +			Assert_That__PassesAdding(req, unitType1, army);
    4.81  			AddUnitOfTypeToArmy(unitType2, army);
    4.82 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    4.83 +			Assert_That__FailsAdding(req, unitType1, army, "Army cannot contain more than: 1 × " + unitType2.Name + " (would have 2).");
    4.84  		}
    4.85  
    4.86  		[Test()]
    4.87 @@ -107,169 +107,83 @@
    4.88  			Army army = new Army(mockRace, "Test", 1000);
    4.89  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    4.90  			req.AddUnitTypeRequirement(unitType2);
    4.91 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    4.92 +			Assert_That__PassesAdding(req, unitType1, army);
    4.93  			AddUnitOfTypeToArmy(unitType2, army);
    4.94 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    4.95 +			Assert_That__FailsAdding(req, unitType1, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).");
    4.96  		}
    4.97  
    4.98  		[Test]
    4.99 -		public void TestRequirementNotApplicableWhenLimitedUnitNotIncluded()
   4.100 +		public void TestRequirementNotApplicableWhenAddingWithLimitedUnitNotIncluded()
   4.101  		{
   4.102  			Army army = new Army(mockRace, "Test", 1000);
   4.103  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.104  			req.AddUnitTypeRequirement(unitType2);
   4.105 -			Assert.That(req.AllowsAdding(unitType3, army), Is.EqualTo(Validation.NotApplicable));
   4.106 -			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.NotApplicable));
   4.107 +			Assert_That__AddingNotApplicable(req, unitType3, army);
   4.108 +			Assert_That__AddingNotApplicable(req, CreateUnitOfType(unitType3, army), army);
   4.109 +			Assert_That__AddingNotApplicable(req, unitType2, army);
   4.110 +			Assert_That__AddingNotApplicable(req, CreateUnitOfType(unitType2, army), army);
   4.111  		}
   4.112  
   4.113  		[Test]
   4.114 -		public void TestRequirementBecomesInvalidWhenProhibitedUnitsChange()
   4.115 +		public void TestRequirementNotApplicableWhenAddingUnrelatedType()
   4.116  		{
   4.117  			Army army = new Army(mockRace, "Test", 1000);
   4.118  			AddUnitOfTypeToArmy(unitType1, army);
   4.119  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.120  			req.AddUnitTypeRequirement(unitType2);
   4.121 -			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
   4.122 +			Assert_That__AddingNotApplicable(req, unitType3, army);
   4.123  			AddUnitOfTypeToArmy(unitType2, army);
   4.124 -			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
   4.125 +			Assert_That__AddingNotApplicable(req, unitType3, army);
   4.126  		}
   4.127  
   4.128  		[Test()]
   4.129 -		public void TestAddingLimitedUnitTriggersFailure()
   4.130 +		public void TestAddingRequirementUnitTriggersFailure()
   4.131  		{
   4.132  			Army army = new Army(mockRace, "Test", 1000);
   4.133  			AddUnitOfTypeToArmy(unitType1, army);
   4.134  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.135 -			req.AddUnitTypeRequirement(unitType2);
   4.136 -			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed));
   4.137 +			req.AddUnitTypeRequirement(unitType2, 1);
   4.138 +			Assert_That__PassesAdding(req, unitType2, army);
   4.139 +			AddUnitOfTypeToArmy(unitType2, army);
   4.140 +			Assert_That__FailsAdding(req, unitType2, army, "Army cannot contain more than: 1 × " + unitType2.Name + " (would have 2).");
   4.141  		}
   4.142  
   4.143  		[Test]
   4.144 -		public void TestValidationMessageIsBlankForPass()
   4.145 -		{
   4.146 -			Army army = new Army(mockRace, "Test", 1000);
   4.147 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.148 -			req.AddUnitTypeRequirement(unitType2);
   4.149 -			Assert.That(req.GetValidationMessage(army), Is.Empty);
   4.150 -		}
   4.151 -
   4.152 -		[Test]
   4.153 -		public void TestValidationMessageIsCorrectForFailWithOneUnitProhibited()
   4.154 -		{
   4.155 -			Army army = new Army(mockRace, "Test", 1000);
   4.156 -			AddUnitOfTypeToArmy(unitType1, army);
   4.157 -			AddUnitOfTypeToArmy(unitType2, army);
   4.158 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.159 -			req.AddUnitTypeRequirement(unitType2);
   4.160 -			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1)."));
   4.161 -		}
   4.162 -
   4.163 -		[Test]
   4.164 -		public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitLimit()
   4.165 -		{
   4.166 -			Army army = new Army(mockRace, "Test", 1000);
   4.167 -			AddUnitOfTypeToArmy(unitType1, army);
   4.168 -			AddUnitOfTypeToArmy(unitType2, army);
   4.169 -			AddUnitOfTypeToArmy(unitType2, army);
   4.170 -			AddUnitOfTypeToArmy(unitType2, army);
   4.171 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.172 -			req.AddUnitTypeRequirement(unitType2, 2);
   4.173 -			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (have 3)."));
   4.174 -		}
   4.175 -
   4.176 -		[Test]
   4.177 -		public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibited()
   4.178 -		{
   4.179 -			Army army = new Army(mockRace, "Test", 1000);
   4.180 -			AddUnitOfTypeToArmy(unitType1, army);
   4.181 -			AddUnitOfTypeToArmy(unitType2, army);
   4.182 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.183 -			req.AddUnitTypeRequirement(unitType2);
   4.184 -			req.AddUnitTypeRequirement(unitType3);
   4.185 -			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1)."));
   4.186 -		}
   4.187 -
   4.188 -		[Test]
   4.189 -		public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy()
   4.190 -		{
   4.191 -			Army army = new Army(mockRace, "Test", 1000);
   4.192 -			AddUnitOfTypeToArmy(unitType1, army);
   4.193 -			AddUnitOfTypeToArmy(unitType3, army);
   4.194 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.195 -			req.AddUnitTypeRequirement(unitType2);
   4.196 -			req.AddUnitTypeRequirement(unitType3);
   4.197 -			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType3.Name + " (have 1)."));
   4.198 -		}
   4.199 -
   4.200 -		[Test]
   4.201 -		public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndBothUnitsInArmy()
   4.202 -		{
   4.203 -			Army army = new Army(mockRace, "Test", 1000);
   4.204 -			AddUnitOfTypeToArmy(unitType1, army);
   4.205 -			AddUnitOfTypeToArmy(unitType2, army);
   4.206 -			AddUnitOfTypeToArmy(unitType3, army);
   4.207 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.208 -			req.AddUnitTypeRequirement(unitType2);
   4.209 -			req.AddUnitTypeRequirement(unitType3);
   4.210 -			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1); 0 × " + unitType3.Name + " (have 1)."));
   4.211 -		}
   4.212 -
   4.213 -		[Test]
   4.214 -		public void TestAllowsAddMessageIsBlankForPass()
   4.215 -		{
   4.216 -			Army army = new Army(mockRace, "Test", 1000);
   4.217 -			AddUnitOfTypeToArmy(unitType1, army);
   4.218 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.219 -			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.Empty);
   4.220 -		}
   4.221 -
   4.222 -		[Test]
   4.223 -		public void TestAllowsAddMessageIsCorrectForFailWithOneUnitProhibited()
   4.224 -		{
   4.225 -			Army army = new Army(mockRace, "Test", 1000);
   4.226 -			AddUnitOfTypeToArmy(unitType1, army);
   4.227 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.228 -			req.AddUnitTypeRequirement(unitType2);
   4.229 -			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1)."));
   4.230 -		}
   4.231 -
   4.232 -		[Test]
   4.233 -		public void TestAllowsAddMessageIsCorrectForFailWithTwoOfOneUnitLimit()
   4.234 -		{
   4.235 -			Army army = new Army(mockRace, "Test", 1000);
   4.236 -			AddUnitOfTypeToArmy(unitType1, army);
   4.237 -			AddUnitOfTypeToArmy(unitType2, army);
   4.238 -			AddUnitOfTypeToArmy(unitType2, army);
   4.239 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.240 -			req.AddUnitTypeRequirement(unitType2, 2);
   4.241 -			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (would have 3)."));
   4.242 -		}
   4.243 -
   4.244 -		[Test]
   4.245 -		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited()
   4.246 +		public void TestAddingRequirementUnitFailsWithTwoUnitTypesProhibited()
   4.247  		{
   4.248  			Army army = new Army(mockRace, "Test", 1000);
   4.249  			AddUnitOfTypeToArmy(unitType1, army);
   4.250  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.251  			req.AddUnitTypeRequirement(unitType2);
   4.252  			req.AddUnitTypeRequirement(unitType3);
   4.253 -			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1)."));
   4.254 +			Assert_That__FailsAdding(req, unitType2, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).");
   4.255  		}
   4.256  
   4.257  		[Test]
   4.258 -		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy()
   4.259 +		public void TestAddingOtherRequirementUnitFailsWithTwoUnitTypesProhibited()
   4.260  		{
   4.261  			Army army = new Army(mockRace, "Test", 1000);
   4.262  			AddUnitOfTypeToArmy(unitType1, army);
   4.263 -			AddUnitOfTypeToArmy(unitType2, army);
   4.264  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.265  			req.AddUnitTypeRequirement(unitType2);
   4.266  			req.AddUnitTypeRequirement(unitType3);
   4.267 -			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)."));
   4.268 +			Assert_That__FailsAdding(req, unitType3, army, "Army cannot contain more than: 0 × " + unitType3.Name + " (would have 1).");
   4.269 +		}
   4.270 +
   4.271 +		[Test]
   4.272 +		public void TestAddingRequirementUnitFailsWithTwoUnitTypesProhibitedAndOneUnitTypeAlreadyInArmy()
   4.273 +		{
   4.274 +			Army army = new Army(mockRace, "Test", 1000);
   4.275 +			AddUnitOfTypeToArmy(unitType1, army);
   4.276 +			AddUnitOfTypeToArmy(unitType2, army);
   4.277 +			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.278 +			req.AddUnitTypeRequirement(unitType2);
   4.279 +			req.AddUnitTypeRequirement(unitType3);
   4.280 +			Assert_That__FailsAdding(req, unitType3, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1).");
   4.281  		}
   4.282  
   4.283  		[Test]
   4.284 -		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy()
   4.285 +		public void TestAddingRequirementUnitFailsWithTwoUnitTypesProhibitedAndOtherUnitTypeAlreadyInArmy()
   4.286  		{
   4.287  			Army army = new Army(mockRace, "Test", 1000);
   4.288  			AddUnitOfTypeToArmy(unitType1, army);
   4.289 @@ -277,17 +191,7 @@
   4.290  			UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   4.291  			req.AddUnitTypeRequirement(unitType2);
   4.292  			req.AddUnitTypeRequirement(unitType3);
   4.293 -			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)."));
   4.294 -		}
   4.295 -
   4.296 -		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
   4.297 -		{
   4.298 -			army.AddUnit(CreateUnitOfType(unitType, army));
   4.299 -		}
   4.300 -
   4.301 -		private static Unit CreateUnitOfType(UnitType unitType, Army army)
   4.302 -		{
   4.303 -			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
   4.304 +			Assert_That__FailsAdding(req, unitType2, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1).");
   4.305  		}
   4.306  	}
   4.307  }
     5.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Feb 25 17:02:38 2012 +0000
     5.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Feb 26 15:20:48 2012 +0000
     5.3 @@ -119,6 +119,7 @@
     5.4      <Compile Include="API\Objects\Requirement\UnitRequiresNUnitsForMUnitsRequirementTests.cs" />
     5.5      <Compile Include="API\Objects\Requirement\RequiresNUnitsForMObjectsRequirementTest.cs" />
     5.6      <Compile Include="API\Objects\Requirement\Mock\MockRequiresNUnitsForMObjectsRequirement.cs" />
     5.7 +    <Compile Include="API\Objects\Requirement\AbstractUnitRequirementTest.cs" />
     5.8    </ItemGroup>
     5.9    <ItemGroup>
    5.10      <None Include="app.config" />