# HG changeset patch # User IBBoard # Date 1272208230 0 # Node ID 00abd1c2f7d6ffd1bea2cb42dce9e5a168214a5b # Parent d4f6e9ac981ef097a61beb0a517e02aefd810d1a Re #268: Restructure stats for re-use * Test new stat line behaviour diff -r d4f6e9ac981e -r 00abd1c2f7d6 API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs --- 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 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); + } } } diff -r d4f6e9ac981e -r 00abd1c2f7d6 IBBoard.WarFoundry.API.Tests.csproj --- 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 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest diff -r d4f6e9ac981e -r 00abd1c2f7d6 testdata/default.systemx --- /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 @@ + + + + + + + + + + + + + + + + + + + + + + + diff -r d4f6e9ac981e -r 00abd1c2f7d6 testdata/single-unit-no-stats-race.racex --- /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 @@ + + + + + + + \ No newline at end of file diff -r d4f6e9ac981e -r 00abd1c2f7d6 testdata/single-unit-race.racex --- /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 @@ + + + + + + 4 + 6 + 6 + 4 + 4 + 3 + 6 + 4 + 9 + + + + \ No newline at end of file diff -r d4f6e9ac981e -r 00abd1c2f7d6 testdata/single-unit-type-referencing-race.racex --- /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 @@ + + + + + + + + + + + + + 4 + 6 + 6 + 4 + 4 + 3 + 6 + 4 + 9 + + + + \ No newline at end of file