changeset 43:00abd1c2f7d6

Re #268: Restructure stats for re-use * Test new stat line behaviour
author IBBoard <dev@ibboard.co.uk>
date Sun, 25 Apr 2010 15:10:30 +0000
parents d4f6e9ac981e
children 0de5d86bc1cb
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/default.systemx testdata/single-unit-no-stats-race.racex testdata/single-unit-race.racex testdata/single-unit-type-referencing-race.racex
diffstat 6 files changed, 157 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sat Mar 13 20:50:31 2010 +0000
+++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sun Apr 25 15:10:30 2010 +0000
@@ -18,28 +18,27 @@
 	[TestFixture()]
 	public class WarFoundryXmlRaceFactoryTest
 	{
+		[TearDown()]
+		public void AfterTestCleanup()
+		{
+			WarFoundryLoader.SetDefault(null);
+		}
+		
 		[Test()]
 		[ExpectedException(typeof(InvalidFileException), ExpectedMessage="Ability for Empire General with ID leaderOfMen did not exist in race definition")]
-		public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors ()
+		public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors()
 		{
-			try
-			{
-				GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/race-with-non-existant-ability.systemx"));
-				FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
-				WarFoundryLoader.SetDefault(fixedLoader);
-				FileInfo raceFile = new FileInfo ("testdata/race-with-non-existant-ability.racex");
-				Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
-				Category[] cats = race.Categories;
-			}
-			finally
-			{
-				WarFoundryLoader.SetDefault(null);
-			}
+			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/race-with-non-existant-ability.systemx"));
+			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
+			WarFoundryLoader.SetDefault(fixedLoader);
+			FileInfo raceFile = new FileInfo("testdata/race-with-non-existant-ability.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			Category[] cats = race.Categories;			
 		}
 		
 		[Test()]
 		[ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")]
-		public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors ()
+		public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors()
 		{
 			ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-game-system.race"));
 			Assert.AreEqual(1, objs.Count);
@@ -49,5 +48,63 @@
 			Race race = (Race)enumerator.Current;
 			Category[] cats = race.Categories;
 		}
+		
+		[Test()]
+		public void TestSingleUnitArmyLoadsSuccessfully()
+		{
+			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
+			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
+			WarFoundryLoader.SetDefault(fixedLoader);
+			FileInfo raceFile = new FileInfo("testdata/single-unit-race.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
+			Assert.That(unitTypes.Length == 1);
+			UnitType unitType = unitTypes[0];
+			Stat[] stats = unitType.UnitStatsArray;
+			Assert.That(stats.Length == 9);
+			Assert.AreEqual("M", stats[0].ParentSlotName);
+			Assert.AreEqual("4", stats[0].SlotValueString);
+			Assert.AreEqual("Empire General", unitType.UnitStatsArrayWithName[0].SlotValueString);
+		}
+		
+		[Test()]
+		public void TestSingleUnitArmyWithMemberTypeReferenceLoadsSuccessfully()
+		{
+			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
+			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
+			WarFoundryLoader.SetDefault(fixedLoader);
+			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"));
+			Assert.That(unitTypes.Length == 1);
+			UnitType unitType = unitTypes[0];
+			Stat[] stats = unitType.UnitStatsArray;
+			Assert.That(stats.Length == 9);
+			Assert.AreEqual("M", stats[0].ParentSlotName);
+			Assert.AreEqual("4", stats[0].SlotValueString);
+			Assert.AreEqual("General", unitType.UnitStatsArrayWithName[0].SlotValueString);
+		}
+		
+		[Test()]
+		public void TestSingleUnitArmyWithNoStatsReturnsUnitWithBlankStats()
+		{
+			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
+			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
+			WarFoundryLoader.SetDefault(fixedLoader);
+			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"));
+			Assert.That(unitTypes.Length == 1);
+			UnitType unitType = unitTypes[0];
+			Stat[] stats = unitType.UnitStatsArray;
+			Assert.That(stats.Length == race.GameSystem.StandardSystemStats.SlotCount);
+			
+			foreach (Stat stat in stats)
+			{
+				Assert.AreEqual("", stat.SlotValueString);
+			}
+			
+			Assert.AreEqual("Empire General", unitType.UnitStatsArrayWithName[0].SlotValueString);
+		}
 	}
 }
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Mar 13 20:50:31 2010 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Apr 25 15:10:30 2010 +0000
@@ -81,6 +81,18 @@
     <None Include="testdata\extended-data.racex">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="testdata\single-unit-race.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\default.systemx">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\single-unit-type-referencing-race.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\single-unit-no-stats-race.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
     <None Include="testdata\extended-data.systemx">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/default.systemx	Sun Apr 25 15:10:30 2010 +0000
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<system xmlns="http://ibboard.co.uk/warfoundry/system" xmlns:cats="http://ibboard.co.uk/warfoundry/cats" id="default" name="Default Game System" warn="false">
+	<categories>
+		<cats:cat id="cat1" name="Characters" minPercentage="0" maxPercentage="50" />
+		<cats:cat id="cat2" name="Regiments" minPercentage="25" maxPercentage="100" />
+		<cats:cat id="cat3" name="War Machines" minPercentage="0" maxPercentage="25" />
+		<cats:cat id="cat4" name="Monsters" minPercentage="0" maxPercentage="25" />
+		<cats:cat id="cat5" name="Allies" minPercentage="0" maxPercentage="25" />
+	</categories>
+	<sysStatsList defaultStats="default">
+		<sysStats id="default">
+			<sysStat name="M"/>
+			<sysStat name="WS"/>
+			<sysStat name="BS"/>
+			<sysStat name="S"/>
+			<sysStat name="T"/>
+			<sysStat name="W"/>
+			<sysStat name="I"/>
+			<sysStat name="A"/>
+			<sysStat name="Ld"/>
+		</sysStats>
+	</sysStatsList>
+</system>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/single-unit-no-stats-race.racex	Sun Apr 25 15:10:30 2010 +0000
@@ -0,0 +1,7 @@
+<?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">
+		</unit>
+	</units>
+</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/single-unit-race.racex	Sun Apr 25 15:10:30 2010 +0000
@@ -0,0 +1,18 @@
+<?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">
+			<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>
+		</unit>
+	</units>
+</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/single-unit-type-referencing-race.racex	Sun Apr 25 15:10:30 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="General"/>
+			</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