changeset 187:cd2aeab2357f

Re #356: Add factory for UnitRequiresNoMoreThanNOfUnitTypeRequirement * Rename factory * Update unit tests from basic copy/paste/find&replace
author IBBoard <dev@ibboard.co.uk>
date Sun, 13 Nov 2011 20:53:55 +0000
parents 3263691443be
children 0762766bd3f2
files API/Factories/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest.cs API/Factories/Requirement/UnitRequiresNoMoreThanNUnitsRequirementFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 3 files changed, 131 insertions(+), 131 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Factories/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest.cs	Sun Nov 13 20:53:55 2011 +0000
     1.3 @@ -0,0 +1,130 @@
     1.4 +// This file (UnitRequiresNoMoreThanNUnitsRequirementFactoryTest.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 UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest
    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 +			UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory();
    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 +			UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory();
    1.48 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.49 +			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(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 +			UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory();
    1.59 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.60 +			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(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 +			UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory();
    1.71 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.72 +			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(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 +			UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory();
    1.82 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.83 +			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(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 +			UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory();
    1.94 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.95 +			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(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 +			UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory();
   1.106 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.107 +			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(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 no more than N of unit type' requirement")]
   1.116 +		public void TestExceptionsForInvalidID()
   1.117 +		{
   1.118 +			UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory();
   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 no more than N of unit type' requirement")]
   1.125 +		public void TestExceptionsForInvalidNumber()
   1.126 +		{
   1.127 +			UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory();
   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/API/Factories/Requirement/UnitRequiresNoMoreThanNUnitsRequirementFactoryTest.cs	Sun Nov 13 20:49:37 2011 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,130 +0,0 @@
     2.4 -// This file (UnitRequiresNoMoreThanNUnitsRequirementFactoryTest.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 IBBoard.WarFoundry.API.Objects;
    2.12 -using IBBoard.WarFoundry.API.Objects.Requirement;
    2.13 -using IBBoard.WarFoundry.API.Factories.Mock;
    2.14 -
    2.15 -namespace IBBoard.WarFoundry.API.Factories.Requirement
    2.16 -{
    2.17 -	[TestFixture()]
    2.18 -	public class UnitRequiresNoMoreThanNUnitsRequirementFactoryTest
    2.19 -	{
    2.20 -		private static Race race;
    2.21 -		private static string typeID1 = "unit1";
    2.22 -		private static string typeID2 = "unit2";
    2.23 -		private static UnitType unitType1;
    2.24 -		private static UnitType unitType2;
    2.25 -		private static MockRaceFactory raceFactory = new MockRaceFactory();
    2.26 -
    2.27 -		[TestFixtureSetUp()]
    2.28 -		public void Setup()
    2.29 -		{
    2.30 -			race = new MockRace();
    2.31 -			unitType1 = new UnitType(typeID1, "Unit 1", race);
    2.32 -			race.AddUnitType(unitType1);
    2.33 -			unitType2 = new UnitType(typeID2, "Unit 2", race);
    2.34 -			race.AddUnitType(unitType2);
    2.35 -		}
    2.36 -
    2.37 -		[Test()]
    2.38 -		public void TestCreatesRequirement()
    2.39 -		{
    2.40 -			UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory();
    2.41 -			Assert.That(factory.CreateRequirement(unitType2, typeID1, raceFactory), Is.Not.Null);
    2.42 -		}
    2.43 -
    2.44 -		[Test()]
    2.45 -		public void TestCreatesCorrectRequirement()
    2.46 -		{
    2.47 -			UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory();
    2.48 -			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    2.49 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType);
    2.50 -			expectedReq.AddUnitTypeRequirement(unitType1);
    2.51 -			IRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory);
    2.52 -			Assert.That(req, Is.EqualTo(expectedReq));
    2.53 -		}
    2.54 -
    2.55 -		[Test()]
    2.56 -		public void TestCreatesCorrectRequirementForTwoIDs()
    2.57 -		{
    2.58 -			UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory();
    2.59 -			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    2.60 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType);
    2.61 -			expectedReq.AddUnitTypeRequirement(unitType1);
    2.62 -			expectedReq.AddUnitTypeRequirement(unitType2);
    2.63 -			IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory);
    2.64 -			Assert.That(req, Is.EqualTo(expectedReq));
    2.65 -		}
    2.66 -
    2.67 -		[Test()]
    2.68 -		public void TestCreatesCorrectRequirementWithNumber()
    2.69 -		{
    2.70 -			UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory();
    2.71 -			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    2.72 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType);
    2.73 -			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    2.74 -			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory);
    2.75 -			Assert.That(req, Is.EqualTo(expectedReq));
    2.76 -		}
    2.77 -
    2.78 -		[Test()]
    2.79 -		public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers()
    2.80 -		{
    2.81 -			UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory();
    2.82 -			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    2.83 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType);
    2.84 -			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    2.85 -			expectedReq.AddUnitTypeRequirement(unitType2, 3);
    2.86 -			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory);
    2.87 -			Assert.That(req, Is.EqualTo(expectedReq));
    2.88 -		}
    2.89 -
    2.90 -		[Test()]
    2.91 -		public void TestCreatesCorrectRequirementForTwoIDsWithOneNumber()
    2.92 -		{
    2.93 -			UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory();
    2.94 -			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    2.95 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType);
    2.96 -			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    2.97 -			expectedReq.AddUnitTypeRequirement(unitType2);
    2.98 -			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory);
    2.99 -			Assert.That(req, Is.EqualTo(expectedReq));
   2.100 -		}
   2.101 -
   2.102 -		[Test()]
   2.103 -		public void TestCreatesCorrectRequirementForTwoIDsWithOtherNumber()
   2.104 -		{
   2.105 -			UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory();
   2.106 -			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   2.107 -			UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType);
   2.108 -			expectedReq.AddUnitTypeRequirement(unitType1);
   2.109 -			expectedReq.AddUnitTypeRequirement(unitType2, 3);
   2.110 -			IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory);
   2.111 -			Assert.That(req, Is.EqualTo(expectedReq));
   2.112 -		}
   2.113 -
   2.114 -		[Test()]
   2.115 -		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires at least N units' requirement")]
   2.116 -		public void TestExceptionsForInvalidID()
   2.117 -		{
   2.118 -			UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory();
   2.119 -			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   2.120 -			factory.CreateRequirement(unitType, "fibble", raceFactory);
   2.121 -		}
   2.122 -
   2.123 -		[Test()]
   2.124 -		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid amount 'a' for unit type 'unit1' for 'Requires at least N units' requirement")]
   2.125 -		public void TestExceptionsForInvalidNumber()
   2.126 -		{
   2.127 -			UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory();
   2.128 -			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   2.129 -			factory.CreateRequirement(unitType, typeID1+":a", raceFactory);
   2.130 -		}
   2.131 -	}
   2.132 -}
   2.133 -
     3.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Nov 13 20:49:37 2011 +0000
     3.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Nov 13 20:53:55 2011 +0000
     3.3 @@ -112,7 +112,7 @@
     3.4      <Compile Include="API\Objects\UnitEquipmentLimitTests.cs" />
     3.5      <Compile Include="API\Objects\UnitEquipmentRatioSelectionTests.cs" />
     3.6      <Compile Include="API\Objects\UnitEquipmentNumericSelectionTests.cs" />
     3.7 -    <Compile Include="API\Factories\Requirement\UnitRequiresNoMoreThanNUnitsRequirementFactoryTest.cs" />
     3.8 +    <Compile Include="API\Factories\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest.cs" />
     3.9    </ItemGroup>
    3.10    <ItemGroup>
    3.11      <None Include="app.config" />