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 diff
     1.1 --- a/API/EventListeningWarFoundryLoader.cs	Sat Mar 05 15:53:29 2011 +0000
     1.2 +++ b/API/EventListeningWarFoundryLoader.cs	Sat Mar 05 19:53:25 2011 +0000
     1.3 @@ -25,6 +25,13 @@
     1.4  			factory.RaceLoaded+= DoStoreRace;
     1.5  		}
     1.6  		
     1.7 +		public override void UnregisterFactory (INativeWarFoundryFactory factory)
     1.8 +		{
     1.9 +			base.UnregisterFactory(factory);
    1.10 +			factory.GameSystemLoaded-= DoStoreGameSystem;
    1.11 +			factory.RaceLoaded-= DoStoreRace;
    1.12 +		}
    1.13 +		
    1.14  		protected override GameSystem GetExistingSystemForSystem (GameSystem system)
    1.15  		{
    1.16  			throw new System.NotImplementedException();
     2.1 --- a/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Sat Mar 05 15:53:29 2011 +0000
     2.2 +++ b/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Sat Mar 05 19:53:25 2011 +0000
     2.3 @@ -16,26 +16,33 @@
     2.4  			EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader();
     2.5  			WarFoundryLoader.SetDefault(loader);
     2.6  			WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
     2.7 -			loader.RegisterFactory(factory);
     2.8 -			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
     2.9 -			Assert.That(objs, Has.Count(2));
    2.10 -			int raceCount = 0;
    2.11 -			int systemCount = 0;
    2.12 -			
    2.13 -			foreach (IWarFoundryObject obj in objs)
    2.14 +			try
    2.15  			{
    2.16 -				if (obj is Race)
    2.17 +				loader.RegisterFactory(factory);
    2.18 +				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
    2.19 +				Assert.That(objs, Has.Count(2));
    2.20 +				int raceCount = 0;
    2.21 +				int systemCount = 0;
    2.22 +				
    2.23 +				foreach (IWarFoundryObject obj in objs)
    2.24  				{
    2.25 -					raceCount++;
    2.26 +					if (obj is Race)
    2.27 +					{
    2.28 +						raceCount++;
    2.29 +					}
    2.30 +					else if (obj is GameSystem)
    2.31 +					{
    2.32 +						systemCount++;
    2.33 +					}
    2.34  				}
    2.35 -				else if (obj is GameSystem)
    2.36 -				{
    2.37 -					systemCount++;
    2.38 -				}
    2.39 +				
    2.40 +				Assert.That(raceCount, Is.EqualTo(1));
    2.41 +				Assert.That(systemCount, Is.EqualTo(1));
    2.42  			}
    2.43 -			
    2.44 -			Assert.That(raceCount, Is.EqualTo(1));
    2.45 -			Assert.That(systemCount, Is.EqualTo(1));
    2.46 +			finally
    2.47 +			{				
    2.48 +				loader.UnregisterFactory(factory);
    2.49 +			}
    2.50  		}
    2.51  			
    2.52  		[Test()]
    2.53 @@ -45,25 +52,32 @@
    2.54  			WarFoundryLoader.SetDefault(loader);
    2.55  			WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
    2.56  			loader.RegisterFactory(factory);
    2.57 -			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.race"));
    2.58 -			Assert.That(objs, Has.Count(2));
    2.59 -			int raceCount = 0;
    2.60 -			int systemCount = 0;
    2.61 -			
    2.62 -			foreach (IWarFoundryObject obj in objs)
    2.63 +			try
    2.64  			{
    2.65 -				if (obj is Race)
    2.66 +				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.race"));
    2.67 +				Assert.That(objs, Has.Count(2));
    2.68 +				int raceCount = 0;
    2.69 +				int systemCount = 0;
    2.70 +				
    2.71 +				foreach (IWarFoundryObject obj in objs)
    2.72  				{
    2.73 -					raceCount++;
    2.74 +					if (obj is Race)
    2.75 +					{
    2.76 +						raceCount++;
    2.77 +					}
    2.78 +					else if (obj is GameSystem)
    2.79 +					{
    2.80 +						systemCount++;
    2.81 +					}
    2.82  				}
    2.83 -				else if (obj is GameSystem)
    2.84 -				{
    2.85 -					systemCount++;
    2.86 -				}
    2.87 +				
    2.88 +				Assert.That(raceCount, Is.EqualTo(1));
    2.89 +				Assert.That(systemCount, Is.EqualTo(1));
    2.90  			}
    2.91 -			
    2.92 -			Assert.That(raceCount, Is.EqualTo(1));
    2.93 -			Assert.That(systemCount, Is.EqualTo(1));
    2.94 +			finally
    2.95 +			{				
    2.96 +				loader.UnregisterFactory(factory);
    2.97 +			}
    2.98  		}
    2.99  		
   2.100  		[Test()]
   2.101 @@ -73,25 +87,32 @@
   2.102  			WarFoundryLoader.SetDefault(loader);
   2.103  			WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
   2.104  			loader.RegisterFactory(factory);
   2.105 -			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Multipack.system"));
   2.106 -			Assert.That(objs, Has.Count(4));
   2.107 -			int raceCount = 0;
   2.108 -			int systemCount = 0;
   2.109 -			
   2.110 -			foreach (IWarFoundryObject obj in objs)
   2.111 +			try
   2.112  			{
   2.113 -				if (obj is Race)
   2.114 +				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Multipack.system"));
   2.115 +				Assert.That(objs, Has.Count(4));
   2.116 +				int raceCount = 0;
   2.117 +				int systemCount = 0;
   2.118 +				
   2.119 +				foreach (IWarFoundryObject obj in objs)
   2.120  				{
   2.121 -					raceCount++;
   2.122 +					if (obj is Race)
   2.123 +					{
   2.124 +						raceCount++;
   2.125 +					}
   2.126 +					else if (obj is GameSystem)
   2.127 +					{
   2.128 +						systemCount++;
   2.129 +					}
   2.130  				}
   2.131 -				else if (obj is GameSystem)
   2.132 -				{
   2.133 -					systemCount++;
   2.134 -				}
   2.135 +				
   2.136 +				Assert.That(raceCount, Is.EqualTo(2));
   2.137 +				Assert.That(systemCount, Is.EqualTo(2));
   2.138  			}
   2.139 -			
   2.140 -			Assert.That(raceCount, Is.EqualTo(2));
   2.141 -			Assert.That(systemCount, Is.EqualTo(2));
   2.142 +			finally
   2.143 +			{				
   2.144 +				loader.UnregisterFactory(factory);
   2.145 +			}
   2.146  		}
   2.147  	}
   2.148  }