changeset 96:3c2c108a2f08

Re #253: Allow multiple data files in a single zip * Fix unit tests by unsubscribing at end of test no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sat, 05 Mar 2011 19:53:25 +0000
parents db6db25921fb
children 45b80fed5e2a
files API/EventListeningWarFoundryLoader.cs API/Factories/Xml/WarFoundryXmlFactoryTests.cs
diffstat 2 files changed, 74 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/API/EventListeningWarFoundryLoader.cs	Sat Mar 05 15:53:29 2011 +0000
+++ b/API/EventListeningWarFoundryLoader.cs	Sat Mar 05 19:53:25 2011 +0000
@@ -25,6 +25,13 @@
 			factory.RaceLoaded+= DoStoreRace;
 		}
 		
+		public override void UnregisterFactory (INativeWarFoundryFactory factory)
+		{
+			base.UnregisterFactory(factory);
+			factory.GameSystemLoaded-= DoStoreGameSystem;
+			factory.RaceLoaded-= DoStoreRace;
+		}
+		
 		protected override GameSystem GetExistingSystemForSystem (GameSystem system)
 		{
 			throw new System.NotImplementedException();
--- a/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Sat Mar 05 15:53:29 2011 +0000
+++ b/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Sat Mar 05 19:53:25 2011 +0000
@@ -16,26 +16,33 @@
 			EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader();
 			WarFoundryLoader.SetDefault(loader);
 			WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
-			loader.RegisterFactory(factory);
-			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
-			Assert.That(objs, Has.Count(2));
-			int raceCount = 0;
-			int systemCount = 0;
-			
-			foreach (IWarFoundryObject obj in objs)
+			try
 			{
-				if (obj is Race)
+				loader.RegisterFactory(factory);
+				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
+				Assert.That(objs, Has.Count(2));
+				int raceCount = 0;
+				int systemCount = 0;
+				
+				foreach (IWarFoundryObject obj in objs)
 				{
-					raceCount++;
+					if (obj is Race)
+					{
+						raceCount++;
+					}
+					else if (obj is GameSystem)
+					{
+						systemCount++;
+					}
 				}
-				else if (obj is GameSystem)
-				{
-					systemCount++;
-				}
+				
+				Assert.That(raceCount, Is.EqualTo(1));
+				Assert.That(systemCount, Is.EqualTo(1));
 			}
-			
-			Assert.That(raceCount, Is.EqualTo(1));
-			Assert.That(systemCount, Is.EqualTo(1));
+			finally
+			{				
+				loader.UnregisterFactory(factory);
+			}
 		}
 			
 		[Test()]
@@ -45,25 +52,32 @@
 			WarFoundryLoader.SetDefault(loader);
 			WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
 			loader.RegisterFactory(factory);
-			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.race"));
-			Assert.That(objs, Has.Count(2));
-			int raceCount = 0;
-			int systemCount = 0;
-			
-			foreach (IWarFoundryObject obj in objs)
+			try
 			{
-				if (obj is Race)
+				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.race"));
+				Assert.That(objs, Has.Count(2));
+				int raceCount = 0;
+				int systemCount = 0;
+				
+				foreach (IWarFoundryObject obj in objs)
 				{
-					raceCount++;
+					if (obj is Race)
+					{
+						raceCount++;
+					}
+					else if (obj is GameSystem)
+					{
+						systemCount++;
+					}
 				}
-				else if (obj is GameSystem)
-				{
-					systemCount++;
-				}
+				
+				Assert.That(raceCount, Is.EqualTo(1));
+				Assert.That(systemCount, Is.EqualTo(1));
 			}
-			
-			Assert.That(raceCount, Is.EqualTo(1));
-			Assert.That(systemCount, Is.EqualTo(1));
+			finally
+			{				
+				loader.UnregisterFactory(factory);
+			}
 		}
 		
 		[Test()]
@@ -73,25 +87,32 @@
 			WarFoundryLoader.SetDefault(loader);
 			WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
 			loader.RegisterFactory(factory);
-			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Multipack.system"));
-			Assert.That(objs, Has.Count(4));
-			int raceCount = 0;
-			int systemCount = 0;
-			
-			foreach (IWarFoundryObject obj in objs)
+			try
 			{
-				if (obj is Race)
+				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Multipack.system"));
+				Assert.That(objs, Has.Count(4));
+				int raceCount = 0;
+				int systemCount = 0;
+				
+				foreach (IWarFoundryObject obj in objs)
 				{
-					raceCount++;
+					if (obj is Race)
+					{
+						raceCount++;
+					}
+					else if (obj is GameSystem)
+					{
+						systemCount++;
+					}
 				}
-				else if (obj is GameSystem)
-				{
-					systemCount++;
-				}
+				
+				Assert.That(raceCount, Is.EqualTo(2));
+				Assert.That(systemCount, Is.EqualTo(2));
 			}
-			
-			Assert.That(raceCount, Is.EqualTo(2));
-			Assert.That(systemCount, Is.EqualTo(2));
+			finally
+			{				
+				loader.UnregisterFactory(factory);
+			}
 		}
 	}
 }