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 diff
     1.1 --- a/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Sun May 01 19:14:38 2011 +0000
     1.2 +++ b/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Sun May 01 19:17:11 2011 +0000
     1.3 @@ -28,6 +28,11 @@
     1.4  		{
     1.5  			return (result.Equals(Validation.Failed)) ? "Validation failed" : "";
     1.6  		}
     1.7 +
     1.8 +		public string GetAllowsAddingMessage (UnitType toAdd, Army toArmy)
     1.9 +		{
    1.10 +			return (result.Equals(Validation.Failed)) ? "Validation failed" : "";
    1.11 +		}
    1.12  	}
    1.13  }
    1.14  
     2.1 --- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 19:14:38 2011 +0000
     2.2 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 19:17:11 2011 +0000
     2.3 @@ -204,6 +204,88 @@
     2.4  			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0); 1 × " + unitType2.Name + " (have 0)."));
     2.5  		}
     2.6  
     2.7 +		[Test]
     2.8 +		public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit()
     2.9 +		{
    2.10 +			Army army = new Army(mockRace, "Test", 1000);
    2.11 +			AddUnitOfTypeToArmy(unitType1, army);
    2.12 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    2.13 +			req.AddUnitTypeRequirement(unitType1);
    2.14 +			req.AddUnitTypeRequirement(unitType2);
    2.15 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (have 0)."));
    2.16 +		}
    2.17 +
    2.18 +		[Test]
    2.19 +		public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit()
    2.20 +		{
    2.21 +			Army army = new Army(mockRace, "Test", 1000);
    2.22 +			AddUnitOfTypeToArmy(unitType2, army);
    2.23 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    2.24 +			req.AddUnitTypeRequirement(unitType1);
    2.25 +			req.AddUnitTypeRequirement(unitType2);
    2.26 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0)."));
    2.27 +		}
    2.28 +
    2.29 +		[Test]
    2.30 +		public void TestAllowsAddingMessageIsBlankForPass()
    2.31 +		{
    2.32 +			Army army = new Army(mockRace, "Test", 1000);
    2.33 +			AddUnitOfTypeToArmy(unitType1, army);
    2.34 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1);
    2.35 +			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.Empty);
    2.36 +		}
    2.37 +
    2.38 +		[Test]
    2.39 +		public void TestAllowsAddingMessageIsCorrectForFailWithTwoOfOneUnitRequired()
    2.40 +		{
    2.41 +			Army army = new Army(mockRace, "Test", 1000);
    2.42 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    2.43 +			req.AddUnitTypeRequirement(unitType1, 2);
    2.44 +			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 2 × " + unitType1.Name + " (would have 1)."));
    2.45 +		}
    2.46 +
    2.47 +		[Test]
    2.48 +		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequired()
    2.49 +		{
    2.50 +			Army army = new Army(mockRace, "Test", 1000);
    2.51 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    2.52 +			req.AddUnitTypeRequirement(unitType1);
    2.53 +			req.AddUnitTypeRequirement(unitType2);
    2.54 +			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0)."));
    2.55 +		}
    2.56 +
    2.57 +		[Test]
    2.58 +		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredOtherUnit()
    2.59 +		{
    2.60 +			Army army = new Army(mockRace, "Test", 1000);
    2.61 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    2.62 +			req.AddUnitTypeRequirement(unitType1);
    2.63 +			req.AddUnitTypeRequirement(unitType2);
    2.64 +			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (would have 0)."));
    2.65 +		}
    2.66 +
    2.67 +		[Test]
    2.68 +		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit()
    2.69 +		{
    2.70 +			Army army = new Army(mockRace, "Test", 1000);
    2.71 +			AddUnitOfTypeToArmy(unitType1, army);
    2.72 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    2.73 +			req.AddUnitTypeRequirement(unitType1);
    2.74 +			req.AddUnitTypeRequirement(unitType2);
    2.75 +			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0)."));
    2.76 +		}
    2.77 +
    2.78 +		[Test]
    2.79 +		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit()
    2.80 +		{
    2.81 +			Army army = new Army(mockRace, "Test", 1000);
    2.82 +			AddUnitOfTypeToArmy(unitType2, army);
    2.83 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    2.84 +			req.AddUnitTypeRequirement(unitType1);
    2.85 +			req.AddUnitTypeRequirement(unitType2);
    2.86 +			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (would have 0)."));
    2.87 +		}
    2.88 +
    2.89  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    2.90  		{
    2.91  			army.AddUnit(CreateUnitOfType(unitType, army));
     3.1 --- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sun May 01 19:14:38 2011 +0000
     3.2 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sun May 01 19:17:11 2011 +0000
     3.3 @@ -173,6 +173,65 @@
     3.4  			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1)."));
     3.5  		}
     3.6  
     3.7 +		[Test]
     3.8 +		public void TestAllowsAddMessageIsBlankForPass()
     3.9 +		{
    3.10 +			Army army = new Army(mockRace, "Test", 1000);
    3.11 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    3.12 +			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.Empty);
    3.13 +		}
    3.14 +
    3.15 +		[Test]
    3.16 +		public void TestAllowsAddMessageIsCorrectForFailWithOneUnitProhibited()
    3.17 +		{
    3.18 +			Army army = new Army(mockRace, "Test", 1000);
    3.19 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    3.20 +			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (would have 1)."));
    3.21 +		}
    3.22 +
    3.23 +		[Test]
    3.24 +		public void TestAllowsAddMessageIsCorrectForFailWithTwoOfOneUnitLimit()
    3.25 +		{
    3.26 +			Army army = new Army(mockRace, "Test", 1000);
    3.27 +			AddUnitOfTypeToArmy(unitType1, army);
    3.28 +			AddUnitOfTypeToArmy(unitType1, army);
    3.29 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
    3.30 +			req.AddUnitTypeRequirement(unitType1, 2);
    3.31 +			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType1.Name + " (would have 3)."));
    3.32 +		}
    3.33 +
    3.34 +		[Test]
    3.35 +		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited()
    3.36 +		{
    3.37 +			Army army = new Army(mockRace, "Test", 1000);
    3.38 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
    3.39 +			req.AddUnitTypeRequirement(unitType1);
    3.40 +			req.AddUnitTypeRequirement(unitType2);
    3.41 +			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (would have 1)."));
    3.42 +		}
    3.43 +
    3.44 +		[Test]
    3.45 +		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy()
    3.46 +		{
    3.47 +			Army army = new Army(mockRace, "Test", 1000);
    3.48 +			AddUnitOfTypeToArmy(unitType1, army);
    3.49 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
    3.50 +			req.AddUnitTypeRequirement(unitType1);
    3.51 +			req.AddUnitTypeRequirement(unitType2);
    3.52 +			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)."));
    3.53 +		}
    3.54 +
    3.55 +		[Test]
    3.56 +		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy()
    3.57 +		{
    3.58 +			Army army = new Army(mockRace, "Test", 1000);
    3.59 +			AddUnitOfTypeToArmy(unitType2, army);
    3.60 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
    3.61 +			req.AddUnitTypeRequirement(unitType1);
    3.62 +			req.AddUnitTypeRequirement(unitType2);
    3.63 +			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)."));
    3.64 +		}
    3.65 +
    3.66  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    3.67  		{
    3.68  			army.AddUnit(CreateUnitOfType(unitType, army));
     4.1 --- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 19:14:38 2011 +0000
     4.2 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun May 01 19:17:11 2011 +0000
     4.3 @@ -262,6 +262,66 @@
     4.4  			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)."));
     4.5  		}
     4.6  
     4.7 +		[Test]
     4.8 +		public void TestAllowsAddingMessageIsBlankForPass()
     4.9 +		{
    4.10 +			Army army = new Army(mockRace, "Test", 1000);
    4.11 +			AddUnitOfTypeToArmy(unitType1, army);
    4.12 +			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    4.13 +			Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.Empty);
    4.14 +		}
    4.15 +
    4.16 +		[Test]
    4.17 +		public void TestAllowsAddingMessageIsCorrectForFailWithTwoOfOneUnitRequired()
    4.18 +		{
    4.19 +			Army army = new Army(mockRace, "Test", 1000);
    4.20 +			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    4.21 +			req.AddUnitTypeRequirement(unitType2, 2);
    4.22 +			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 2 × " + unitType2.Name + " (would have 1)."));
    4.23 +		}
    4.24 +
    4.25 +		[Test]
    4.26 +		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequired()
    4.27 +		{
    4.28 +			Army army = new Army(mockRace, "Test", 1000);
    4.29 +			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    4.30 +			req.AddUnitTypeRequirement(unitType2);
    4.31 +			req.AddUnitTypeRequirement(unitType3);
    4.32 +			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType3.Name + " (would have 0)."));
    4.33 +		}
    4.34 +
    4.35 +		[Test]
    4.36 +		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredOtherUnit()
    4.37 +		{
    4.38 +			Army army = new Army(mockRace, "Test", 1000);
    4.39 +			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    4.40 +			req.AddUnitTypeRequirement(unitType2);
    4.41 +			req.AddUnitTypeRequirement(unitType3);
    4.42 +			Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (would have 0)."));
    4.43 +		}
    4.44 +
    4.45 +		[Test]
    4.46 +		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit()
    4.47 +		{
    4.48 +			Army army = new Army(mockRace, "Test", 1000);
    4.49 +			AddUnitOfTypeToArmy(unitType2, army);
    4.50 +			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    4.51 +			req.AddUnitTypeRequirement(unitType2);
    4.52 +			req.AddUnitTypeRequirement(unitType3);
    4.53 +			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType3.Name + " (would have 0)."));
    4.54 +		}
    4.55 +
    4.56 +		[Test]
    4.57 +		public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit()
    4.58 +		{
    4.59 +			Army army = new Army(mockRace, "Test", 1000);
    4.60 +			AddUnitOfTypeToArmy(unitType3, army);
    4.61 +			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    4.62 +			req.AddUnitTypeRequirement(unitType2);
    4.63 +			req.AddUnitTypeRequirement(unitType3);
    4.64 +			Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (would have 0)."));
    4.65 +		}
    4.66 +
    4.67  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    4.68  		{
    4.69  			army.AddUnit(CreateUnitOfType(unitType, army));
     5.1 --- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sun May 01 19:14:38 2011 +0000
     5.2 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sun May 01 19:17:11 2011 +0000
     5.3 @@ -214,6 +214,72 @@
     5.4  			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)."));
     5.5  		}
     5.6  
     5.7 +		[Test]
     5.8 +		public void TestAllowsAddMessageIsBlankForPass()
     5.9 +		{
    5.10 +			Army army = new Army(mockRace, "Test", 1000);
    5.11 +			AddUnitOfTypeToArmy(unitType1, army);
    5.12 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    5.13 +			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.Empty);
    5.14 +		}
    5.15 +
    5.16 +		[Test]
    5.17 +		public void TestAllowsAddMessageIsCorrectForFailWithOneUnitProhibited()
    5.18 +		{
    5.19 +			Army army = new Army(mockRace, "Test", 1000);
    5.20 +			AddUnitOfTypeToArmy(unitType1, army);
    5.21 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    5.22 +			req.AddUnitTypeRequirement(unitType2);
    5.23 +			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so cannot contain more than: 0 × " + unitType2.Name + " (would have 1)."));
    5.24 +		}
    5.25 +
    5.26 +		[Test]
    5.27 +		public void TestAllowsAddMessageIsCorrectForFailWithTwoOfOneUnitLimit()
    5.28 +		{
    5.29 +			Army army = new Army(mockRace, "Test", 1000);
    5.30 +			AddUnitOfTypeToArmy(unitType1, army);
    5.31 +			AddUnitOfTypeToArmy(unitType2, army);
    5.32 +			AddUnitOfTypeToArmy(unitType2, army);
    5.33 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    5.34 +			req.AddUnitTypeRequirement(unitType2, 2);
    5.35 +			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so cannot contain more than: 2 × " + unitType2.Name + " (would have 3)."));
    5.36 +		}
    5.37 +
    5.38 +		[Test]
    5.39 +		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited()
    5.40 +		{
    5.41 +			Army army = new Army(mockRace, "Test", 1000);
    5.42 +			AddUnitOfTypeToArmy(unitType1, army);
    5.43 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    5.44 +			req.AddUnitTypeRequirement(unitType2);
    5.45 +			req.AddUnitTypeRequirement(unitType3);
    5.46 +			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army contains " + unitType1.Name + " and so cannot contain more than: 0 × " + unitType2.Name + " (would have 1)."));
    5.47 +		}
    5.48 +
    5.49 +		[Test]
    5.50 +		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy()
    5.51 +		{
    5.52 +			Army army = new Army(mockRace, "Test", 1000);
    5.53 +			AddUnitOfTypeToArmy(unitType1, army);
    5.54 +			AddUnitOfTypeToArmy(unitType2, army);
    5.55 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    5.56 +			req.AddUnitTypeRequirement(unitType2);
    5.57 +			req.AddUnitTypeRequirement(unitType3);
    5.58 +			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)."));
    5.59 +		}
    5.60 +
    5.61 +		[Test]
    5.62 +		public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy()
    5.63 +		{
    5.64 +			Army army = new Army(mockRace, "Test", 1000);
    5.65 +			AddUnitOfTypeToArmy(unitType1, army);
    5.66 +			AddUnitOfTypeToArmy(unitType3, army);
    5.67 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    5.68 +			req.AddUnitTypeRequirement(unitType2);
    5.69 +			req.AddUnitTypeRequirement(unitType3);
    5.70 +			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)."));
    5.71 +		}
    5.72 +
    5.73  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    5.74  		{
    5.75  			army.AddUnit(CreateUnitOfType(unitType, army));