diff API/WarFoundryLoaderTest.cs @ 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 d1ec7618f812
children 7c21ca1482cb
line diff
     1.1 --- a/API/WarFoundryLoaderTest.cs	Sat Jul 16 19:59:33 2011 +0000
     1.2 +++ b/API/WarFoundryLoaderTest.cs	Sat Jul 23 19:54:37 2011 +0000
     1.3 @@ -10,6 +10,8 @@
     1.4  using NUnit.Framework.SyntaxHelpers;
     1.5  using System.Collections.Generic;
     1.6  using IBBoard.WarFoundry.API.Factories.Xml;
     1.7 +using IBBoard.WarFoundry.API.Factories.Requirement;
     1.8 +using IBBoard.WarFoundry.API.Objects.Requirement;
     1.9  
    1.10  namespace IBBoard.WarFoundry.API.Factories
    1.11  {
    1.12 @@ -45,6 +47,43 @@
    1.13  			ICollection<IWarFoundryObject> objs = loader.LoadFile(new FileInfo("testdata/Test.system"));
    1.14  			Assert.That(objs, Has.Count(1));
    1.15  		}
    1.16 +
    1.17 +		[Test()]
    1.18 +		public void TestRegisterRequirementFactoryAddsFactory()
    1.19 +		{
    1.20 +			string factoryID = "SomeID";
    1.21 +			MockRequirementFactory mockFactory = new MockRequirementFactory(factoryID);
    1.22 +			WarFoundryLoader.RegisterRequirementFactory(mockFactory);
    1.23 +			Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory));
    1.24 +			Assert.That(WarFoundryLoader.GetRequirementFactory("fibble"), Is.Null);
    1.25 +		}
    1.26 +
    1.27 +		[Test()]
    1.28 +		public void TestRegisterRequirementFactoryAddsFactories()
    1.29 +		{
    1.30 +			string factoryID1 = "SomeID";
    1.31 +			MockRequirementFactory mockFactory1 = new MockRequirementFactory(factoryID1);
    1.32 +			WarFoundryLoader.RegisterRequirementFactory(mockFactory1);
    1.33 +			string factoryID2 = "SomeOtherID";
    1.34 +			MockRequirementFactory mockFactory2 = new MockRequirementFactory(factoryID2);
    1.35 +			WarFoundryLoader.RegisterRequirementFactory(mockFactory2);
    1.36 +			Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID1), Is.EqualTo(mockFactory1));
    1.37 +			Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID2), Is.EqualTo(mockFactory2));
    1.38 +			Assert.That(WarFoundryLoader.GetRequirementFactory("fibble"), Is.Null);
    1.39 +		}
    1.40 +
    1.41 +		[Test()]
    1.42 +		public void TestRegisterRequirementFactoryOverridesWithSecondFactory()
    1.43 +		{
    1.44 +			string factoryID = "SomeID";
    1.45 +			MockRequirementFactory mockFactory1 = new MockRequirementFactory(factoryID);
    1.46 +			WarFoundryLoader.RegisterRequirementFactory(mockFactory1);
    1.47 +			Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory1));
    1.48 +			MockRequirementFactory mockFactory2 = new MockRequirementFactory(factoryID);
    1.49 +			WarFoundryLoader.RegisterRequirementFactory(mockFactory2);
    1.50 +			Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.Not.EqualTo(mockFactory1));
    1.51 +			Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory2));
    1.52 +		}
    1.53  				
    1.54  		private AbstractNativeWarFoundryFactory GetSystemFactory()
    1.55  		{