comparison 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
comparison
equal deleted inserted replaced
156:ae2f1db8290c 157:17c5030485dc
8 using IBBoard.WarFoundry.API.Factories.Mock; 8 using IBBoard.WarFoundry.API.Factories.Mock;
9 using IBBoard.WarFoundry.API.Objects; 9 using IBBoard.WarFoundry.API.Objects;
10 using NUnit.Framework.SyntaxHelpers; 10 using NUnit.Framework.SyntaxHelpers;
11 using System.Collections.Generic; 11 using System.Collections.Generic;
12 using IBBoard.WarFoundry.API.Factories.Xml; 12 using IBBoard.WarFoundry.API.Factories.Xml;
13 using IBBoard.WarFoundry.API.Factories.Requirement;
14 using IBBoard.WarFoundry.API.Objects.Requirement;
13 15
14 namespace IBBoard.WarFoundry.API.Factories 16 namespace IBBoard.WarFoundry.API.Factories
15 { 17 {
16 [TestFixture()] 18 [TestFixture()]
17 public class WarFoundryLoaderTest 19 public class WarFoundryLoaderTest
43 DefaultWarFoundryLoader loader = new DefaultWarFoundryLoader(); 45 DefaultWarFoundryLoader loader = new DefaultWarFoundryLoader();
44 loader.RegisterFactory(WarFoundryXmlFactory.GetFactory()); 46 loader.RegisterFactory(WarFoundryXmlFactory.GetFactory());
45 ICollection<IWarFoundryObject> objs = loader.LoadFile(new FileInfo("testdata/Test.system")); 47 ICollection<IWarFoundryObject> objs = loader.LoadFile(new FileInfo("testdata/Test.system"));
46 Assert.That(objs, Has.Count(1)); 48 Assert.That(objs, Has.Count(1));
47 } 49 }
50
51 [Test()]
52 public void TestRegisterRequirementFactoryAddsFactory()
53 {
54 string factoryID = "SomeID";
55 MockRequirementFactory mockFactory = new MockRequirementFactory(factoryID);
56 WarFoundryLoader.RegisterRequirementFactory(mockFactory);
57 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory));
58 Assert.That(WarFoundryLoader.GetRequirementFactory("fibble"), Is.Null);
59 }
60
61 [Test()]
62 public void TestRegisterRequirementFactoryAddsFactories()
63 {
64 string factoryID1 = "SomeID";
65 MockRequirementFactory mockFactory1 = new MockRequirementFactory(factoryID1);
66 WarFoundryLoader.RegisterRequirementFactory(mockFactory1);
67 string factoryID2 = "SomeOtherID";
68 MockRequirementFactory mockFactory2 = new MockRequirementFactory(factoryID2);
69 WarFoundryLoader.RegisterRequirementFactory(mockFactory2);
70 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID1), Is.EqualTo(mockFactory1));
71 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID2), Is.EqualTo(mockFactory2));
72 Assert.That(WarFoundryLoader.GetRequirementFactory("fibble"), Is.Null);
73 }
74
75 [Test()]
76 public void TestRegisterRequirementFactoryOverridesWithSecondFactory()
77 {
78 string factoryID = "SomeID";
79 MockRequirementFactory mockFactory1 = new MockRequirementFactory(factoryID);
80 WarFoundryLoader.RegisterRequirementFactory(mockFactory1);
81 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory1));
82 MockRequirementFactory mockFactory2 = new MockRequirementFactory(factoryID);
83 WarFoundryLoader.RegisterRequirementFactory(mockFactory2);
84 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.Not.EqualTo(mockFactory1));
85 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory2));
86 }
48 87
49 private AbstractNativeWarFoundryFactory GetSystemFactory() 88 private AbstractNativeWarFoundryFactory GetSystemFactory()
50 { 89 {
51 if (sysFactory == null) 90 if (sysFactory == null)
52 { 91 {