changeset 234:e418ba645d06

Re #410: Create "N units per M models in parent unit" requirement * Add tests, based on NUnitsForMUnits requirement factory TODO: * Test new methods on adding to requirement properly (e.g. multiple requirements for multi-parentage don't break things) * Test loading from XML (manually?)
author IBBoard <dev@ibboard.co.uk>
date Sun, 29 Jul 2012 21:05:41 +0100
parents 99248d05ba9c
children d122354eeebc
files API/Factories/Requirement/UnitRequiresNParentModelsForMUnitsRequirementFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 2 files changed, 177 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Factories/Requirement/UnitRequiresNParentModelsForMUnitsRequirementFactoryTest.cs	Sun Jul 29 21:05:41 2012 +0100
     1.3 @@ -0,0 +1,176 @@
     1.4 +// This file (UnitUnitRequiresNParentModelsForMUnitsRequirementFactoryTest.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 +using IBBoard.WarFoundry.API.Objects;
    1.12 +using IBBoard.WarFoundry.API.Objects.Requirement;
    1.13 +using IBBoard.WarFoundry.API.Factories.Mock;
    1.14 +
    1.15 +namespace IBBoard.WarFoundry.API.Factories.Requirement
    1.16 +{
    1.17 +	[TestFixture()]
    1.18 +	public class UnitRequiresNParentModelsForMUnitsRequirementFactoryTest
    1.19 +	{
    1.20 +		private static Race race;
    1.21 +		private static string typeID1 = "unit1";
    1.22 +		private static string typeID2 = "unit2";
    1.23 +		private static string typeID3 = "unit3";
    1.24 +		private static UnitType unitType1;
    1.25 +		private static UnitType unitType2;
    1.26 +		private static UnitType unitType3;
    1.27 +		private static MockRaceFactory raceFactory = new MockRaceFactory();
    1.28 +
    1.29 +		[TestFixtureSetUp()]
    1.30 +		public void Setup()
    1.31 +		{
    1.32 +			race = new MockRace();
    1.33 +			unitType1 = new UnitType(typeID1, "Unit 1", race);
    1.34 +			race.AddUnitType(unitType1);
    1.35 +			unitType2 = new UnitType(typeID2, "Unit 2", race);
    1.36 +			race.AddUnitType(unitType2);
    1.37 +			unitType3 = new UnitType(typeID3, "Unit 3", race);
    1.38 +			race.AddUnitType(unitType3);
    1.39 +		}
    1.40 +
    1.41 +		[Test()]
    1.42 +		public void TestCreatesRequirement()
    1.43 +		{
    1.44 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
    1.45 +			Assert.That(factory.CreateRequirement(unitType2, typeID1, raceFactory), Is.Not.Null);
    1.46 +		}
    1.47 +
    1.48 +		[Test()]
    1.49 +		public void TestCreatesCorrectRequirement()
    1.50 +		{
    1.51 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
    1.52 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.53 +			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
    1.54 +			expectedReq.AddUnitTypeRequirement(unitType1);
    1.55 +			IRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory);
    1.56 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.57 +		}
    1.58 +
    1.59 +		[Test()]
    1.60 +		public void TestCreatesCorrectRequirementForTwoIDs()
    1.61 +		{
    1.62 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
    1.63 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.64 +			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
    1.65 +			expectedReq.AddUnitTypeRequirement(unitType1);
    1.66 +			expectedReq.AddUnitTypeRequirement(unitType2);
    1.67 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory);
    1.68 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.69 +		}
    1.70 +
    1.71 +		[Test()]
    1.72 +		public void TestCreatesCorrectRequirementForThreeIDs()
    1.73 +		{
    1.74 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
    1.75 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.76 +			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
    1.77 +			expectedReq.AddUnitTypeRequirement(unitType1);
    1.78 +			expectedReq.AddUnitTypeRequirement(unitType2);
    1.79 +			expectedReq.AddUnitTypeRequirement(unitType3);
    1.80 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + "|" + typeID3, raceFactory);
    1.81 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.82 +		}
    1.83 +
    1.84 +		[Test()]
    1.85 +		public void TestCreatesCorrectRequirementWithNumber()
    1.86 +		{
    1.87 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
    1.88 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.89 +			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
    1.90 +			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    1.91 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory);
    1.92 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.93 +		}
    1.94 +
    1.95 +		[Test()]
    1.96 +		public void TestCreatesCorrectRequirementWithTwoNumbers()
    1.97 +		{
    1.98 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
    1.99 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.100 +			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
   1.101 +			expectedReq.AddUnitTypeRequirement(unitType1, 2, 3);
   1.102 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2;3", raceFactory);
   1.103 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.104 +		}
   1.105 +
   1.106 +		[Test()]
   1.107 +		public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers()
   1.108 +		{
   1.109 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
   1.110 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.111 +			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
   1.112 +			expectedReq.AddUnitTypeRequirement(unitType1, 2);
   1.113 +			expectedReq.AddUnitTypeRequirement(unitType2, 3);
   1.114 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory);
   1.115 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.116 +		}
   1.117 +
   1.118 +		[Test()]
   1.119 +		public void TestCreatesCorrectRequirementForTwoIDsWithOneNumber()
   1.120 +		{
   1.121 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
   1.122 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.123 +			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
   1.124 +			expectedReq.AddUnitTypeRequirement(unitType1, 2);
   1.125 +			expectedReq.AddUnitTypeRequirement(unitType2);
   1.126 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory);
   1.127 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.128 +		}
   1.129 +
   1.130 +		[Test()]
   1.131 +		public void TestCreatesCorrectRequirementForTwoIDsWithOtherNumber()
   1.132 +		{
   1.133 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
   1.134 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.135 +			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
   1.136 +			expectedReq.AddUnitTypeRequirement(unitType1);
   1.137 +			expectedReq.AddUnitTypeRequirement(unitType2, 3);
   1.138 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory);
   1.139 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.140 +		}
   1.141 +
   1.142 +		[Test()]
   1.143 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N models in parent unit for M units' requirement")]
   1.144 +		public void TestExceptionsForInvalidID()
   1.145 +		{
   1.146 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
   1.147 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.148 +			factory.CreateRequirement(unitType, "fibble", raceFactory);
   1.149 +		}
   1.150 +
   1.151 +		[Test()]
   1.152 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1' for 'Requires N models in parent unit for M units' requirement")]
   1.153 +		public void TestExceptionsForInvalidNumber()
   1.154 +		{
   1.155 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
   1.156 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.157 +			factory.CreateRequirement(unitType, typeID1 + ":a", raceFactory);
   1.158 +		}
   1.159 +
   1.160 +		[Test()]
   1.161 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid model amount 'a' for unit types 'unit1' for 'Requires N models in parent unit for M units' requirement")]
   1.162 +		public void TestExceptionsForInvalidAllowedNumber()
   1.163 +		{
   1.164 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
   1.165 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.166 +			factory.CreateRequirement(unitType, typeID1 + ":3;a", raceFactory);
   1.167 +		}
   1.168 +
   1.169 +		[Test()]
   1.170 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1' for 'Requires N models in parent unit for M units' requirement")]
   1.171 +		public void TestExceptionsForInvalidMinimumNumber()
   1.172 +		{
   1.173 +			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
   1.174 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.175 +			factory.CreateRequirement(unitType, typeID1 + ":a;3", raceFactory);
   1.176 +		}
   1.177 +	}
   1.178 +}
   1.179 +
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Jul 29 15:29:43 2012 +0100
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Jul 29 21:05:41 2012 +0100
     2.3 @@ -128,6 +128,7 @@
     2.4      <Compile Include="API\Loading\LoadableObjectSourceDirectoryTests.cs" />
     2.5      <Compile Include="API\Factories\Mock\MockRaceAndSystemFactory.cs" />
     2.6      <Compile Include="API\Objects\Requirement\UnitRequiresNParentModelsForMUnitsRequirementTests.cs" />
     2.7 +    <Compile Include="API\Factories\Requirement\UnitRequiresNParentModelsForMUnitsRequirementFactoryTest.cs" />
     2.8    </ItemGroup>
     2.9    <ItemGroup>
    2.10      <None Include="app.config" />