changeset 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 73308371f9d8
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/single-unit-non-existant-type-referencing-race.racex
diffstat 3 files changed, 59 insertions(+), 20 deletions(-) [+]
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);
+		}
 	}
 }
--- a/IBBoard.WarFoundry.API.Tests.csproj	Mon Apr 26 19:50:47 2010 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Wed May 12 19:30:06 2010 +0000
@@ -105,6 +105,9 @@
     <None Include="testdata\single-unit-multi-type-referencing-race-with-override.racex">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="testdata\single-unit-non-existant-type-referencing-race.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/single-unit-non-existant-type-referencing-race.racex	Wed May 12 19:30:06 2010 +0000
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="EmpireAlt" name="Empire (Extended)" system="default" lang="en">
+	<units>
+		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
+			<unitMembers>
+				<unitMember typeID="Empire1"/>
+			</unitMembers>
+		</unit>
+	</units>
+	<memberTypes>
+		<memberType id="General" name="General">
+			<stats>
+				<stat name="M">4</stat>
+				<stat name="WS">6</stat>
+				<stat name="BS">6</stat>
+				<stat name="S">4</stat>
+				<stat name="T">4</stat>
+				<stat name="W">3</stat>
+				<stat name="I">6</stat>
+				<stat name="A">4</stat>
+				<stat name="Ld">9</stat>
+			</stats>
+		</memberType>
+	</memberTypes>
+</race>
\ No newline at end of file