# HG changeset patch # User IBBoard # Date 1272311447 0 # Node ID 0de5d86bc1cbf1dc77f70d035da938ad84c283cc # Parent 00abd1c2f7d6ffd1bea2cb42dce9e5a168214a5b Re #268: Restructure stats for re-use * Add tests for multiple stat lines/referenced types and for overriding the stats diff -r 00abd1c2f7d6 -r 0de5d86bc1cb API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs --- 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); } } } diff -r 00abd1c2f7d6 -r 0de5d86bc1cb IBBoard.WarFoundry.API.Tests.csproj --- a/IBBoard.WarFoundry.API.Tests.csproj Sun Apr 25 15:10:30 2010 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Mon Apr 26 19:50:47 2010 +0000 @@ -99,6 +99,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + diff -r 00abd1c2f7d6 -r 0de5d86bc1cb testdata/single-unit-multi-type-referencing-race-with-override.racex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/single-unit-multi-type-referencing-race-with-override.racex Mon Apr 26 19:50:47 2010 +0000 @@ -0,0 +1,50 @@ + + + + + + 4 + 6 + 6 + 4 + 4 + 3 + 6 + 4 + 9 + + + + + + + + + + + 4 + 6 + 6 + 4 + 4 + 3 + 6 + 4 + 9 + + + + + 8 + 3 + 0 + 3 + 3 + 1 + 2 + 1 + 4 + + + + \ No newline at end of file diff -r 00abd1c2f7d6 -r 0de5d86bc1cb testdata/single-unit-multi-type-referencing-race.racex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/single-unit-multi-type-referencing-race.racex Mon Apr 26 19:50:47 2010 +0000 @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + 4 + 6 + 6 + 4 + 4 + 3 + 6 + 4 + 9 + + + + + 8 + 3 + 0 + 3 + 3 + 1 + 2 + 1 + 4 + + + + \ No newline at end of file