changeset 133:f64742dde5f9

Re #27: Unit requirements * Start writing tests for requirement handler * Add mocks to support tests Note: NA test currently fails (expect pass but get fail)
author IBBoard <dev@ibboard.co.uk>
date Sun, 17 Apr 2011 20:07:57 +0000
parents 8f1af48e120c
children 4e1a477c38d8
files API/Objects/Requirement/Mock/AbstractFixedRequirement.cs API/Objects/Requirement/Mock/FailingRequirement.cs API/Objects/Requirement/Mock/NotApplicableRequirement.cs API/Objects/Requirement/Mock/PassingRequirement.cs API/Objects/Requirement/RequirementHandlerTests.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 6 files changed, 139 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Sun Apr 17 20:07:57 2011 +0000
@@ -0,0 +1,28 @@
+// This file (AbstractFixedRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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;
+
+namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock
+{
+	public class AbstractFixedRequirement : IRequirement
+	{
+		private Validation result;
+
+		public AbstractFixedRequirement(Validation fixedResult)
+		{
+			result = fixedResult;
+		}
+
+		public Validation AllowsAdding (WarFoundryObject wfObject, Army toArmy)
+		{
+			return result;
+		}
+
+		public Validation ValidatesArmy (Army army)
+		{
+			return result;
+		}
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Requirement/Mock/FailingRequirement.cs	Sun Apr 17 20:07:57 2011 +0000
@@ -0,0 +1,16 @@
+// This file (FailingRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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;
+
+namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock
+{
+	public class FailingRequirement : AbstractFixedRequirement
+	{
+		public FailingRequirement() : base(Validation.Failed)
+		{
+			//Do nothing special
+		}
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Requirement/Mock/NotApplicableRequirement.cs	Sun Apr 17 20:07:57 2011 +0000
@@ -0,0 +1,15 @@
+// This file (NotApplicableRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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;
+
+namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock
+{
+	public class NotApplicableRequirement : AbstractFixedRequirement
+	{
+		public NotApplicableRequirement() : base(Validation.NotApplicable)
+		{
+		}
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Requirement/Mock/PassingRequirement.cs	Sun Apr 17 20:07:57 2011 +0000
@@ -0,0 +1,15 @@
+// This file (PassingRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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;
+
+namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock
+{
+	public class PassingRequirement : AbstractFixedRequirement
+	{
+		public PassingRequirement() : base(Validation.Passed)
+		{
+		}
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Requirement/RequirementHandlerTests.cs	Sun Apr 17 20:07:57 2011 +0000
@@ -0,0 +1,58 @@
+// This file (RequirementHandlerTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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.Mock;
+using IBBoard.WarFoundry.API.Objects;
+using NUnit.Framework.SyntaxHelpers;
+using IBBoard.WarFoundry.API.Objects.Requirement.Mock;
+
+namespace IBBoard.WarFoundry.API.Objects.Requirement
+{
+	[TestFixture()]
+	public class RequirementHandlerTests
+	{
+		[Test()]
+		public void TestArmyWithNoRequirementsValidates()
+		{
+			MockRace race = new MockRace();
+			Army army = new Army(race, "test", 1000);
+			Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestArmyWithFailingRequirementFails()
+		{
+			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.ValidateArmy(army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestArmyWithPassingRequirementPasses()
+		{
+			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.ValidateArmy(army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestArmyWithNotApplicableRequirementPasses()
+		{
+			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.ValidateArmy(army), Is.EqualTo(Validation.Passed));
+		}
+	}
+}
+
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Apr 17 19:34:48 2011 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Apr 17 20:07:57 2011 +0000
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -97,6 +97,11 @@
     <Compile Include="API\Objects\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs" />
     <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirementTest.cs" />
     <Compile Include="API\Objects\RaceTests.cs" />
+    <Compile Include="API\Objects\Requirement\RequirementHandlerTests.cs" />
+    <Compile Include="API\Objects\Requirement\Mock\FailingRequirement.cs" />
+    <Compile Include="API\Objects\Requirement\Mock\AbstractFixedRequirement.cs" />
+    <Compile Include="API\Objects\Requirement\Mock\PassingRequirement.cs" />
+    <Compile Include="API\Objects\Requirement\Mock\NotApplicableRequirement.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
@@ -345,5 +350,6 @@
   </ItemGroup>
   <ItemGroup>
     <Folder Include="API\Savers\Xml\" />
+    <Folder Include="API\Objects\Requirement\Mock\" />
   </ItemGroup>
 </Project>
\ No newline at end of file