changeset 111:f0b488c9f29b

Re #27: Define unit requirements * Rebuild and add unit test for "no more than N" requirement
author IBBoard <dev@ibboard.co.uk>
date Wed, 30 Mar 2011 19:07:33 +0000
parents 788ef54f5b5a
children 53cfd5b3d1bd
files API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 2 files changed, 62 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Wed Mar 30 19:07:33 2011 +0000
     1.3 @@ -0,0 +1,61 @@
     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 RequiresNoMoreThanNOfUnitTypeRequirementTest
    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 RequiresNoMoreThanNOfUnitTypeRequirement(unitType2);
    1.40 +			Assert.That(req.AllowsAdding(unit, army), Is.True);
    1.41 +		}
    1.42 +
    1.43 +		[Test()]
    1.44 +		public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredIsNotAllowed()
    1.45 +		{
    1.46 +			Army army = new Army(mockRace, "Test", 1000);
    1.47 +			AddUnitOfTypeToArmy(unitType2, army);
    1.48 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.49 +			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2);
    1.50 +			Assert.That(req.AllowsAdding(unit, army), Is.False);
    1.51 +		}
    1.52 +
    1.53 +		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    1.54 +		{
    1.55 +			army.AddUnit(CreateUnitOfType(unitType, army));
    1.56 +		}
    1.57 +
    1.58 +		private static Unit CreateUnitOfType(UnitType unitType, Army army)
    1.59 +		{
    1.60 +			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
    1.61 +		}
    1.62 +	}
    1.63 +}
    1.64 +
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Tue Mar 29 19:51:08 2011 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Wed Mar 30 19:07:33 2011 +0000
     2.3 @@ -92,6 +92,7 @@
     2.4      <Compile Include="API\EventListeningWarFoundryLoader.cs" />
     2.5      <Compile Include="API\Savers\IWarFoundryFileSaverTests.cs" />
     2.6      <Compile Include="API\Objects\Requirement\RequiresAtLeastNUnitsRequirementTest.cs" />
     2.7 +    <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirementTest.cs" />
     2.8    </ItemGroup>
     2.9    <ItemGroup>
    2.10      <None Include="app.config" />