Mercurial > repos > IBBoard.WarFoundry.API.Tests
annotate 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 |
rev | line source |
---|---|
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (WarFoundryXmlRaceFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.Collections.Generic; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using System.IO; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using System.Xml; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 using NUnit.Framework; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 using IBBoard.WarFoundry.API.Objects; |
35
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
11 using IBBoard.WarFoundry.API.Objects.Mock; |
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 using IBBoard.IO; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 namespace IBBoard.WarFoundry.API.Factories.Xml |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 { |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 [TestFixture()] |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 public class WarFoundryXmlRaceFactoryTest |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 { |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
21 [TearDown()] |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
22 public void AfterTestCleanup() |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
23 { |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
24 WarFoundryLoader.SetDefault(null); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
25 } |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
26 |
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 [Test()] |
35
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
28 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Ability for Empire General with ID leaderOfMen did not exist in race definition")] |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
29 public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors() |
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 { |
45
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
31 SetDefaultGameSystem(new FileInfo("testdata/race-with-non-existant-ability.systemx")); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
32 FileInfo raceFile = new FileInfo("testdata/race-with-non-existant-ability.racex"); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
33 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); |
45
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
34 race.EnsureFullyLoaded(); |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
35 } |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
36 |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
37 [Test()] |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
38 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="TBD")] |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
39 public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError() |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
40 { |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
41 SetDefaultGameSystem(); |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
42 FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex"); |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
43 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
44 race.EnsureFullyLoaded(); |
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 } |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 [Test()] |
35
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
48 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")] |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
49 public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors() |
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 { |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-game-system.race")); |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 Assert.AreEqual(1, objs.Count); |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator(); |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 enumerator.Reset(); |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 enumerator.MoveNext(); |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 Race race = (Race)enumerator.Current; |
45
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
57 race.EnsureFullyLoaded(); |
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 } |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
59 |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
60 [Test()] |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
61 public void TestSingleUnitArmyLoadsSuccessfully() |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
62 { |
45
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
63 SetDefaultGameSystem(); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
64 FileInfo raceFile = new FileInfo("testdata/single-unit-race.racex"); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
65 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
66 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); |
44
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
67 Assert.AreEqual(1, unitTypes.Length); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
68 UnitType unitType = unitTypes[0]; |
44
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
69 Stat[] stats = unitType.UnitStatsArrays[0]; |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
70 Assert.AreEqual(9, stats.Length); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
71 Assert.AreEqual("M", stats[0].ParentSlotName); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
72 Assert.AreEqual("4", stats[0].SlotValueString); |
44
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
73 Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
74 } |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
75 |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
76 [Test()] |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
77 public void TestSingleUnitArmyWithMemberTypeReferenceLoadsSuccessfully() |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
78 { |
45
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
79 SetDefaultGameSystem(); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
80 FileInfo raceFile = new FileInfo("testdata/single-unit-type-referencing-race.racex"); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
81 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
82 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); |
44
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
83 Assert.AreEqual(1, unitTypes.Length); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
84 UnitType unitType = unitTypes[0]; |
44
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
85 Stat[] stats = unitType.UnitStatsArrays[0]; |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
86 Assert.AreEqual(9, stats.Length); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
87 Assert.AreEqual("M", stats[0].ParentSlotName); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
88 Assert.AreEqual("4", stats[0].SlotValueString); |
44
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
89 Assert.AreEqual("General", unitType.UnitStatsArraysWithName[0][0].SlotValueString); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
90 } |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
91 |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
92 [Test()] |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
93 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesLoadsSuccessfully() |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
94 { |
45
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
95 SetDefaultGameSystem(); |
44
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
96 FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race.racex"); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
97 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
98 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
99 Assert.AreEqual(1, unitTypes.Length); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
100 UnitType unitType = unitTypes[0]; |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
101 Stat[][] stats = unitType.UnitStatsArrays; |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
102 Assert.AreEqual(2, stats.Length); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
103 Assert.AreEqual("M", stats[0][0].ParentSlotName); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
104 Assert.AreEqual("4", stats[0][0].SlotValueString); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
105 Assert.AreEqual("General", unitType.UnitStatsArraysWithName[0][0].SlotValueString); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
106 Assert.AreEqual("M", stats[1][0].ParentSlotName); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
107 Assert.AreEqual("8", stats[1][0].SlotValueString); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
108 Assert.AreEqual("Warhorse", unitType.UnitStatsArraysWithName[1][0].SlotValueString); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
109 } |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
110 |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
111 [Test()] |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
112 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesAndOverrideLoadsSuccessfully() |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
113 { |
45
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
114 SetDefaultGameSystem(); |
44
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
115 FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race-with-override.racex"); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
116 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
117 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
118 Assert.AreEqual(1, unitTypes.Length); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
119 UnitType unitType = unitTypes[0]; |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
120 Stat[][] allStats = unitType.UnitStatsArrays; |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
121 Stat[] stats = allStats[0]; |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
122 Assert.AreEqual(1, allStats.Length); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
123 Assert.AreEqual(9, stats.Length); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
124 Assert.AreEqual("M", stats[0].ParentSlotName); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
125 Assert.AreEqual("4", stats[0].SlotValueString); |
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
126 Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
127 } |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
128 |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
129 [Test()] |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
130 public void TestSingleUnitArmyWithNoStatsReturnsUnitWithBlankStats() |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
131 { |
45
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
132 SetDefaultGameSystem(); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
133 FileInfo raceFile = new FileInfo("testdata/single-unit-no-stats-race.racex"); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
134 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
135 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1")); |
44
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
136 Assert.AreEqual(1, unitTypes.Length); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
137 UnitType unitType = unitTypes[0]; |
44
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
138 Stat[] stats = unitType.UnitStatsArrays[0]; |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
139 Assert.That(stats.Length == race.GameSystem.StandardSystemStats.SlotCount); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
140 |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
141 foreach (Stat stat in stats) |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
142 { |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
143 Assert.AreEqual("", stat.SlotValueString); |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
144 } |
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
145 |
44
0de5d86bc1cb
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
43
diff
changeset
|
146 Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString); |
43
00abd1c2f7d6
Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
147 } |
45
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
148 |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
149 private static void SetDefaultGameSystem() |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
150 { |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
151 FileInfo systemFile = new FileInfo("testdata/default.systemx"); |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
152 SetDefaultGameSystem(systemFile); |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
153 } |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
154 |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
155 public static void SetDefaultGameSystem(FileInfo systemFile) |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
156 { |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
157 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), systemFile); |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
158 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system); |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
159 WarFoundryLoader.SetDefault(fixedLoader); |
04d7cd276b1d
Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
160 } |
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
161 } |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
162 } |