changeset 155:3725fd449c77

Re #353: Handle unloaded units being referenced outside factory * Add mock factory and use it in tests All tests now pass (including tests that started failing because of unit loading order - triggered by requirement changes)
author IBBoard <dev@ibboard.co.uk>
date Mon, 04 Jul 2011 20:03:47 +0000
parents bf2880cf7bc5
children ae2f1db8290c
files API/Factories/Mock/MockRaceFactory.cs API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs API/Factories/Xml/SingleXmlObjectLoader.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 4 files changed, 50 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Factories/Mock/MockRaceFactory.cs	Mon Jul 04 20:03:47 2011 +0000
     1.3 @@ -0,0 +1,37 @@
     1.4 +// This file (MockRaceFactory.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 IBBoard.WarFoundry.API.Objects;
     1.9 +
    1.10 +namespace IBBoard.WarFoundry.API.Factories.Mock
    1.11 +{
    1.12 +	public class MockRaceFactory : IRaceFactory<object, object>
    1.13 +	{
    1.14 +		public MockRaceFactory()
    1.15 +		{
    1.16 +			//Do nothing special
    1.17 +		}
    1.18 +
    1.19 +		public Race CreateRace (object entry)
    1.20 +		{
    1.21 +			throw new NotImplementedException ();
    1.22 +		}
    1.23 +
    1.24 +		public void CompleteLoading (Race race)
    1.25 +		{
    1.26 +			//Do nothing
    1.27 +		}
    1.28 +
    1.29 +		public UnitType GetUnitType (string id, Race parentRace)
    1.30 +		{
    1.31 +			return parentRace.GetUnitType(id);
    1.32 +		}
    1.33 +
    1.34 +		public UnitType GetUnitType (string id, Race parentRace, object src)
    1.35 +		{
    1.36 +			return parentRace.GetUnitType(id);
    1.37 +		}
    1.38 +	}
    1.39 +}
    1.40 +
     2.1 --- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs	Sat Jul 02 19:56:30 2011 +0000
     2.2 +++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs	Mon Jul 04 20:03:47 2011 +0000
     2.3 @@ -7,6 +7,7 @@
     2.4  using NUnit.Framework.SyntaxHelpers;
     2.5  using IBBoard.WarFoundry.API.Objects;
     2.6  using IBBoard.WarFoundry.API.Objects.Requirement;
     2.7 +using IBBoard.WarFoundry.API.Factories.Mock;
     2.8  
     2.9  namespace IBBoard.WarFoundry.API.Factories.Requirement
    2.10  {
    2.11 @@ -18,6 +19,7 @@
    2.12  		private static string typeID2 = "unit2";
    2.13  		private static UnitType unitType1;
    2.14  		private static UnitType unitType2;
    2.15 +		private static MockRaceFactory raceFactory = new MockRaceFactory();
    2.16  
    2.17  		[TestFixtureSetUp()]
    2.18  		public void Setup()
    2.19 @@ -33,7 +35,7 @@
    2.20  		public void TestCreatesRequirement()
    2.21  		{
    2.22  			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
    2.23 -			Assert.That(factory.CreateRequirement(unitType2, typeID1), Is.Not.Null);
    2.24 +			Assert.That(factory.CreateRequirement(unitType2, typeID1, raceFactory), Is.Not.Null);
    2.25  		}
    2.26  
    2.27  		[Test()]
    2.28 @@ -43,7 +45,7 @@
    2.29  			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    2.30  			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    2.31  			expectedReq.AddUnitTypeRequirement(unitType1);
    2.32 -			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1);
    2.33 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory);
    2.34  			Assert.That(req, Is.EqualTo(expectedReq));
    2.35  		}
    2.36  
    2.37 @@ -55,7 +57,7 @@
    2.38  			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    2.39  			expectedReq.AddUnitTypeRequirement(unitType1);
    2.40  			expectedReq.AddUnitTypeRequirement(unitType2);
    2.41 -			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2);
    2.42 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory);
    2.43  			Assert.That(req, Is.EqualTo(expectedReq));
    2.44  		}
    2.45  
    2.46 @@ -66,7 +68,7 @@
    2.47  			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    2.48  			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    2.49  			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    2.50 -			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2");
    2.51 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory);
    2.52  			Assert.That(req, Is.EqualTo(expectedReq));
    2.53  		}
    2.54  
    2.55 @@ -78,7 +80,7 @@
    2.56  			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    2.57  			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    2.58  			expectedReq.AddUnitTypeRequirement(unitType2, 3);
    2.59 -			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3");
    2.60 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory);
    2.61  			Assert.That(req, Is.EqualTo(expectedReq));
    2.62  		}
    2.63  
    2.64 @@ -90,7 +92,7 @@
    2.65  			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    2.66  			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    2.67  			expectedReq.AddUnitTypeRequirement(unitType2);
    2.68 -			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2);
    2.69 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory);
    2.70  			Assert.That(req, Is.EqualTo(expectedReq));
    2.71  		}
    2.72  
    2.73 @@ -102,7 +104,7 @@
    2.74  			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    2.75  			expectedReq.AddUnitTypeRequirement(unitType1);
    2.76  			expectedReq.AddUnitTypeRequirement(unitType2, 3);
    2.77 -			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3");
    2.78 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory);
    2.79  			Assert.That(req, Is.EqualTo(expectedReq));
    2.80  		}
    2.81  
    2.82 @@ -112,7 +114,7 @@
    2.83  		{
    2.84  			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
    2.85  			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    2.86 -			factory.CreateRequirement(unitType, "fibble");
    2.87 +			factory.CreateRequirement(unitType, "fibble", raceFactory);
    2.88  		}
    2.89  
    2.90  		[Test()]
    2.91 @@ -121,7 +123,7 @@
    2.92  		{
    2.93  			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
    2.94  			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    2.95 -			factory.CreateRequirement(unitType, typeID1+":a");
    2.96 +			factory.CreateRequirement(unitType, typeID1+":a", raceFactory);
    2.97  		}
    2.98  	}
    2.99  }
     3.1 --- a/API/Factories/Xml/SingleXmlObjectLoader.cs	Sat Jul 02 19:56:30 2011 +0000
     3.2 +++ b/API/Factories/Xml/SingleXmlObjectLoader.cs	Mon Jul 04 20:03:47 2011 +0000
     3.3 @@ -21,7 +21,7 @@
     3.4  			
     3.5  			try
     3.6  			{
     3.7 -				return factory.GetRaceFactory().CreateRaceFromElement(null, CreateDocumentElementFromStream(stream));
     3.8 +				return factory.GetRaceFactory().CreateRaceFromElement(CreateDocumentElementFromStream(stream));
     3.9  			}
    3.10  			finally
    3.11  			{
     4.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Jul 02 19:56:30 2011 +0000
     4.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Mon Jul 04 20:03:47 2011 +0000
     4.3 @@ -104,6 +104,7 @@
     4.4      <Compile Include="API\Objects\Requirement\Mock\NotApplicableRequirement.cs" />
     4.5      <Compile Include="API\Objects\Requirement\UnitCountRequirementDataTest.cs" />
     4.6      <Compile Include="API\Factories\Requirement\UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs" />
     4.7 +    <Compile Include="API\Factories\Mock\MockRaceFactory.cs" />
     4.8    </ItemGroup>
     4.9    <ItemGroup>
    4.10      <None Include="app.config" />