annotate API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 51:9d68b5dd70b3

Re #270: Add multiple categories to API * Add test for unit being in multiple categories Also: * Add assertions in other tests that unit is cached in army
author IBBoard <dev@ibboard.co.uk>
date Wed, 19 May 2010 19:22:20 +0000
parents d3519f38a0f4
children 745820ad7656
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
47
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
5 using IBBoard.IO;
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
6 using IBBoard.WarFoundry.API.Objects;
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
7 using NUnit.Framework;
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 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
9 using System.IO;
50
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
10 using NUnit.Framework.SyntaxHelpers;
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 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
13 {
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14
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 [TestFixture()]
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 public class WarFoundryXmlRaceFactoryTest
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 {
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
19 [TearDown()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
20 public void AfterTestCleanup()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
21 {
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
22 WarFoundryLoader.SetDefault(null);
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
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 [Test()]
35
4302e6b2c5c1 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 33
diff changeset
26 [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
27 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
28 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
29 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
30 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
31 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
32 race.EnsureFullyLoaded();
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
33 }
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
34
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
35 [Test()]
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
36 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="TBD")]
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
37 public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError()
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
38 {
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
39 SetDefaultGameSystem();
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
40 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
41 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
42 race.EnsureFullyLoaded();
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 }
47
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
44
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
45 [Test()]
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
46 [ExpectedException(typeof(InvalidFileException), ExpectedMessage = "TBD")]
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
47 public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors()
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
48 {
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
49 SetDefaultGameSystem();
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
50 FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-reference.racex");
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
51 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
52 race.EnsureFullyLoaded();
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
53 }
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 [Test()]
35
4302e6b2c5c1 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 33
diff changeset
56 [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
57 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
58 {
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 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
60 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
61 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
62 enumerator.Reset();
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 enumerator.MoveNext();
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 Race race = (Race)enumerator.Current;
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
65 race.EnsureFullyLoaded();
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 }
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
67
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
68 [Test()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
69 public void TestSingleUnitArmyLoadsSuccessfully()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
70 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
71 SetDefaultGameSystem();
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
72 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
73 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
51
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
74 Assert.That(race.GetUnitType("Empire1"), Is.Not.Null);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
75 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
76 Assert.AreEqual(1, unitTypes.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
77 UnitType unitType = unitTypes[0];
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
78 Stat[] stats = unitType.UnitStatsArrays[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
79 Assert.AreEqual(9, stats.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
80 Assert.AreEqual("M", stats[0].ParentSlotName);
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
81 Assert.AreEqual("4", stats[0].SlotValueString);
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
82 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
83 }
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
84
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
85 [Test()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
86 public void TestSingleUnitArmyWithMemberTypeReferenceLoadsSuccessfully()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
87 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
88 SetDefaultGameSystem();
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
89 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
90 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
51
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
91 Assert.That(race.GetUnitType("Empire1"), Is.Not.Null);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
92 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
93 Assert.AreEqual(1, unitTypes.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
94 UnitType unitType = unitTypes[0];
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
95 Stat[] stats = unitType.UnitStatsArrays[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
96 Assert.AreEqual(9, stats.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
97 Assert.AreEqual("M", stats[0].ParentSlotName);
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
98 Assert.AreEqual("4", stats[0].SlotValueString);
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
99 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
100 }
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
101
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
102 [Test()]
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
103 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesLoadsSuccessfully()
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
104 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
105 SetDefaultGameSystem();
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
106 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
107 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
51
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
108 Assert.That(race.GetUnitType("Empire1"), Is.Not.Null);
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
109 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
110 Assert.AreEqual(1, unitTypes.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
111 UnitType unitType = unitTypes[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
112 Stat[][] stats = unitType.UnitStatsArrays;
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
113 Assert.AreEqual(2, stats.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
114 Assert.AreEqual("M", stats[0][0].ParentSlotName);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
115 Assert.AreEqual("4", stats[0][0].SlotValueString);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
116 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
117 Assert.AreEqual("M", stats[1][0].ParentSlotName);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
118 Assert.AreEqual("8", stats[1][0].SlotValueString);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
119 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
120 }
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
121
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
122 [Test()]
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
123 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesAndOverrideLoadsSuccessfully()
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
124 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
125 SetDefaultGameSystem();
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
126 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
127 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
51
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
128 Assert.That(race.GetUnitType("Empire1"), Is.Not.Null);
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
129 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
130 Assert.AreEqual(1, unitTypes.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
131 UnitType unitType = unitTypes[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
132 Stat[][] allStats = unitType.UnitStatsArrays;
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
133 Stat[] stats = allStats[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
134 Assert.AreEqual(1, allStats.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
135 Assert.AreEqual(9, stats.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
136 Assert.AreEqual("M", stats[0].ParentSlotName);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
137 Assert.AreEqual("4", stats[0].SlotValueString);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
138 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
139 }
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 [Test()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
142 public void TestSingleUnitArmyWithNoStatsReturnsUnitWithBlankStats()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
143 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
144 SetDefaultGameSystem();
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
145 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
146 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
51
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
147 Assert.That(race.GetUnitType("Empire1"), Is.Not.Null);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
148 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
149 Assert.AreEqual(1, unitTypes.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
150 UnitType unitType = unitTypes[0];
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
151 Stat[] stats = unitType.UnitStatsArrays[0];
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
152 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
153
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
154 foreach (Stat stat in stats)
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
155 {
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
156 Assert.AreEqual("", stat.SlotValueString);
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
157 }
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
158
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
159 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
160 }
50
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
161
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
162 [Test()]
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
163 public void TestSingleUnitArmyWithNoCategoriesUsesMainCategory()
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
164 {
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
165 SetDefaultGameSystem();
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
166 FileInfo raceFile = new FileInfo("testdata/single-unit-no-category.racex");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
167 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
168 Category category = race.GetCategory("cat1");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
169 UnitType[] unitTypes = race.GetUnitTypes(category);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
170 Assert.AreEqual(1, unitTypes.Length);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
171 UnitType unitType = unitTypes[0];
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
172 Assert.That(unitType.MainCategory, Is.EqualTo(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
173 Assert.That(unitType.Categories.Length, Is.EqualTo(1));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
174 Assert.That(unitType.Categories, Has.Member(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
175 }
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
176
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
177 [Test()]
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
178 public void TestSingleUnitArmyWithOneCategoryAndSameMainCategoryHasOneCategory()
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
179 {
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
180 SetDefaultGameSystem();
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
181 FileInfo raceFile = new FileInfo("testdata/single-unit-one-category-same-main-category.racex");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
182 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
183 Category category = race.GetCategory("cat1");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
184 UnitType[] unitTypes = race.GetUnitTypes(category);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
185 Assert.AreEqual(1, unitTypes.Length);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
186 UnitType unitType = unitTypes[0];
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
187 Assert.That(unitType.MainCategory, Is.EqualTo(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
188 Assert.That(unitType.Categories.Length, Is.EqualTo(1));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
189 Assert.That(unitType.Categories, Has.Member(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
190 }
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
191
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
192 [Test()]
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
193 public void TestSingleUnitArmyWithOneCategoryAndDifferentMainCategoryHasTwoCategories()
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
194 {
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
195 SetDefaultGameSystem();
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
196 FileInfo raceFile = new FileInfo("testdata/single-unit-one-category-different-main-category.racex");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
197 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
198 Category category = race.GetCategory("cat1");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
199 UnitType[] unitTypes = race.GetUnitTypes(category);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
200 Assert.AreEqual(1, unitTypes.Length);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
201 UnitType unitType = unitTypes[0];
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
202 Assert.That(unitType.MainCategory, Is.EqualTo(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
203 Assert.That(unitType.Categories.Length, Is.EqualTo(2));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
204 Assert.That(unitType.Categories, Has.Member(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
205 Assert.That(unitType.Categories, Has.Member(race.GetCategory("cat2")));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
206 }
51
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
207
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
208 [Test()]
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
209 public void TestSingleUnitArmyWithMultipleCategoriesIsInEachCategory()
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
210 {
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
211 SetDefaultGameSystem();
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
212 FileInfo raceFile = new FileInfo("testdata/single-unit-two-categories.racex");
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
213 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
214 UnitType unitType = race.GetUnitType("Empire1");
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
215 Assert.That(unitType.Categories.Length, Is.EqualTo(2));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
216 Category cat1 = race.GetCategory("cat1");
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
217 Category cat2 = race.GetCategory("cat2");
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
218 Assert.That(unitType.MainCategory, Is.EqualTo(cat1));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
219 Assert.That(unitType.Categories, Has.Member(cat1));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
220 Assert.That(unitType.Categories, Has.Member(cat2));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
221 Assert.That(race.GetUnitTypes(cat1), Is.All.EqualTo(unitType));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
222 UnitType[] unitTypesCat2 = race.GetUnitTypes(cat2);
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
223 Assert.That(unitTypesCat2, Has.Length(1));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
224 Assert.That(unitTypesCat2, Is.All.EqualTo(unitType));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
225 }
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
226
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
227 private static void SetDefaultGameSystem()
47
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
228 {
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
229 SetDefaultGameSystem(new FileInfo("testdata/default.systemx"));
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
230 }
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
231
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
232 public static void SetDefaultGameSystem(FileInfo systemFile)
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
233 {
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
234 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), systemFile);
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
235 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
236 WarFoundryLoader.SetDefault(fixedLoader);
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
237 }
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
238 }
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
239 }