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 diff
     1.1 --- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Mon Apr 26 19:50:47 2010 +0000
     1.2 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Wed May 12 19:30:06 2010 +0000
     1.3 @@ -28,12 +28,20 @@
     1.4  		[ExpectedException(typeof(InvalidFileException), ExpectedMessage="Ability for Empire General with ID leaderOfMen did not exist in race definition")]
     1.5  		public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors()
     1.6  		{
     1.7 -			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/race-with-non-existant-ability.systemx"));
     1.8 -			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
     1.9 -			WarFoundryLoader.SetDefault(fixedLoader);
    1.10 +			SetDefaultGameSystem(new FileInfo("testdata/race-with-non-existant-ability.systemx"));
    1.11  			FileInfo raceFile = new FileInfo("testdata/race-with-non-existant-ability.racex");
    1.12  			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.13 -			Category[] cats = race.Categories;			
    1.14 +			race.EnsureFullyLoaded();
    1.15 +		}
    1.16 +		
    1.17 +		[Test()]
    1.18 +		[ExpectedException(typeof(InvalidFileException), ExpectedMessage="TBD")]
    1.19 +		public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError()
    1.20 +		{
    1.21 +			SetDefaultGameSystem();
    1.22 +			FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex");
    1.23 +			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.24 +			race.EnsureFullyLoaded();
    1.25  		}
    1.26  		
    1.27  		[Test()]
    1.28 @@ -46,15 +54,13 @@
    1.29  			enumerator.Reset();
    1.30  			enumerator.MoveNext();
    1.31  			Race race = (Race)enumerator.Current;
    1.32 -			Category[] cats = race.Categories;
    1.33 +			race.EnsureFullyLoaded();
    1.34  		}
    1.35  		
    1.36  		[Test()]
    1.37  		public void TestSingleUnitArmyLoadsSuccessfully()
    1.38  		{
    1.39 -			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
    1.40 -			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
    1.41 -			WarFoundryLoader.SetDefault(fixedLoader);
    1.42 +			SetDefaultGameSystem();
    1.43  			FileInfo raceFile = new FileInfo("testdata/single-unit-race.racex");
    1.44  			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.45  			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
    1.46 @@ -70,9 +76,7 @@
    1.47  		[Test()]
    1.48  		public void TestSingleUnitArmyWithMemberTypeReferenceLoadsSuccessfully()
    1.49  		{
    1.50 -			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
    1.51 -			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
    1.52 -			WarFoundryLoader.SetDefault(fixedLoader);
    1.53 +			SetDefaultGameSystem();
    1.54  			FileInfo raceFile = new FileInfo("testdata/single-unit-type-referencing-race.racex");
    1.55  			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.56  			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
    1.57 @@ -88,9 +92,7 @@
    1.58  		[Test()]
    1.59  		public void TestSingleUnitArmyWithMultipleMemberTypeReferencesLoadsSuccessfully()
    1.60  		{
    1.61 -			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
    1.62 -			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
    1.63 -			WarFoundryLoader.SetDefault(fixedLoader);
    1.64 +			SetDefaultGameSystem();
    1.65  			FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race.racex");
    1.66  			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.67  			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
    1.68 @@ -109,9 +111,7 @@
    1.69  		[Test()]
    1.70  		public void TestSingleUnitArmyWithMultipleMemberTypeReferencesAndOverrideLoadsSuccessfully()
    1.71  		{
    1.72 -			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
    1.73 -			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
    1.74 -			WarFoundryLoader.SetDefault(fixedLoader);
    1.75 +			SetDefaultGameSystem();
    1.76  			FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race-with-override.racex");
    1.77  			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.78  			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
    1.79 @@ -129,9 +129,7 @@
    1.80  		[Test()]
    1.81  		public void TestSingleUnitArmyWithNoStatsReturnsUnitWithBlankStats()
    1.82  		{
    1.83 -			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
    1.84 -			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
    1.85 -			WarFoundryLoader.SetDefault(fixedLoader);
    1.86 +			SetDefaultGameSystem();
    1.87  			FileInfo raceFile = new FileInfo("testdata/single-unit-no-stats-race.racex");
    1.88  			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.89  			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
    1.90 @@ -147,5 +145,18 @@
    1.91  			
    1.92  			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
    1.93  		}
    1.94 +		
    1.95 +		private static void SetDefaultGameSystem()
    1.96 +		{			
    1.97 +			FileInfo systemFile = new FileInfo("testdata/default.systemx");
    1.98 +			SetDefaultGameSystem(systemFile);
    1.99 +		}
   1.100 +		
   1.101 +		public static void SetDefaultGameSystem(FileInfo systemFile)
   1.102 +		{
   1.103 +			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), systemFile);
   1.104 +			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
   1.105 +			WarFoundryLoader.SetDefault(fixedLoader);
   1.106 +		}
   1.107  	}
   1.108  }
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Mon Apr 26 19:50:47 2010 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Wed May 12 19:30:06 2010 +0000
     2.3 @@ -105,6 +105,9 @@
     2.4      <None Include="testdata\single-unit-multi-type-referencing-race-with-override.racex">
     2.5        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     2.6      </None>
     2.7 +    <None Include="testdata\single-unit-non-existant-type-referencing-race.racex">
     2.8 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     2.9 +    </None>
    2.10    </ItemGroup>
    2.11    <ItemGroup>
    2.12      <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/testdata/single-unit-non-existant-type-referencing-race.racex	Wed May 12 19:30:06 2010 +0000
     3.3 @@ -0,0 +1,25 @@
     3.4 +<?xml version="1.0" encoding="UTF-8"?>
     3.5 +<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">
     3.6 +	<units>
     3.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     3.8 +			<unitMembers>
     3.9 +				<unitMember typeID="Empire1"/>
    3.10 +			</unitMembers>
    3.11 +		</unit>
    3.12 +	</units>
    3.13 +	<memberTypes>
    3.14 +		<memberType id="General" name="General">
    3.15 +			<stats>
    3.16 +				<stat name="M">4</stat>
    3.17 +				<stat name="WS">6</stat>
    3.18 +				<stat name="BS">6</stat>
    3.19 +				<stat name="S">4</stat>
    3.20 +				<stat name="T">4</stat>
    3.21 +				<stat name="W">3</stat>
    3.22 +				<stat name="I">6</stat>
    3.23 +				<stat name="A">4</stat>
    3.24 +				<stat name="Ld">9</stat>
    3.25 +			</stats>
    3.26 +		</memberType>
    3.27 +	</memberTypes>
    3.28 +</race>
    3.29 \ No newline at end of file