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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Sun Apr 17 20:07:57 2011 +0000
     1.3 @@ -0,0 +1,28 @@
     1.4 +// This file (AbstractFixedRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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 +
     1.9 +namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock
    1.10 +{
    1.11 +	public class AbstractFixedRequirement : IRequirement
    1.12 +	{
    1.13 +		private Validation result;
    1.14 +
    1.15 +		public AbstractFixedRequirement(Validation fixedResult)
    1.16 +		{
    1.17 +			result = fixedResult;
    1.18 +		}
    1.19 +
    1.20 +		public Validation AllowsAdding (WarFoundryObject wfObject, Army toArmy)
    1.21 +		{
    1.22 +			return result;
    1.23 +		}
    1.24 +
    1.25 +		public Validation ValidatesArmy (Army army)
    1.26 +		{
    1.27 +			return result;
    1.28 +		}
    1.29 +	}
    1.30 +}
    1.31 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/API/Objects/Requirement/Mock/FailingRequirement.cs	Sun Apr 17 20:07:57 2011 +0000
     2.3 @@ -0,0 +1,16 @@
     2.4 +// This file (FailingRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
     2.5 +// 
     2.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.
     2.7 +using System;
     2.8 +
     2.9 +namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock
    2.10 +{
    2.11 +	public class FailingRequirement : AbstractFixedRequirement
    2.12 +	{
    2.13 +		public FailingRequirement() : base(Validation.Failed)
    2.14 +		{
    2.15 +			//Do nothing special
    2.16 +		}
    2.17 +	}
    2.18 +}
    2.19 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/API/Objects/Requirement/Mock/NotApplicableRequirement.cs	Sun Apr 17 20:07:57 2011 +0000
     3.3 @@ -0,0 +1,15 @@
     3.4 +// This file (NotApplicableRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
     3.5 +// 
     3.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.
     3.7 +using System;
     3.8 +
     3.9 +namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock
    3.10 +{
    3.11 +	public class NotApplicableRequirement : AbstractFixedRequirement
    3.12 +	{
    3.13 +		public NotApplicableRequirement() : base(Validation.NotApplicable)
    3.14 +		{
    3.15 +		}
    3.16 +	}
    3.17 +}
    3.18 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/API/Objects/Requirement/Mock/PassingRequirement.cs	Sun Apr 17 20:07:57 2011 +0000
     4.3 @@ -0,0 +1,15 @@
     4.4 +// This file (PassingRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
     4.5 +// 
     4.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.
     4.7 +using System;
     4.8 +
     4.9 +namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock
    4.10 +{
    4.11 +	public class PassingRequirement : AbstractFixedRequirement
    4.12 +	{
    4.13 +		public PassingRequirement() : base(Validation.Passed)
    4.14 +		{
    4.15 +		}
    4.16 +	}
    4.17 +}
    4.18 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/API/Objects/Requirement/RequirementHandlerTests.cs	Sun Apr 17 20:07:57 2011 +0000
     5.3 @@ -0,0 +1,58 @@
     5.4 +// This file (RequirementHandlerTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
     5.5 +// 
     5.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.
     5.7 +using System;
     5.8 +using NUnit.Framework;
     5.9 +using IBBoard.WarFoundry.API.Objects.Mock;
    5.10 +using IBBoard.WarFoundry.API.Objects;
    5.11 +using NUnit.Framework.SyntaxHelpers;
    5.12 +using IBBoard.WarFoundry.API.Objects.Requirement.Mock;
    5.13 +
    5.14 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    5.15 +{
    5.16 +	[TestFixture()]
    5.17 +	public class RequirementHandlerTests
    5.18 +	{
    5.19 +		[Test()]
    5.20 +		public void TestArmyWithNoRequirementsValidates()
    5.21 +		{
    5.22 +			MockRace race = new MockRace();
    5.23 +			Army army = new Army(race, "test", 1000);
    5.24 +			Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed));
    5.25 +		}
    5.26 +
    5.27 +		[Test()]
    5.28 +		public void TestArmyWithFailingRequirementFails()
    5.29 +		{
    5.30 +			MockRace race = new MockRace();
    5.31 +			MockUnitType mockUnitType = new MockUnitType();
    5.32 +			mockUnitType.AddRequirement(new FailingRequirement());
    5.33 +			race.AddUnitType(mockUnitType);
    5.34 +			Army army = new Army(race, "test", 1000);
    5.35 +			Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Failed));
    5.36 +		}
    5.37 +
    5.38 +		[Test()]
    5.39 +		public void TestArmyWithPassingRequirementPasses()
    5.40 +		{
    5.41 +			MockRace race = new MockRace();
    5.42 +			MockUnitType mockUnitType = new MockUnitType();
    5.43 +			mockUnitType.AddRequirement(new PassingRequirement());
    5.44 +			race.AddUnitType(mockUnitType);
    5.45 +			Army army = new Army(race, "test", 1000);
    5.46 +			Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed));
    5.47 +		}
    5.48 +
    5.49 +		[Test()]
    5.50 +		public void TestArmyWithNotApplicableRequirementPasses()
    5.51 +		{
    5.52 +			MockRace race = new MockRace();
    5.53 +			MockUnitType mockUnitType = new MockUnitType();
    5.54 +			mockUnitType.AddRequirement(new NotApplicableRequirement());
    5.55 +			race.AddUnitType(mockUnitType);
    5.56 +			Army army = new Army(race, "test", 1000);
    5.57 +			Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed));
    5.58 +		}
    5.59 +	}
    5.60 +}
    5.61 +
     6.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Apr 17 19:34:48 2011 +0000
     6.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Apr 17 20:07:57 2011 +0000
     6.3 @@ -1,4 +1,4 @@
     6.4 -<?xml version="1.0" encoding="utf-8"?>
     6.5 +<?xml version="1.0" encoding="utf-8"?>
     6.6  <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
     6.7    <PropertyGroup>
     6.8      <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     6.9 @@ -97,6 +97,11 @@
    6.10      <Compile Include="API\Objects\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs" />
    6.11      <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirementTest.cs" />
    6.12      <Compile Include="API\Objects\RaceTests.cs" />
    6.13 +    <Compile Include="API\Objects\Requirement\RequirementHandlerTests.cs" />
    6.14 +    <Compile Include="API\Objects\Requirement\Mock\FailingRequirement.cs" />
    6.15 +    <Compile Include="API\Objects\Requirement\Mock\AbstractFixedRequirement.cs" />
    6.16 +    <Compile Include="API\Objects\Requirement\Mock\PassingRequirement.cs" />
    6.17 +    <Compile Include="API\Objects\Requirement\Mock\NotApplicableRequirement.cs" />
    6.18    </ItemGroup>
    6.19    <ItemGroup>
    6.20      <None Include="app.config" />
    6.21 @@ -345,5 +350,6 @@
    6.22    </ItemGroup>
    6.23    <ItemGroup>
    6.24      <Folder Include="API\Savers\Xml\" />
    6.25 +    <Folder Include="API\Objects\Requirement\Mock\" />
    6.26    </ItemGroup>
    6.27  </Project>
    6.28 \ No newline at end of file