diff API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 45:04d7cd276b1d

Re #274: crash when missing unitMember id * Add test data and unit test for error Also: * Refactor out common test code (setting up system)
author IBBoard <dev@ibboard.co.uk>
date Wed, 12 May 2010 19:30:06 +0000
parents 0de5d86bc1cb
children b4b4bde843d7
line wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Mon Apr 26 19:50:47 2010 +0000
+++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Wed May 12 19:30:06 2010 +0000
@@ -28,12 +28,20 @@
 		[ExpectedException(typeof(InvalidFileException), ExpectedMessage="Ability for Empire General with ID leaderOfMen did not exist in race definition")]
 		public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors()
 		{
-			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/race-with-non-existant-ability.systemx"));
-			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
-			WarFoundryLoader.SetDefault(fixedLoader);
+			SetDefaultGameSystem(new FileInfo("testdata/race-with-non-existant-ability.systemx"));
 			FileInfo raceFile = new FileInfo("testdata/race-with-non-existant-ability.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
-			Category[] cats = race.Categories;			
+			race.EnsureFullyLoaded();
+		}
+		
+		[Test()]
+		[ExpectedException(typeof(InvalidFileException), ExpectedMessage="TBD")]
+		public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError()
+		{
+			SetDefaultGameSystem();
+			FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			race.EnsureFullyLoaded();
 		}
 		
 		[Test()]
@@ -46,15 +54,13 @@
 			enumerator.Reset();
 			enumerator.MoveNext();
 			Race race = (Race)enumerator.Current;
-			Category[] cats = race.Categories;
+			race.EnsureFullyLoaded();
 		}
 		
 		[Test()]
 		public void TestSingleUnitArmyLoadsSuccessfully()
 		{
-			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
-			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
-			WarFoundryLoader.SetDefault(fixedLoader);
+			SetDefaultGameSystem();
 			FileInfo raceFile = new FileInfo("testdata/single-unit-race.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
@@ -70,9 +76,7 @@
 		[Test()]
 		public void TestSingleUnitArmyWithMemberTypeReferenceLoadsSuccessfully()
 		{
-			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
-			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
-			WarFoundryLoader.SetDefault(fixedLoader);
+			SetDefaultGameSystem();
 			FileInfo raceFile = new FileInfo("testdata/single-unit-type-referencing-race.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
@@ -88,9 +92,7 @@
 		[Test()]
 		public void TestSingleUnitArmyWithMultipleMemberTypeReferencesLoadsSuccessfully()
 		{
-			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
-			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
-			WarFoundryLoader.SetDefault(fixedLoader);
+			SetDefaultGameSystem();
 			FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
@@ -109,9 +111,7 @@
 		[Test()]
 		public void TestSingleUnitArmyWithMultipleMemberTypeReferencesAndOverrideLoadsSuccessfully()
 		{
-			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
-			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
-			WarFoundryLoader.SetDefault(fixedLoader);
+			SetDefaultGameSystem();
 			FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race-with-override.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
@@ -129,9 +129,7 @@
 		[Test()]
 		public void TestSingleUnitArmyWithNoStatsReturnsUnitWithBlankStats()
 		{
-			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
-			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
-			WarFoundryLoader.SetDefault(fixedLoader);
+			SetDefaultGameSystem();
 			FileInfo raceFile = new FileInfo("testdata/single-unit-no-stats-race.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
@@ -147,5 +145,18 @@
 			
 			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
 		}
+		
+		private static void SetDefaultGameSystem()
+		{			
+			FileInfo systemFile = new FileInfo("testdata/default.systemx");
+			SetDefaultGameSystem(systemFile);
+		}
+		
+		public static void SetDefaultGameSystem(FileInfo systemFile)
+		{
+			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), systemFile);
+			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
+			WarFoundryLoader.SetDefault(fixedLoader);
+		}
 	}
 }