changeset 205:d39682a98adf

Re #379: Fix validation of requirements to check for unit * Add unit tests for army object * Update tests that check the message
author IBBoard <dev@ibboard.co.uk>
date Sun, 29 Jan 2012 19:40:19 +0000
parents ea104de9189e
children 78ba834cb1f7
files API/Objects/ArmyTests.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs
diffstat 2 files changed, 80 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/ArmyTests.cs	Sun Jan 29 19:40:19 2012 +0000
@@ -0,0 +1,75 @@
+// This file (ArmyTests.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 IBBoard.WarFoundry.API.Objects.Requirement.Mock;
+using NUnit.Framework.SyntaxHelpers;
+using System.Collections.Generic;
+using IBBoard.WarFoundry.API.Objects.Requirement;
+using IBBoard.WarFoundry.API.Objects.Mock;
+
+namespace IBBoard.WarFoundry.API.Objects
+{
+	[TestFixture()]
+	public class ArmyTests
+	{
+		private MockRace mockRace;
+		private UnitType unitType1;
+		private IRequirement unitType1Requirement;
+		private UnitType unitType2;
+		private IRequirement unitType2Requirement;
+		private UnitType unitType3;
+		private IRequirement unitType3Requirement;
+
+		[TestFixtureSetUp()]
+		public void SetupRace()
+		{
+			mockRace = new MockRace();
+			unitType1 = new MockUnitType("type1", "Unit Type 1");
+			mockRace.AddUnitType(unitType1);
+			unitType1Requirement = new PassingRequirement();
+			unitType1.AddRequirement(unitType1Requirement);
+			unitType2 = new MockUnitType("type2", "Unit Type 2");
+			mockRace.AddUnitType(unitType2);
+			unitType2Requirement = new FailingRequirement();
+			unitType2.AddRequirement(unitType2Requirement);
+			unitType3 = new MockUnitType("type3", "Unit Type 3");
+			mockRace.AddUnitType(unitType3);
+			unitType3Requirement = new NotApplicableRequirement();
+			unitType3.AddRequirement(unitType3Requirement);
+		}
+
+		[Test()]
+		public void TestGetRequirementsGetsAllRaceRequirements()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			ICollection<IRequirement> requirements = army.GetRequirements();
+			Assert.That(requirements, Has.Count(3));
+			Assert.That(requirements, Has.Member(unitType1Requirement));
+			Assert.That(requirements, Has.Member(unitType2Requirement));
+			Assert.That(requirements, Has.Member(unitType3Requirement));
+		}
+
+		[Test()]
+		public void TestGetRequirementsGetsJustAddedUnitRequirementsWithEmptyArmy()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			ICollection<IRequirement> requirements = army.GetAddingUnitRequirements(unitType1);
+			Assert.That(requirements, Has.Count(1));
+			Assert.That(requirements, Has.Member(unitType1Requirement));
+		}
+
+		[Test()]
+		public void TestGetRequirementsGetsAddedUnitRequirementsAndExistingUnitRequirements()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			army.AddUnit(new Unit(unitType1, army.GetCategory(unitType1.MainCategory)));
+			ICollection<IRequirement> requirements = army.GetAddingUnitRequirements(unitType2);
+			Assert.That(requirements, Has.Count(2));
+			Assert.That(requirements, Has.Member(unitType1Requirement));
+			Assert.That(requirements, Has.Member(unitType2Requirement));
+		}
+	}
+}
+
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sat Jan 28 16:58:42 2012 +0000
+++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun Jan 29 19:40:19 2012 +0000
@@ -277,7 +277,7 @@
 			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)."));
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army would contain " + unitType1.Name + " and so must contain: 2 × " + unitType2.Name + " (would have 1)."));
 		}
 
 		[Test]
@@ -287,7 +287,7 @@
 			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)."));
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army would contain " + unitType1.Name + " and so must contain: 1 × " + unitType3.Name + " (would have 0)."));
 		}
 
 		[Test]
@@ -297,7 +297,7 @@
 			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)."));
+			Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army would contain " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (would have 0)."));
 		}
 
 		[Test]
@@ -308,7 +308,7 @@
 			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)."));
+			Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army would contain " + unitType1.Name + " and so must contain: 1 × " + unitType3.Name + " (would have 0)."));
 		}
 
 		[Test]
@@ -319,7 +319,7 @@
 			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)."));
+			Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army would contain " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (would have 0)."));
 		}
 
 		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)