diff API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 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
line wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sun Apr 25 15:10:30 2010 +0000
+++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Mon Apr 26 19:50:47 2010 +0000
@@ -58,13 +58,13 @@
 			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);
+			Assert.AreEqual(1, unitTypes.Length);
 			UnitType unitType = unitTypes[0];
-			Stat[] stats = unitType.UnitStatsArray;
-			Assert.That(stats.Length == 9);
+			Stat[] stats = unitType.UnitStatsArrays[0];
+			Assert.AreEqual(9, stats.Length);
 			Assert.AreEqual("M", stats[0].ParentSlotName);
 			Assert.AreEqual("4", stats[0].SlotValueString);
-			Assert.AreEqual("Empire General", unitType.UnitStatsArrayWithName[0].SlotValueString);
+			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
 		}
 		
 		[Test()]
@@ -76,13 +76,54 @@
 			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);
+			Assert.AreEqual(1, unitTypes.Length);
 			UnitType unitType = unitTypes[0];
-			Stat[] stats = unitType.UnitStatsArray;
-			Assert.That(stats.Length == 9);
+			Stat[] stats = unitType.UnitStatsArrays[0];
+			Assert.AreEqual(9, stats.Length);
 			Assert.AreEqual("M", stats[0].ParentSlotName);
 			Assert.AreEqual("4", stats[0].SlotValueString);
-			Assert.AreEqual("General", unitType.UnitStatsArrayWithName[0].SlotValueString);
+			Assert.AreEqual("General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
+		}
+		
+		[Test()]
+		public void TestSingleUnitArmyWithMultipleMemberTypeReferencesLoadsSuccessfully()
+		{
+			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-multi-type-referencing-race.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
+			Assert.AreEqual(1, unitTypes.Length);
+			UnitType unitType = unitTypes[0];
+			Stat[][] stats = unitType.UnitStatsArrays;
+			Assert.AreEqual(2, stats.Length);
+			Assert.AreEqual("M", stats[0][0].ParentSlotName);
+			Assert.AreEqual("4", stats[0][0].SlotValueString);
+			Assert.AreEqual("General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
+			Assert.AreEqual("M", stats[1][0].ParentSlotName);
+			Assert.AreEqual("8", stats[1][0].SlotValueString);
+			Assert.AreEqual("Warhorse", unitType.UnitStatsArraysWithName[1][0].SlotValueString);
+		}
+		
+		[Test()]
+		public void TestSingleUnitArmyWithMultipleMemberTypeReferencesAndOverrideLoadsSuccessfully()
+		{
+			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-multi-type-referencing-race-with-override.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
+			Assert.AreEqual(1, unitTypes.Length);
+			UnitType unitType = unitTypes[0];
+			Stat[][] allStats = unitType.UnitStatsArrays;
+			Stat[] stats = allStats[0];
+			Assert.AreEqual(1, allStats.Length);
+			Assert.AreEqual(9, stats.Length);
+			Assert.AreEqual("M", stats[0].ParentSlotName);
+			Assert.AreEqual("4", stats[0].SlotValueString);
+			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
 		}
 		
 		[Test()]
@@ -94,9 +135,9 @@
 			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);
+			Assert.AreEqual(1, unitTypes.Length);
 			UnitType unitType = unitTypes[0];
-			Stat[] stats = unitType.UnitStatsArray;
+			Stat[] stats = unitType.UnitStatsArrays[0];
 			Assert.That(stats.Length == race.GameSystem.StandardSystemStats.SlotCount);
 			
 			foreach (Stat stat in stats)
@@ -104,7 +145,7 @@
 				Assert.AreEqual("", stat.SlotValueString);
 			}
 			
-			Assert.AreEqual("Empire General", unitType.UnitStatsArrayWithName[0].SlotValueString);
+			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
 		}
 	}
 }