changeset 193:cf1c0a91eaa9

Re #350: Add requirement to allow N of unit for specific other units * Add first unit tests for factory, based on existing factory unit tests
author IBBoard <dev@ibboard.co.uk>
date Sat, 03 Dec 2011 16:53:36 +0000
parents f25cb069f700
children f1f4df654a91
files API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 2 files changed, 131 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs	Sat Dec 03 16:53:36 2011 +0000
     1.3 @@ -0,0 +1,130 @@
     1.4 +// This file (UnitUnitRequiresNUnitsForMUnitsRequirementFactoryTest.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 UnitUnitRequiresNUnitsForMUnitsRequirementFactoryTest
    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 UnitType unitType1;
    1.24 +		private static UnitType unitType2;
    1.25 +		private static MockRaceFactory raceFactory = new MockRaceFactory();
    1.26 +
    1.27 +		[TestFixtureSetUp()]
    1.28 +		public void Setup()
    1.29 +		{
    1.30 +			race = new MockRace();
    1.31 +			unitType1 = new UnitType(typeID1, "Unit 1", race);
    1.32 +			race.AddUnitType(unitType1);
    1.33 +			unitType2 = new UnitType(typeID2, "Unit 2", race);
    1.34 +			race.AddUnitType(unitType2);
    1.35 +		}
    1.36 +
    1.37 +		[Test()]
    1.38 +		public void TestCreatesRequirement()
    1.39 +		{
    1.40 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.41 +			Assert.That(factory.CreateRequirement(unitType2, typeID1, raceFactory), Is.Not.Null);
    1.42 +		}
    1.43 +
    1.44 +		[Test()]
    1.45 +		public void TestCreatesCorrectRequirement()
    1.46 +		{
    1.47 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.48 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.49 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.50 +			expectedReq.AddUnitTypeRequirement(unitType1);
    1.51 +			IRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory);
    1.52 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.53 +		}
    1.54 +
    1.55 +		[Test()]
    1.56 +		public void TestCreatesCorrectRequirementForTwoIDs()
    1.57 +		{
    1.58 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.59 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.60 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.61 +			expectedReq.AddUnitTypeRequirement(unitType1);
    1.62 +			expectedReq.AddUnitTypeRequirement(unitType2);
    1.63 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory);
    1.64 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.65 +		}
    1.66 +
    1.67 +		[Test()]
    1.68 +		public void TestCreatesCorrectRequirementWithNumber()
    1.69 +		{
    1.70 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.71 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.72 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.73 +			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    1.74 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory);
    1.75 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.76 +		}
    1.77 +
    1.78 +		[Test()]
    1.79 +		public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers()
    1.80 +		{
    1.81 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.82 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.83 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.84 +			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    1.85 +			expectedReq.AddUnitTypeRequirement(unitType2, 3);
    1.86 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory);
    1.87 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.88 +		}
    1.89 +
    1.90 +		[Test()]
    1.91 +		public void TestCreatesCorrectRequirementForTwoIDsWithOneNumber()
    1.92 +		{
    1.93 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.94 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.95 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.96 +			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    1.97 +			expectedReq.AddUnitTypeRequirement(unitType2);
    1.98 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory);
    1.99 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.100 +		}
   1.101 +
   1.102 +		[Test()]
   1.103 +		public void TestCreatesCorrectRequirementForTwoIDsWithOtherNumber()
   1.104 +		{
   1.105 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.106 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.107 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.108 +			expectedReq.AddUnitTypeRequirement(unitType1);
   1.109 +			expectedReq.AddUnitTypeRequirement(unitType2, 3);
   1.110 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory);
   1.111 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.112 +		}
   1.113 +
   1.114 +		[Test()]
   1.115 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N units for M units' requirement")]
   1.116 +		public void TestExceptionsForInvalidID()
   1.117 +		{
   1.118 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.119 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.120 +			factory.CreateRequirement(unitType, "fibble", raceFactory);
   1.121 +		}
   1.122 +
   1.123 +		[Test()]
   1.124 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")]
   1.125 +		public void TestExceptionsForInvalidNumber()
   1.126 +		{
   1.127 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.128 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.129 +			factory.CreateRequirement(unitType, typeID1+":a", raceFactory);
   1.130 +		}
   1.131 +	}
   1.132 +}
   1.133 +
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Dec 03 16:41:54 2011 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Dec 03 16:53:36 2011 +0000
     2.3 @@ -114,6 +114,7 @@
     2.4      <Compile Include="API\Objects\UnitEquipmentNumericSelectionTests.cs" />
     2.5      <Compile Include="API\Factories\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest.cs" />
     2.6      <Compile Include="API\Objects\Requirement\RequiresNUnitsForMUnitsRequirementTest.cs" />
     2.7 +    <Compile Include="API\Factories\Requirement\UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs" />
     2.8    </ItemGroup>
     2.9    <ItemGroup>
    2.10      <None Include="app.config" />