changeset 135:8c3bba80a25e

Re #27: Unit requirements * Add tests for mixed requirements * Add tests for adding units
author IBBoard <dev@ibboard.co.uk>
date Mon, 25 Apr 2011 10:31:49 +0000
parents 4e1a477c38d8
children d28c3c1ec1ec
files API/Objects/Requirement/RequirementHandlerTests.cs
diffstat 1 files changed, 113 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/Requirement/RequirementHandlerTests.cs	Fri Apr 22 10:30:26 2011 +0000
+++ b/API/Objects/Requirement/RequirementHandlerTests.cs	Mon Apr 25 10:31:49 2011 +0000
@@ -53,6 +53,119 @@
 			Army army = new Army(race, "test", 1000);
 			Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed));
 		}
+
+		[Test()]
+		public void TestArmyWithMixedRequirementsWithFailFails()
+		{
+			MockRace race = new MockRace();
+			MockUnitType mockUnitType = new MockUnitType();
+			mockUnitType.AddRequirement(new PassingRequirement());
+			mockUnitType.AddRequirement(new FailingRequirement());
+			race.AddUnitType(mockUnitType);
+			Army army = new Army(race, "test", 1000);
+			Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestArmyWithMixedRequirementsWithFailInOtherOrderFails()
+		{
+			MockRace race = new MockRace();
+			MockUnitType mockUnitType = new MockUnitType();
+			mockUnitType.AddRequirement(new FailingRequirement());
+			mockUnitType.AddRequirement(new PassingRequirement());
+			race.AddUnitType(mockUnitType);
+			Army army = new Army(race, "test", 1000);
+			Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestArmyWithMixedRequirementsWithNoFailsPasses()
+		{
+			MockRace race = new MockRace();
+			MockUnitType mockUnitType = new MockUnitType();
+			mockUnitType.AddRequirement(new PassingRequirement());
+			mockUnitType.AddRequirement(new NotApplicableRequirement());
+			race.AddUnitType(mockUnitType);
+			Army army = new Army(race, "test", 1000);
+			Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestCanAddToArmyWithNoRequirementsValidates()
+		{
+			MockRace race = new MockRace();
+			Army army = new Army(race, "test", 1000);
+			Assert.That(RequirementHandler.AllowsAdding(new MockUnitType(), army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestCanAddToArmyWithFailingRequirementFails()
+		{
+			MockRace race = new MockRace();
+			MockUnitType mockUnitType = new MockUnitType();
+			mockUnitType.AddRequirement(new FailingRequirement());
+			race.AddUnitType(mockUnitType);
+			Army army = new Army(race, "test", 1000);
+			Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestCanAddToArmyWithPassingRequirementPasses()
+		{
+			MockRace race = new MockRace();
+			MockUnitType mockUnitType = new MockUnitType();
+			mockUnitType.AddRequirement(new PassingRequirement());
+			race.AddUnitType(mockUnitType);
+			Army army = new Army(race, "test", 1000);
+			Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestCanAddToArmyWithNotApplicableRequirementPasses()
+		{
+			MockRace race = new MockRace();
+			MockUnitType mockUnitType = new MockUnitType();
+			mockUnitType.AddRequirement(new NotApplicableRequirement());
+			race.AddUnitType(mockUnitType);
+			Army army = new Army(race, "test", 1000);
+			Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestCanAddToArmyWithMixedRequirementsWithFailFails()
+		{
+			MockRace race = new MockRace();
+			MockUnitType mockUnitType = new MockUnitType();
+			mockUnitType.AddRequirement(new PassingRequirement());
+			mockUnitType.AddRequirement(new FailingRequirement());
+			race.AddUnitType(mockUnitType);
+			Army army = new Army(race, "test", 1000);
+			Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestCanAddToArmyWithMixedRequirementsWithFailInOtherOrderFails()
+		{
+			MockRace race = new MockRace();
+			MockUnitType mockUnitType = new MockUnitType();
+			mockUnitType.AddRequirement(new FailingRequirement());
+			mockUnitType.AddRequirement(new PassingRequirement());
+			race.AddUnitType(mockUnitType);
+			Army army = new Army(race, "test", 1000);
+			Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestCanAddToArmyWithMixedRequirementsWithNoFailsPasses()
+		{
+			MockRace race = new MockRace();
+			MockUnitType mockUnitType = new MockUnitType();
+			mockUnitType.AddRequirement(new PassingRequirement());
+			mockUnitType.AddRequirement(new NotApplicableRequirement());
+			race.AddUnitType(mockUnitType);
+			Army army = new Army(race, "test", 1000);
+			Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Passed));
+		}
 	}
 }