diff API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 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 82cd08385bfe
children 0de5d86bc1cb
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);
+		}
 	}
 }