changeset 44:0de5d86bc1cb

Re #268: Restructure stats for re-use * Add tests for multiple stat lines/referenced types and for overriding the stats
author IBBoard <dev@ibboard.co.uk>
date Mon, 26 Apr 2010 19:50:47 +0000
parents 00abd1c2f7d6
children 04d7cd276b1d
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/single-unit-multi-type-referencing-race-with-override.racex testdata/single-unit-multi-type-referencing-race.racex
diffstat 4 files changed, 147 insertions(+), 11 deletions(-) [+]
line diff
     1.1 --- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sun Apr 25 15:10:30 2010 +0000
     1.2 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Mon Apr 26 19:50:47 2010 +0000
     1.3 @@ -58,13 +58,13 @@
     1.4  			FileInfo raceFile = new FileInfo("testdata/single-unit-race.racex");
     1.5  			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
     1.6  			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
     1.7 -			Assert.That(unitTypes.Length == 1);
     1.8 +			Assert.AreEqual(1, unitTypes.Length);
     1.9  			UnitType unitType = unitTypes[0];
    1.10 -			Stat[] stats = unitType.UnitStatsArray;
    1.11 -			Assert.That(stats.Length == 9);
    1.12 +			Stat[] stats = unitType.UnitStatsArrays[0];
    1.13 +			Assert.AreEqual(9, stats.Length);
    1.14  			Assert.AreEqual("M", stats[0].ParentSlotName);
    1.15  			Assert.AreEqual("4", stats[0].SlotValueString);
    1.16 -			Assert.AreEqual("Empire General", unitType.UnitStatsArrayWithName[0].SlotValueString);
    1.17 +			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
    1.18  		}
    1.19  		
    1.20  		[Test()]
    1.21 @@ -76,13 +76,54 @@
    1.22  			FileInfo raceFile = new FileInfo("testdata/single-unit-type-referencing-race.racex");
    1.23  			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.24  			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
    1.25 -			Assert.That(unitTypes.Length == 1);
    1.26 +			Assert.AreEqual(1, unitTypes.Length);
    1.27  			UnitType unitType = unitTypes[0];
    1.28 -			Stat[] stats = unitType.UnitStatsArray;
    1.29 -			Assert.That(stats.Length == 9);
    1.30 +			Stat[] stats = unitType.UnitStatsArrays[0];
    1.31 +			Assert.AreEqual(9, stats.Length);
    1.32  			Assert.AreEqual("M", stats[0].ParentSlotName);
    1.33  			Assert.AreEqual("4", stats[0].SlotValueString);
    1.34 -			Assert.AreEqual("General", unitType.UnitStatsArrayWithName[0].SlotValueString);
    1.35 +			Assert.AreEqual("General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
    1.36 +		}
    1.37 +		
    1.38 +		[Test()]
    1.39 +		public void TestSingleUnitArmyWithMultipleMemberTypeReferencesLoadsSuccessfully()
    1.40 +		{
    1.41 +			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
    1.42 +			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
    1.43 +			WarFoundryLoader.SetDefault(fixedLoader);
    1.44 +			FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race.racex");
    1.45 +			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.46 +			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
    1.47 +			Assert.AreEqual(1, unitTypes.Length);
    1.48 +			UnitType unitType = unitTypes[0];
    1.49 +			Stat[][] stats = unitType.UnitStatsArrays;
    1.50 +			Assert.AreEqual(2, stats.Length);
    1.51 +			Assert.AreEqual("M", stats[0][0].ParentSlotName);
    1.52 +			Assert.AreEqual("4", stats[0][0].SlotValueString);
    1.53 +			Assert.AreEqual("General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
    1.54 +			Assert.AreEqual("M", stats[1][0].ParentSlotName);
    1.55 +			Assert.AreEqual("8", stats[1][0].SlotValueString);
    1.56 +			Assert.AreEqual("Warhorse", unitType.UnitStatsArraysWithName[1][0].SlotValueString);
    1.57 +		}
    1.58 +		
    1.59 +		[Test()]
    1.60 +		public void TestSingleUnitArmyWithMultipleMemberTypeReferencesAndOverrideLoadsSuccessfully()
    1.61 +		{
    1.62 +			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
    1.63 +			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
    1.64 +			WarFoundryLoader.SetDefault(fixedLoader);
    1.65 +			FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race-with-override.racex");
    1.66 +			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.67 +			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
    1.68 +			Assert.AreEqual(1, unitTypes.Length);
    1.69 +			UnitType unitType = unitTypes[0];
    1.70 +			Stat[][] allStats = unitType.UnitStatsArrays;
    1.71 +			Stat[] stats = allStats[0];
    1.72 +			Assert.AreEqual(1, allStats.Length);
    1.73 +			Assert.AreEqual(9, stats.Length);
    1.74 +			Assert.AreEqual("M", stats[0].ParentSlotName);
    1.75 +			Assert.AreEqual("4", stats[0].SlotValueString);
    1.76 +			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
    1.77  		}
    1.78  		
    1.79  		[Test()]
    1.80 @@ -94,9 +135,9 @@
    1.81  			FileInfo raceFile = new FileInfo("testdata/single-unit-no-stats-race.racex");
    1.82  			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.83  			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
    1.84 -			Assert.That(unitTypes.Length == 1);
    1.85 +			Assert.AreEqual(1, unitTypes.Length);
    1.86  			UnitType unitType = unitTypes[0];
    1.87 -			Stat[] stats = unitType.UnitStatsArray;
    1.88 +			Stat[] stats = unitType.UnitStatsArrays[0];
    1.89  			Assert.That(stats.Length == race.GameSystem.StandardSystemStats.SlotCount);
    1.90  			
    1.91  			foreach (Stat stat in stats)
    1.92 @@ -104,7 +145,7 @@
    1.93  				Assert.AreEqual("", stat.SlotValueString);
    1.94  			}
    1.95  			
    1.96 -			Assert.AreEqual("Empire General", unitType.UnitStatsArrayWithName[0].SlotValueString);
    1.97 +			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
    1.98  		}
    1.99  	}
   1.100  }
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Apr 25 15:10:30 2010 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Mon Apr 26 19:50:47 2010 +0000
     2.3 @@ -99,6 +99,12 @@
     2.4      <None Include="testdata\extended-data.armyx">
     2.5        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     2.6      </None>
     2.7 +    <None Include="testdata\single-unit-multi-type-referencing-race.racex">
     2.8 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     2.9 +    </None>
    2.10 +    <None Include="testdata\single-unit-multi-type-referencing-race-with-override.racex">
    2.11 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.12 +    </None>
    2.13    </ItemGroup>
    2.14    <ItemGroup>
    2.15      <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-multi-type-referencing-race-with-override.racex	Mon Apr 26 19:50:47 2010 +0000
     3.3 @@ -0,0 +1,50 @@
     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 +			<stats>
     3.9 +				<stat name="M">4</stat>
    3.10 +				<stat name="WS">6</stat>
    3.11 +				<stat name="BS">6</stat>
    3.12 +				<stat name="S">4</stat>
    3.13 +				<stat name="T">4</stat>
    3.14 +				<stat name="W">3</stat>
    3.15 +				<stat name="I">6</stat>
    3.16 +				<stat name="A">4</stat>
    3.17 +				<stat name="Ld">9</stat>
    3.18 +			</stats>
    3.19 +			<unitMembers>
    3.20 +				<unitMember typeID="General"/>
    3.21 +				<unitMember typeID="Warhorse"/>
    3.22 +			</unitMembers>
    3.23 +		</unit>
    3.24 +	</units>
    3.25 +	<memberTypes>
    3.26 +		<memberType id="General" name="General">
    3.27 +			<stats>
    3.28 +				<stat name="M">4</stat>
    3.29 +				<stat name="WS">6</stat>
    3.30 +				<stat name="BS">6</stat>
    3.31 +				<stat name="S">4</stat>
    3.32 +				<stat name="T">4</stat>
    3.33 +				<stat name="W">3</stat>
    3.34 +				<stat name="I">6</stat>
    3.35 +				<stat name="A">4</stat>
    3.36 +				<stat name="Ld">9</stat>
    3.37 +			</stats>
    3.38 +		</memberType>
    3.39 +		<memberType id="Warhorse" name="Warhorse">
    3.40 +			<stats>
    3.41 +				<stat name="M">8</stat>
    3.42 +				<stat name="WS">3</stat>
    3.43 +				<stat name="BS">0</stat>
    3.44 +				<stat name="S">3</stat>
    3.45 +				<stat name="T">3</stat>
    3.46 +				<stat name="W">1</stat>
    3.47 +				<stat name="I">2</stat>
    3.48 +				<stat name="A">1</stat>
    3.49 +				<stat name="Ld">4</stat>
    3.50 +			</stats>
    3.51 +		</memberType>
    3.52 +	</memberTypes>
    3.53 +</race>
    3.54 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/testdata/single-unit-multi-type-referencing-race.racex	Mon Apr 26 19:50:47 2010 +0000
     4.3 @@ -0,0 +1,39 @@
     4.4 +<?xml version="1.0" encoding="UTF-8"?>
     4.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">
     4.6 +	<units>
     4.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     4.8 +			<unitMembers>
     4.9 +				<unitMember typeID="General"/>
    4.10 +				<unitMember typeID="Warhorse"/>
    4.11 +			</unitMembers>
    4.12 +		</unit>
    4.13 +	</units>
    4.14 +	<memberTypes>
    4.15 +		<memberType id="General" name="General">
    4.16 +			<stats>
    4.17 +				<stat name="M">4</stat>
    4.18 +				<stat name="WS">6</stat>
    4.19 +				<stat name="BS">6</stat>
    4.20 +				<stat name="S">4</stat>
    4.21 +				<stat name="T">4</stat>
    4.22 +				<stat name="W">3</stat>
    4.23 +				<stat name="I">6</stat>
    4.24 +				<stat name="A">4</stat>
    4.25 +				<stat name="Ld">9</stat>
    4.26 +			</stats>
    4.27 +		</memberType>
    4.28 +		<memberType id="Warhorse" name="Warhorse">
    4.29 +			<stats>
    4.30 +				<stat name="M">8</stat>
    4.31 +				<stat name="WS">3</stat>
    4.32 +				<stat name="BS">0</stat>
    4.33 +				<stat name="S">3</stat>
    4.34 +				<stat name="T">3</stat>
    4.35 +				<stat name="W">1</stat>
    4.36 +				<stat name="I">2</stat>
    4.37 +				<stat name="A">1</stat>
    4.38 +				<stat name="Ld">4</stat>
    4.39 +			</stats>
    4.40 +		</memberType>
    4.41 +	</memberTypes>
    4.42 +</race>
    4.43 \ No newline at end of file