comparison API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 45:04d7cd276b1d

Re #274: crash when missing unitMember id * Add test data and unit test for error Also: * Refactor out common test code (setting up system)
author IBBoard <dev@ibboard.co.uk>
date Wed, 12 May 2010 19:30:06 +0000
parents 0de5d86bc1cb
children b4b4bde843d7
comparison
equal deleted inserted replaced
44:0de5d86bc1cb 45:04d7cd276b1d
26 26
27 [Test()] 27 [Test()]
28 [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")]
29 public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors() 29 public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors()
30 { 30 {
31 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/race-with-non-existant-ability.systemx")); 31 SetDefaultGameSystem(new FileInfo("testdata/race-with-non-existant-ability.systemx"));
32 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
33 WarFoundryLoader.SetDefault(fixedLoader);
34 FileInfo raceFile = new FileInfo("testdata/race-with-non-existant-ability.racex"); 32 FileInfo raceFile = new FileInfo("testdata/race-with-non-existant-ability.racex");
35 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 33 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
36 Category[] cats = race.Categories; 34 race.EnsureFullyLoaded();
35 }
36
37 [Test()]
38 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="TBD")]
39 public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError()
40 {
41 SetDefaultGameSystem();
42 FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex");
43 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
44 race.EnsureFullyLoaded();
37 } 45 }
38 46
39 [Test()] 47 [Test()]
40 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")] 48 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")]
41 public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors() 49 public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors()
44 Assert.AreEqual(1, objs.Count); 52 Assert.AreEqual(1, objs.Count);
45 IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator(); 53 IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator();
46 enumerator.Reset(); 54 enumerator.Reset();
47 enumerator.MoveNext(); 55 enumerator.MoveNext();
48 Race race = (Race)enumerator.Current; 56 Race race = (Race)enumerator.Current;
49 Category[] cats = race.Categories; 57 race.EnsureFullyLoaded();
50 } 58 }
51 59
52 [Test()] 60 [Test()]
53 public void TestSingleUnitArmyLoadsSuccessfully() 61 public void TestSingleUnitArmyLoadsSuccessfully()
54 { 62 {
55 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx")); 63 SetDefaultGameSystem();
56 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
57 WarFoundryLoader.SetDefault(fixedLoader);
58 FileInfo raceFile = new FileInfo("testdata/single-unit-race.racex"); 64 FileInfo raceFile = new FileInfo("testdata/single-unit-race.racex");
59 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 65 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
60 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); 66 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
61 Assert.AreEqual(1, unitTypes.Length); 67 Assert.AreEqual(1, unitTypes.Length);
62 UnitType unitType = unitTypes[0]; 68 UnitType unitType = unitTypes[0];
68 } 74 }
69 75
70 [Test()] 76 [Test()]
71 public void TestSingleUnitArmyWithMemberTypeReferenceLoadsSuccessfully() 77 public void TestSingleUnitArmyWithMemberTypeReferenceLoadsSuccessfully()
72 { 78 {
73 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx")); 79 SetDefaultGameSystem();
74 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
75 WarFoundryLoader.SetDefault(fixedLoader);
76 FileInfo raceFile = new FileInfo("testdata/single-unit-type-referencing-race.racex"); 80 FileInfo raceFile = new FileInfo("testdata/single-unit-type-referencing-race.racex");
77 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 81 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
78 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); 82 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
79 Assert.AreEqual(1, unitTypes.Length); 83 Assert.AreEqual(1, unitTypes.Length);
80 UnitType unitType = unitTypes[0]; 84 UnitType unitType = unitTypes[0];
86 } 90 }
87 91
88 [Test()] 92 [Test()]
89 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesLoadsSuccessfully() 93 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesLoadsSuccessfully()
90 { 94 {
91 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx")); 95 SetDefaultGameSystem();
92 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
93 WarFoundryLoader.SetDefault(fixedLoader);
94 FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race.racex"); 96 FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race.racex");
95 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 97 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
96 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); 98 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
97 Assert.AreEqual(1, unitTypes.Length); 99 Assert.AreEqual(1, unitTypes.Length);
98 UnitType unitType = unitTypes[0]; 100 UnitType unitType = unitTypes[0];
107 } 109 }
108 110
109 [Test()] 111 [Test()]
110 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesAndOverrideLoadsSuccessfully() 112 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesAndOverrideLoadsSuccessfully()
111 { 113 {
112 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx")); 114 SetDefaultGameSystem();
113 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
114 WarFoundryLoader.SetDefault(fixedLoader);
115 FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race-with-override.racex"); 115 FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race-with-override.racex");
116 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 116 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
117 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); 117 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
118 Assert.AreEqual(1, unitTypes.Length); 118 Assert.AreEqual(1, unitTypes.Length);
119 UnitType unitType = unitTypes[0]; 119 UnitType unitType = unitTypes[0];
127 } 127 }
128 128
129 [Test()] 129 [Test()]
130 public void TestSingleUnitArmyWithNoStatsReturnsUnitWithBlankStats() 130 public void TestSingleUnitArmyWithNoStatsReturnsUnitWithBlankStats()
131 { 131 {
132 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx")); 132 SetDefaultGameSystem();
133 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
134 WarFoundryLoader.SetDefault(fixedLoader);
135 FileInfo raceFile = new FileInfo("testdata/single-unit-no-stats-race.racex"); 133 FileInfo raceFile = new FileInfo("testdata/single-unit-no-stats-race.racex");
136 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 134 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
137 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); 135 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
138 Assert.AreEqual(1, unitTypes.Length); 136 Assert.AreEqual(1, unitTypes.Length);
139 UnitType unitType = unitTypes[0]; 137 UnitType unitType = unitTypes[0];
145 Assert.AreEqual("", stat.SlotValueString); 143 Assert.AreEqual("", stat.SlotValueString);
146 } 144 }
147 145
148 Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString); 146 Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
149 } 147 }
148
149 private static void SetDefaultGameSystem()
150 {
151 FileInfo systemFile = new FileInfo("testdata/default.systemx");
152 SetDefaultGameSystem(systemFile);
153 }
154
155 public static void SetDefaultGameSystem(FileInfo systemFile)
156 {
157 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), systemFile);
158 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
159 WarFoundryLoader.SetDefault(fixedLoader);
160 }
150 } 161 }
151 } 162 }