changeset 120:d186d46f0bae

Re #27: Unit requirements * Quick first draft of unit tests for "unit requires no more than X"
author IBBoard <dev@ibboard.co.uk>
date Wed, 06 Apr 2011 20:05:04 +0000
parents 5f389466e8a8
children 6f46fa3c47e5
files API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 2 files changed, 115 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Wed Apr 06 20:05:04 2011 +0000
     1.3 @@ -0,0 +1,113 @@
     1.4 +// This file (RequiresNoMoreThanNOfUnitTypeRequirementTest.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 +using NUnit.Framework;
     1.9 +using IBBoard.WarFoundry.API.Objects.Mock;
    1.10 +using NUnit.Framework.SyntaxHelpers;
    1.11 +
    1.12 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    1.13 +{
    1.14 +	[TestFixture()]
    1.15 +	public class UnitRequiresNoMoreThanNOfUnitTypeRequirementTest
    1.16 +	{
    1.17 +		private MockRace mockRace;
    1.18 +		private UnitType unitType1;
    1.19 +		private UnitType unitType2;
    1.20 +		private UnitType unitType3;
    1.21 +
    1.22 +		[TestFixtureSetUp()]
    1.23 +		public void SetupRace()
    1.24 +		{
    1.25 +			mockRace = new MockRace();
    1.26 +			unitType1 = new MockUnitType("type1", "Unit Type 1");
    1.27 +			mockRace.AddUnitType(unitType1);
    1.28 +			unitType2 = new MockUnitType("type2", "Unit Type 2");
    1.29 +			mockRace.AddUnitType(unitType2);
    1.30 +			unitType3 = new MockUnitType("type3", "Unit Type 3");
    1.31 +			mockRace.AddUnitType(unitType3);
    1.32 +		}
    1.33 +
    1.34 +		[Test()]
    1.35 +		public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
    1.36 +		{
    1.37 +			Army army = new Army(mockRace, "Test", 1000);
    1.38 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.39 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    1.40 +			req.AddUnitTypeRequirement(unitType2);
    1.41 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.42 +		}
    1.43 +
    1.44 +		[Test()]
    1.45 +		public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredIsNotAllowed()
    1.46 +		{
    1.47 +			Army army = new Army(mockRace, "Test", 1000);
    1.48 +			AddUnitOfTypeToArmy(unitType2, army);
    1.49 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.50 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    1.51 +			req.AddUnitTypeRequirement(unitType2);
    1.52 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    1.53 +		}
    1.54 +
    1.55 +		[Test()]
    1.56 +		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
    1.57 +		{
    1.58 +			Army army = new Army(mockRace, "Test", 1000);
    1.59 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    1.60 +			req.AddUnitTypeRequirement(unitType2);
    1.61 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    1.62 +		}
    1.63 +
    1.64 +		[Test()]
    1.65 +		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequiredIsNotAllowed()
    1.66 +		{
    1.67 +			Army army = new Army(mockRace, "Test", 1000);
    1.68 +			AddUnitOfTypeToArmy(unitType2, army);
    1.69 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    1.70 +			req.AddUnitTypeRequirement(unitType2);
    1.71 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    1.72 +		}
    1.73 +
    1.74 +		[Test()]
    1.75 +		public void TestAddingUnitTypeSetsLimit()
    1.76 +		{
    1.77 +			Army army = new Army(mockRace, "Test", 1000);
    1.78 +			AddUnitOfTypeToArmy(unitType2, army);
    1.79 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    1.80 +			req.AddUnitTypeRequirement(unitType2, 1);
    1.81 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    1.82 +		}
    1.83 +
    1.84 +		[Test()]
    1.85 +		public void TestAddingUnitTypeSetsLimitForFailure()
    1.86 +		{
    1.87 +			Army army = new Army(mockRace, "Test", 1000);
    1.88 +			AddUnitOfTypeToArmy(unitType2, army);
    1.89 +			AddUnitOfTypeToArmy(unitType2, army);
    1.90 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
    1.91 +			req.AddUnitTypeRequirement(unitType2, 1);
    1.92 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    1.93 +		}
    1.94 +
    1.95 +		[Test()]
    1.96 +		public void TestAddingUnitTypeDefaultsToNoMoreThanZero()
    1.97 +		{
    1.98 +			Army army = new Army(mockRace, "Test", 1000);
    1.99 +			AddUnitOfTypeToArmy(unitType2, army);
   1.100 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
   1.101 +			req.AddUnitTypeRequirement(unitType2);
   1.102 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
   1.103 +		}
   1.104 +
   1.105 +		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
   1.106 +		{
   1.107 +			army.AddUnit(CreateUnitOfType(unitType, army));
   1.108 +		}
   1.109 +
   1.110 +		private static Unit CreateUnitOfType(UnitType unitType, Army army)
   1.111 +		{
   1.112 +			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
   1.113 +		}
   1.114 +	}
   1.115 +}
   1.116 +
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Wed Apr 06 19:44:31 2011 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Wed Apr 06 20:05:04 2011 +0000
     2.3 @@ -17,7 +17,6 @@
     2.4      <OldToolsVersion>2.0</OldToolsVersion>
     2.5      <TargetFrameworkSubset>
     2.6      </TargetFrameworkSubset>
     2.7 -    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
     2.8      <IsWebBootstrapper>false</IsWebBootstrapper>
     2.9      <PublishUrl>publish\</PublishUrl>
    2.10      <Install>true</Install>
    2.11 @@ -92,9 +91,10 @@
    2.12      <Compile Include="API\EventListeningWarFoundryLoader.cs" />
    2.13      <Compile Include="API\Savers\IWarFoundryFileSaverTests.cs" />
    2.14      <Compile Include="API\Objects\Requirement\RequiresAtLeastNUnitsRequirementTest.cs" />
    2.15 -    <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirementTest.cs" />
    2.16      <Compile Include="API\Objects\Requirement\UnitRequiresAtLeastNUnitsRequirementTest.cs" />
    2.17      <Compile Include="API\Objects\Requirement\ValidationTests.cs" />
    2.18 +    <Compile Include="API\Objects\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs" />
    2.19 +    <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirementTest.cs" />
    2.20    </ItemGroup>
    2.21    <ItemGroup>
    2.22      <None Include="app.config" />