Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
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 wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Factories/Mock/MockRaceFactory.cs Mon Jul 04 20:03:47 2011 +0000 @@ -0,0 +1,37 @@ +// This file (MockRaceFactory.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard +// +// 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. +using System; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Factories.Mock +{ + public class MockRaceFactory : IRaceFactory<object, object> + { + public MockRaceFactory() + { + //Do nothing special + } + + public Race CreateRace (object entry) + { + throw new NotImplementedException (); + } + + public void CompleteLoading (Race race) + { + //Do nothing + } + + public UnitType GetUnitType (string id, Race parentRace) + { + return parentRace.GetUnitType(id); + } + + public UnitType GetUnitType (string id, Race parentRace, object src) + { + return parentRace.GetUnitType(id); + } + } +} +
--- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs Sat Jul 02 19:56:30 2011 +0000 +++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs Mon Jul 04 20:03:47 2011 +0000 @@ -7,6 +7,7 @@ using NUnit.Framework.SyntaxHelpers; using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Objects.Requirement; +using IBBoard.WarFoundry.API.Factories.Mock; namespace IBBoard.WarFoundry.API.Factories.Requirement { @@ -18,6 +19,7 @@ private static string typeID2 = "unit2"; private static UnitType unitType1; private static UnitType unitType2; + private static MockRaceFactory raceFactory = new MockRaceFactory(); [TestFixtureSetUp()] public void Setup() @@ -33,7 +35,7 @@ public void TestCreatesRequirement() { UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory(); - Assert.That(factory.CreateRequirement(unitType2, typeID1), Is.Not.Null); + Assert.That(factory.CreateRequirement(unitType2, typeID1, raceFactory), Is.Not.Null); } [Test()] @@ -43,7 +45,7 @@ UnitType unitType = new UnitType("testUnit", "Test Unit", race); UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1); - UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1); + UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -55,7 +57,7 @@ UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1); expectedReq.AddUnitTypeRequirement(unitType2); - UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2); + UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -66,7 +68,7 @@ UnitType unitType = new UnitType("testUnit", "Test Unit", race); UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, 2); - UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2"); + UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -78,7 +80,7 @@ UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, 2); expectedReq.AddUnitTypeRequirement(unitType2, 3); - UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3"); + UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -90,7 +92,7 @@ UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, 2); expectedReq.AddUnitTypeRequirement(unitType2); - UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2); + UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -102,7 +104,7 @@ UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1); expectedReq.AddUnitTypeRequirement(unitType2, 3); - UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3"); + UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -112,7 +114,7 @@ { UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - factory.CreateRequirement(unitType, "fibble"); + factory.CreateRequirement(unitType, "fibble", raceFactory); } [Test()] @@ -121,7 +123,7 @@ { UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - factory.CreateRequirement(unitType, typeID1+":a"); + factory.CreateRequirement(unitType, typeID1+":a", raceFactory); } } }
--- a/API/Factories/Xml/SingleXmlObjectLoader.cs Sat Jul 02 19:56:30 2011 +0000 +++ b/API/Factories/Xml/SingleXmlObjectLoader.cs Mon Jul 04 20:03:47 2011 +0000 @@ -21,7 +21,7 @@ try { - return factory.GetRaceFactory().CreateRaceFromElement(null, CreateDocumentElementFromStream(stream)); + return factory.GetRaceFactory().CreateRaceFromElement(CreateDocumentElementFromStream(stream)); } finally {
--- a/IBBoard.WarFoundry.API.Tests.csproj Sat Jul 02 19:56:30 2011 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Mon Jul 04 20:03:47 2011 +0000 @@ -104,6 +104,7 @@ <Compile Include="API\Objects\Requirement\Mock\NotApplicableRequirement.cs" /> <Compile Include="API\Objects\Requirement\UnitCountRequirementDataTest.cs" /> <Compile Include="API\Factories\Requirement\UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs" /> + <Compile Include="API\Factories\Mock\MockRaceFactory.cs" /> </ItemGroup> <ItemGroup> <None Include="app.config" />