Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
comparison 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 |
comparison
equal
deleted
inserted
replaced
42:d4f6e9ac981e | 43:00abd1c2f7d6 |
---|---|
16 | 16 |
17 | 17 |
18 [TestFixture()] | 18 [TestFixture()] |
19 public class WarFoundryXmlRaceFactoryTest | 19 public class WarFoundryXmlRaceFactoryTest |
20 { | 20 { |
21 [TearDown()] | |
22 public void AfterTestCleanup() | |
23 { | |
24 WarFoundryLoader.SetDefault(null); | |
25 } | |
26 | |
21 [Test()] | 27 [Test()] |
22 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Ability for Empire General with ID leaderOfMen did not exist in race definition")] | 28 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Ability for Empire General with ID leaderOfMen did not exist in race definition")] |
23 public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors () | 29 public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors() |
24 { | 30 { |
25 try | 31 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/race-with-non-existant-ability.systemx")); |
26 { | 32 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system); |
27 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/race-with-non-existant-ability.systemx")); | 33 WarFoundryLoader.SetDefault(fixedLoader); |
28 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system); | 34 FileInfo raceFile = new FileInfo("testdata/race-with-non-existant-ability.racex"); |
29 WarFoundryLoader.SetDefault(fixedLoader); | 35 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); |
30 FileInfo raceFile = new FileInfo ("testdata/race-with-non-existant-ability.racex"); | 36 Category[] cats = race.Categories; |
31 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); | |
32 Category[] cats = race.Categories; | |
33 } | |
34 finally | |
35 { | |
36 WarFoundryLoader.SetDefault(null); | |
37 } | |
38 } | 37 } |
39 | 38 |
40 [Test()] | 39 [Test()] |
41 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")] | 40 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")] |
42 public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors () | 41 public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors() |
43 { | 42 { |
44 ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-game-system.race")); | 43 ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-game-system.race")); |
45 Assert.AreEqual(1, objs.Count); | 44 Assert.AreEqual(1, objs.Count); |
46 IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator(); | 45 IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator(); |
47 enumerator.Reset(); | 46 enumerator.Reset(); |
48 enumerator.MoveNext(); | 47 enumerator.MoveNext(); |
49 Race race = (Race)enumerator.Current; | 48 Race race = (Race)enumerator.Current; |
50 Category[] cats = race.Categories; | 49 Category[] cats = race.Categories; |
51 } | 50 } |
51 | |
52 [Test()] | |
53 public void TestSingleUnitArmyLoadsSuccessfully() | |
54 { | |
55 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx")); | |
56 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system); | |
57 WarFoundryLoader.SetDefault(fixedLoader); | |
58 FileInfo raceFile = new FileInfo("testdata/single-unit-race.racex"); | |
59 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); | |
60 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); | |
61 Assert.That(unitTypes.Length == 1); | |
62 UnitType unitType = unitTypes[0]; | |
63 Stat[] stats = unitType.UnitStatsArray; | |
64 Assert.That(stats.Length == 9); | |
65 Assert.AreEqual("M", stats[0].ParentSlotName); | |
66 Assert.AreEqual("4", stats[0].SlotValueString); | |
67 Assert.AreEqual("Empire General", unitType.UnitStatsArrayWithName[0].SlotValueString); | |
68 } | |
69 | |
70 [Test()] | |
71 public void TestSingleUnitArmyWithMemberTypeReferenceLoadsSuccessfully() | |
72 { | |
73 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx")); | |
74 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system); | |
75 WarFoundryLoader.SetDefault(fixedLoader); | |
76 FileInfo raceFile = new FileInfo("testdata/single-unit-type-referencing-race.racex"); | |
77 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); | |
78 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); | |
79 Assert.That(unitTypes.Length == 1); | |
80 UnitType unitType = unitTypes[0]; | |
81 Stat[] stats = unitType.UnitStatsArray; | |
82 Assert.That(stats.Length == 9); | |
83 Assert.AreEqual("M", stats[0].ParentSlotName); | |
84 Assert.AreEqual("4", stats[0].SlotValueString); | |
85 Assert.AreEqual("General", unitType.UnitStatsArrayWithName[0].SlotValueString); | |
86 } | |
87 | |
88 [Test()] | |
89 public void TestSingleUnitArmyWithNoStatsReturnsUnitWithBlankStats() | |
90 { | |
91 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx")); | |
92 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system); | |
93 WarFoundryLoader.SetDefault(fixedLoader); | |
94 FileInfo raceFile = new FileInfo("testdata/single-unit-no-stats-race.racex"); | |
95 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); | |
96 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); | |
97 Assert.That(unitTypes.Length == 1); | |
98 UnitType unitType = unitTypes[0]; | |
99 Stat[] stats = unitType.UnitStatsArray; | |
100 Assert.That(stats.Length == race.GameSystem.StandardSystemStats.SlotCount); | |
101 | |
102 foreach (Stat stat in stats) | |
103 { | |
104 Assert.AreEqual("", stat.SlotValueString); | |
105 } | |
106 | |
107 Assert.AreEqual("Empire General", unitType.UnitStatsArrayWithName[0].SlotValueString); | |
108 } | |
52 } | 109 } |
53 } | 110 } |