Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
changeset 157:17c5030485dc
Re #351: Add extensible requirement handling method
* Swap to using IRequirement, as per interface
* Test registration of factories
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 23 Jul 2011 19:54:37 +0000 |
parents | ae2f1db8290c |
children | d0b8c43f705f |
files | API/Factories/Requirement/Mock/MockRequirement.cs API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs API/MockRequirementFactory.cs API/WarFoundryLoaderTest.cs IBBoard.WarFoundry.API.Tests.csproj |
diffstat | 5 files changed, 117 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Factories/Requirement/Mock/MockRequirement.cs Sat Jul 23 19:54:37 2011 +0000 @@ -0,0 +1,37 @@ +// This file (MockRequirement.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.Requirement; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Factories.Requirement.Mock +{ + public class MockRequirement : IRequirement + { + public MockRequirement() + { + } + + public Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy) + { + throw new NotImplementedException(); + } + + public Validation ValidatesArmy(Army army) + { + throw new NotImplementedException(); + } + + public string GetValidationMessage(Army army) + { + throw new NotImplementedException(); + } + + public string GetAllowsAddingMessage(UnitType toAdd, Army toArmy) + { + throw new NotImplementedException(); + } + } +} +
--- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs Sat Jul 16 19:59:33 2011 +0000 +++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs Sat Jul 23 19:54:37 2011 +0000 @@ -45,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, raceFactory); + IRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -57,7 +57,7 @@ UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1); expectedReq.AddUnitTypeRequirement(unitType2); - UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -68,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", raceFactory); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -80,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", raceFactory); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -92,7 +92,7 @@ UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, 2); expectedReq.AddUnitTypeRequirement(unitType2); - UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -104,7 +104,7 @@ UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1); expectedReq.AddUnitTypeRequirement(unitType2, 3); - UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/MockRequirementFactory.cs Sat Jul 23 19:54:37 2011 +0000 @@ -0,0 +1,32 @@ +// This file (MockRequirementFactory.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.Factories.Requirement; +using IBBoard.WarFoundry.API.Factories.Requirement.Mock; +using IBBoard.WarFoundry.API.Objects.Requirement; + +namespace IBBoard.WarFoundry.API +{ + public class MockRequirementFactory : IRequirementFactory + { + private string factoryID; + + public MockRequirementFactory(string factoryID) + { + this.factoryID = factoryID; + } + + public IRequirement CreateRequirement<SOURCE_FILE_TYPE, ENTRY_TYPE> (IBBoard.WarFoundry.API.Objects.UnitType type, string data, IBBoard.WarFoundry.API.Factories.IRaceFactory<SOURCE_FILE_TYPE, ENTRY_TYPE> raceFactory) + { + throw new NotImplementedException (); + } + + public string AppliesToID { + get { + return factoryID; + } + } + } +} +
--- a/API/WarFoundryLoaderTest.cs Sat Jul 16 19:59:33 2011 +0000 +++ b/API/WarFoundryLoaderTest.cs Sat Jul 23 19:54:37 2011 +0000 @@ -10,6 +10,8 @@ using NUnit.Framework.SyntaxHelpers; using System.Collections.Generic; using IBBoard.WarFoundry.API.Factories.Xml; +using IBBoard.WarFoundry.API.Factories.Requirement; +using IBBoard.WarFoundry.API.Objects.Requirement; namespace IBBoard.WarFoundry.API.Factories { @@ -45,6 +47,43 @@ ICollection<IWarFoundryObject> objs = loader.LoadFile(new FileInfo("testdata/Test.system")); Assert.That(objs, Has.Count(1)); } + + [Test()] + public void TestRegisterRequirementFactoryAddsFactory() + { + string factoryID = "SomeID"; + MockRequirementFactory mockFactory = new MockRequirementFactory(factoryID); + WarFoundryLoader.RegisterRequirementFactory(mockFactory); + Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory)); + Assert.That(WarFoundryLoader.GetRequirementFactory("fibble"), Is.Null); + } + + [Test()] + public void TestRegisterRequirementFactoryAddsFactories() + { + string factoryID1 = "SomeID"; + MockRequirementFactory mockFactory1 = new MockRequirementFactory(factoryID1); + WarFoundryLoader.RegisterRequirementFactory(mockFactory1); + string factoryID2 = "SomeOtherID"; + MockRequirementFactory mockFactory2 = new MockRequirementFactory(factoryID2); + WarFoundryLoader.RegisterRequirementFactory(mockFactory2); + Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID1), Is.EqualTo(mockFactory1)); + Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID2), Is.EqualTo(mockFactory2)); + Assert.That(WarFoundryLoader.GetRequirementFactory("fibble"), Is.Null); + } + + [Test()] + public void TestRegisterRequirementFactoryOverridesWithSecondFactory() + { + string factoryID = "SomeID"; + MockRequirementFactory mockFactory1 = new MockRequirementFactory(factoryID); + WarFoundryLoader.RegisterRequirementFactory(mockFactory1); + Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory1)); + MockRequirementFactory mockFactory2 = new MockRequirementFactory(factoryID); + WarFoundryLoader.RegisterRequirementFactory(mockFactory2); + Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.Not.EqualTo(mockFactory1)); + Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory2)); + } private AbstractNativeWarFoundryFactory GetSystemFactory() {
--- a/IBBoard.WarFoundry.API.Tests.csproj Sat Jul 16 19:59:33 2011 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Sat Jul 23 19:54:37 2011 +0000 @@ -105,6 +105,8 @@ <Compile Include="API\Objects\Requirement\UnitCountRequirementDataTest.cs" /> <Compile Include="API\Factories\Requirement\UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs" /> <Compile Include="API\Factories\Mock\MockRaceFactory.cs" /> + <Compile Include="API\MockRequirementFactory.cs" /> + <Compile Include="API\Factories\Requirement\Mock\MockRequirement.cs" /> </ItemGroup> <ItemGroup> <None Include="app.config" /> @@ -365,5 +367,6 @@ <Folder Include="API\Savers\Xml\" /> <Folder Include="API\Objects\Requirement\Mock\" /> <Folder Include="API\Factories\Requirement\" /> + <Folder Include="API\Factories\Requirement\Mock\" /> </ItemGroup> </Project> \ No newline at end of file