changeset 188:0762766bd3f2

Re #350: Add requirement to allow N of unit for specific other units * Remove static access to mock race - it broke tests * Add first tests for new requirement
author IBBoard <dev@ibboard.co.uk>
date Tue, 29 Nov 2011 20:56:34 +0000
parents cd2aeab2357f
children eea440e5891b
files API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 3 files changed, 122 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sun Nov 13 20:53:55 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Tue Nov 29 20:56:34 2011 +0000
     1.3 @@ -22,7 +22,7 @@
     1.4  		[TestFixtureSetUp()]
     1.5  		public void SetupRace()
     1.6  		{
     1.7 -			mockRace = MockRace.GetMockRace();
     1.8 +			mockRace = new MockRace();
     1.9  			unitType1 = new MockUnitType("type1", "Unit Type 1");
    1.10  			mockRace.AddUnitType(unitType1);
    1.11  			unitType2 = new MockUnitType("type2", "Unit Type 2");
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Tue Nov 29 20:56:34 2011 +0000
     2.3 @@ -0,0 +1,120 @@
     2.4 +// This file (UnitRequiresNUnitsForMUnitsRequirement.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 +using NUnit.Framework;
     2.9 +using IBBoard.WarFoundry.API.Objects.Mock;
    2.10 +using NUnit.Framework.SyntaxHelpers;
    2.11 +using System.Reflection;
    2.12 +using IBBoard.NUnit;
    2.13 +using IBBoard.WarFoundry.API.Factories;
    2.14 +
    2.15 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    2.16 +{
    2.17 +	[TestFixture()]
    2.18 +	public class RequiresNUnitsForMUnitsRequirementTest : AbstractEqualityTest<RequiresNUnitsForMUnitsRequirement>
    2.19 +	{
    2.20 +		private MockRace mockRace;
    2.21 +		private UnitType unitType1;
    2.22 +		private UnitType unitType2;
    2.23 +		private UnitType unitType3;
    2.24 +
    2.25 +		[TestFixtureSetUp()]
    2.26 +		public void SetupRace()
    2.27 +		{
    2.28 +			mockRace = MockRace.GetMockRace();
    2.29 +			unitType1 = new MockUnitType("type1", "Unit Type 1");
    2.30 +			mockRace.AddUnitType(unitType1);
    2.31 +			unitType2 = new MockUnitType("type2", "Unit Type 2");
    2.32 +			mockRace.AddUnitType(unitType2);
    2.33 +			unitType3 = new MockUnitType("type3", "Unit Type 3");
    2.34 +			mockRace.AddUnitType(unitType3);
    2.35 +		}
    2.36 +
    2.37 +		[Test()]
    2.38 +		public void TestAddingUnrelatedUnitWithNoUnitsAndOneUnitTypeRequiredIsNA()
    2.39 +		{
    2.40 +			Army army = new Army(mockRace, "Test", 1000);
    2.41 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2);
    2.42 +			Unit unit = CreateUnitOfType(unitType3, army);
    2.43 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable));
    2.44 +		}
    2.45 +
    2.46 +		[Test()]
    2.47 +		public void TestAddingOneUnitWithOneUnitTypeRequiredAndOneUnitOfTypePasses()
    2.48 +		{
    2.49 +			Army army = new Army(mockRace, "Test", 1000);
    2.50 +			AddUnitOfTypeToArmy(unitType2, army);
    2.51 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2);
    2.52 +			Unit unit = CreateUnitOfType(unitType1, army);
    2.53 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    2.54 +		}
    2.55 +
    2.56 +		[Test()]
    2.57 +		public void TestAddingOneUnitWithOneUnitTypeRequiredAndNoUnitOfTypeFails()
    2.58 +		{
    2.59 +			Army army = new Army(mockRace, "Test", 1000);
    2.60 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2);
    2.61 +			Unit unit = CreateUnitOfType(unitType1, army);
    2.62 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    2.63 +		}
    2.64 +
    2.65 +		[Test()]
    2.66 +		public void TestAddingTwoUnitsWithOneUnitTypeRequiredAndOneUnitOfTypeFails()
    2.67 +		{
    2.68 +			Army army = new Army(mockRace, "Test", 1000);
    2.69 +			AddUnitOfTypeToArmy(unitType2, army);
    2.70 +			AddUnitOfTypeToArmy(unitType1, army);
    2.71 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2);
    2.72 +			Unit unit = CreateUnitOfType(unitType1, army);
    2.73 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    2.74 +		}
    2.75 +
    2.76 +		[Test()]
    2.77 +		public void TestAddingTwoUnitsWithTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypePasses()
    2.78 +		{
    2.79 +			Army army = new Army(mockRace, "Test", 1000);
    2.80 +			AddUnitOfTypeToArmy(unitType2, army);
    2.81 +			AddUnitOfTypeToArmy(unitType1, army);
    2.82 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    2.83 +			req.AddUnitTypeRequirement(unitType2, 1, 2);
    2.84 +			Unit unit = CreateUnitOfType(unitType1, army);
    2.85 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    2.86 +		}
    2.87 +
    2.88 +		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    2.89 +		{
    2.90 +			army.AddUnit(CreateUnitOfType(unitType, army));
    2.91 +		}
    2.92 +
    2.93 +		private static Unit CreateUnitOfType(UnitType unitType, Army army)
    2.94 +		{
    2.95 +			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
    2.96 +		}
    2.97 +
    2.98 +		public override RequiresNUnitsForMUnitsRequirement GetObject()
    2.99 +		{
   2.100 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType3);
   2.101 +			req.AddUnitTypeRequirement(unitType1, 2, 3);
   2.102 +			return req;
   2.103 +		}
   2.104 +
   2.105 +		public override RequiresNUnitsForMUnitsRequirement GetSameObject()
   2.106 +		{
   2.107 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType3);
   2.108 +			req.AddUnitTypeRequirement(unitType1, 2, 3);
   2.109 +			return req;
   2.110 +		}
   2.111 +
   2.112 +		public override RequiresNUnitsForMUnitsRequirement GetDifferentObject()
   2.113 +		{
   2.114 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType3);
   2.115 +			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
   2.116 +			GameSystem gameSystem = new GameSystem("system", "system", factory);
   2.117 +			Race race = new Race("race", "race", gameSystem, factory);
   2.118 +			req.AddUnitTypeRequirement(new UnitType("id2", "Type 2", race), 2, 3);
   2.119 +			return req;
   2.120 +		}
   2.121 +	}
   2.122 +}
   2.123 +
     3.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Nov 13 20:53:55 2011 +0000
     3.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Tue Nov 29 20:56:34 2011 +0000
     3.3 @@ -113,6 +113,7 @@
     3.4      <Compile Include="API\Objects\UnitEquipmentRatioSelectionTests.cs" />
     3.5      <Compile Include="API\Objects\UnitEquipmentNumericSelectionTests.cs" />
     3.6      <Compile Include="API\Factories\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest.cs" />
     3.7 +    <Compile Include="API\Objects\Requirement\RequiresNUnitsForMUnitsRequirementTest.cs" />
     3.8    </ItemGroup>
     3.9    <ItemGroup>
    3.10      <None Include="app.config" />