annotate API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 212:325943cb1db0

Re #379: Fix validation of requirements to check for unit * Create common base class for requirement testing with helper methods * Rework unit adding tests in UnitRequiresNoMoreThanNOfUnitTypeRequirementTest to new structure
author IBBoard <dev@ibboard.co.uk>
date Sun, 26 Feb 2012 15:20:48 +0000
parents ea104de9189e
children c6313a2c08a2
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
57
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
5 using System;
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
6 using System.Collections.Generic;
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
7 using System.IO;
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
8 using System.Xml.Schema;
47
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
9 using IBBoard.IO;
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
10 using IBBoard.WarFoundry.API.Objects;
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
11 using NUnit.Framework;
50
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
12 using NUnit.Framework.SyntaxHelpers;
149
71b9364f0276 Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 147
diff changeset
13 using IBBoard.WarFoundry.API.Objects.Requirement;
158
d0b8c43f705f Fixes #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 149
diff changeset
14 using IBBoard.WarFoundry.API.Factories.Requirement;
33
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 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
17 {
57
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
18 //It would be better to explicitly check that some of these errors are certain types of schema validation error, but Mono and .Net have
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
19 //different exception messages for the same text and just have one class for all schema exceptions of all types.
58
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
20 //We can't even check line numbers because Mono embeds them in the text and the actual line number is the end of the file.
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 [TestFixture()]
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 public class WarFoundryXmlRaceFactoryTest
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 {
158
d0b8c43f705f Fixes #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 149
diff changeset
24 [SetUp()]
d0b8c43f705f Fixes #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 149
diff changeset
25 public void RegisterRequirementHandler()
d0b8c43f705f Fixes #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 149
diff changeset
26 {
d0b8c43f705f Fixes #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 149
diff changeset
27 WarFoundryLoader.RegisterRequirementFactory(new UnitRequiresAtLeastNUnitsRequirementFactory());
d0b8c43f705f Fixes #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 149
diff changeset
28 }
d0b8c43f705f Fixes #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 149
diff changeset
29
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
30 [TearDown()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
31 public void AfterTestCleanup()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
32 {
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
33 WarFoundryLoader.SetDefault(null);
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
34 }
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
35
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 [Test()]
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
37 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
38 {
65
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
39 TestFileValidationFailure("testdata/xml-race-factory/non-existant-ability.racex");
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
40 }
61
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
41
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
42 [Test()]
62
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
43 public void TestCompleteLoadingOnRaceWithDuplicateAbilityIdErrors()
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
44 {
65
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
45 TestFileValidationFailure("testdata/xml-race-factory/duplicate-ability.racex");
62
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
46 }
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
47
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
48 [Test()]
61
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
49 public void TestCompleteLoadingOnRaceWithAbilityLoadsData()
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
50 {
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
51 SetDefaultGameSystem();
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
52 FileInfo raceFile = new FileInfo("testdata/xml-race-factory/existing-ability.racex");
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
53 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
54 UnitType unitType = race.GetUnitType("Empire1");
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
55 Ability ability = race.GetAbility("leaderOfMen");
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
56 Assert.That(ability.Name, Is.EqualTo("Leader of Men"));
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
57 Assert.That(ability.Description, Is.EqualTo("All men will follow the character and can use his leadership"));
62
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
58 Assert.That(unitType.GetRequiredAbilities(), Has.Member(ability));
61
27625216d8d6 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
59 }
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
60
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
61 [Test()]
62
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
62 public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDErrors()
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
63 {
65
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
64 TestFileValidationFailure("testdata/xml-race-factory/non-existant-member-type.racex");
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 }
47
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
66
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
67 [Test()]
62
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
68 public void TestCompleteLoadingOnRaceWithDuplicateMemberTypeIDErrors()
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
69 {
65
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
70 TestFileValidationFailure("testdata/xml-race-factory/duplicate-member-type.racex");
62
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
71 }
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
72
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
73 [Test()]
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
74 public void TestCompleteLoadingOnRaceWithMemberTypeLoadsData()
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
75 {
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
76 SetDefaultGameSystem();
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
77 FileInfo raceFile = new FileInfo("testdata/xml-race-factory/existing-member-type.racex");
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
78 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
79 UnitMemberType memberType = race.GetUnitMemberType("General");
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
80 Assert.That(memberType.Name, Is.EqualTo("General"));
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
81 }
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
82
ef8950a5f4cb Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 61
diff changeset
83 [Test()]
47
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
84 public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors()
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
85 {
65
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
86 TestFileValidationFailure("testdata/xml-race-factory/single-unit-with-invalid-equipment-slot-reference.racex");
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
87 }
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
88
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
89 [Test()]
66
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
90 public void TestCompleteLoadingOnRaceWithDuplicateEquipmentSlotErrors()
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
91 {
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
92 TestFileValidationFailure("testdata/xml-race-factory/single-unit-with-duplicate-equipment-slot.racex");
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
93 }
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
94
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
95 [Test()]
63
a9163f8dfba1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 62
diff changeset
96 public void TestCompleteLoadingOnRaceWithCorrectEquipmentSlotLoads()
a9163f8dfba1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 62
diff changeset
97 {
a9163f8dfba1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 62
diff changeset
98 SetDefaultGameSystem();
a9163f8dfba1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 62
diff changeset
99 FileInfo raceFile = new FileInfo("testdata/xml-race-factory/single-unit-with-valid-equipment-slot-reference.racex");
a9163f8dfba1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 62
diff changeset
100 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
64
6f638d6f400f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 63
diff changeset
101 UnitType unitType = race.GetUnitType("Empire1");
6f638d6f400f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 63
diff changeset
102 UnitEquipmentItem unitEquipmentItem = unitType.GetEquipmentItem("Empire1equip1");
63
a9163f8dfba1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 62
diff changeset
103 Assert.That(unitEquipmentItem.SlotName, Is.EqualTo("slot1"));
a9163f8dfba1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 62
diff changeset
104 }
65
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
105
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
106 [Test()]
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
107 public void TestCompleteLoadingOnRaceWithNoEquipmentSlotLimitErrors()
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
108 {
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
109 TestFileValidationFailure("testdata/xml-race-factory/single-unit-with-no-equipment-slot-limit.racex");
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
110 }
63
a9163f8dfba1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 62
diff changeset
111
a9163f8dfba1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 62
diff changeset
112 [Test()]
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
113 public void TestCompleteLoadingOnRaceWithIncorrectEquipmentIDError()
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
114 {
66
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
115 TestFileValidationFailure("testdata/xml-race-factory/single-unit-with-invalid-equipment-reference.racex");
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
116 }
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
117
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
118 [Test()]
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
119 public void TestCompleteLoadingOnRaceWithDuplicateEquipmentIDError()
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
120 {
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
121 TestFileValidationFailure("testdata/xml-race-factory/duplicate-equipment-id.racex");
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
122 }
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
123
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
124 [Test()]
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
125 public void TestCompleteLoadingOnRaceWithCorrectEquipmentIDLoads()
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
126 {
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
127 SetDefaultGameSystem();
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
128 FileInfo raceFile = new FileInfo("testdata/xml-race-factory/single-unit-with-valid-equipment-reference.racex");
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
129 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
130 UnitType unitType = race.GetUnitType("Empire1");
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
131 Assert.That(unitType.GetEquipmentItem("Empire1equip1"), Is.Not.Null);
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
132 }
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
133
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
134 [Test()]
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
135 public void TestCompleteLoadingOnRaceWithIncorrectContainedUnitIDError()
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
136 {
66
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
137 TestFileValidationFailure("testdata/xml-race-factory/invalid-contained-unit-reference.racex");
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
138 }
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
139
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
140 [Test()]
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
141 public void TestCompleteLoadingOnRaceWithCorrectContainedUnitIDLoadsData()
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
142 {
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
143 SetDefaultGameSystem();
66
f671ead260b1 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
144 FileInfo raceFile = new FileInfo("testdata/xml-race-factory/valid-contained-unit-reference.racex");
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
145 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
146 UnitType unitType = race.GetUnitType("Empire1");
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
147 Assert.That(unitType.ContainedUnitTypes, Has.Length(1));
47
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
148 }
60
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
149
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
150 [Test()]
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
151 public void TestCompleteLoadingOnRaceWithDuplicateExtraDataKeyErrors()
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
152 {
65
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
153 TestFileValidationFailure("testdata/xml-race-factory/duplicate-extra-data-key.racex");
60
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
154 }
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
155
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
156 [Test()]
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
157 public void TestCompleteLoadingOnRaceWithDifferentExtraDataKeysLoadsData()
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
158 {
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
159 SetDefaultGameSystem();
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
160 FileInfo raceFile = new FileInfo("testdata/xml-race-factory/different-extra-data-key.racex");
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
161 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
162 UnitType unitType = race.GetUnitType("Empire1");
80
102887bd063b Fixes #139: Load additional data for units
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
163 Assert.That(unitType.GetExtraData("data1"), Is.EqualTo("SomeStringHere"));
60
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
164 }
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 [Test()]
35
4302e6b2c5c1 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 33
diff changeset
167 [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
168 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
169 {
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170 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
171 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
172 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
173 enumerator.Reset();
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
174 enumerator.MoveNext();
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 Race race = (Race)enumerator.Current;
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
176 race.EnsureFullyLoaded();
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177 }
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
178
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
179 [Test()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
180 public void TestSingleUnitArmyLoadsSuccessfully()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
181 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
182 SetDefaultGameSystem();
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
183 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
184 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
185 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
186 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
187 Assert.AreEqual(1, unitTypes.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
188 UnitType unitType = unitTypes[0];
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
189 Stat[] stats = unitType.UnitStatsArrays[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
190 Assert.AreEqual(9, stats.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
191 Assert.AreEqual("M", stats[0].ParentSlotName);
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
192 Assert.AreEqual("4", stats[0].SlotValueString);
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
193 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
194 }
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
195
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
196 [Test()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
197 public void TestSingleUnitArmyWithMemberTypeReferenceLoadsSuccessfully()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
198 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
199 SetDefaultGameSystem();
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
200 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
201 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
202 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
203 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
204 Assert.AreEqual(1, unitTypes.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
205 UnitType unitType = unitTypes[0];
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
206 Stat[] stats = unitType.UnitStatsArrays[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
207 Assert.AreEqual(9, stats.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
208 Assert.AreEqual("M", stats[0].ParentSlotName);
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
209 Assert.AreEqual("4", stats[0].SlotValueString);
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
210 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
211 }
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
212
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
213 [Test()]
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
214 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesLoadsSuccessfully()
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
215 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
216 SetDefaultGameSystem();
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
217 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
218 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
219 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
220 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
221 Assert.AreEqual(1, unitTypes.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
222 UnitType unitType = unitTypes[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
223 Stat[][] stats = unitType.UnitStatsArrays;
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
224 Assert.AreEqual(2, stats.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
225 Assert.AreEqual("M", stats[0][0].ParentSlotName);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
226 Assert.AreEqual("4", stats[0][0].SlotValueString);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
227 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
228 Assert.AreEqual("M", stats[1][0].ParentSlotName);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
229 Assert.AreEqual("8", stats[1][0].SlotValueString);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
230 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
231 }
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
232
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
233 [Test()]
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
234 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesAndOverrideLoadsSuccessfully()
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
235 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
236 SetDefaultGameSystem();
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
237 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
238 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
239 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
240 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
241 Assert.AreEqual(1, unitTypes.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
242 UnitType unitType = unitTypes[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
243 Stat[][] allStats = unitType.UnitStatsArrays;
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
244 Stat[] stats = allStats[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
245 Assert.AreEqual(1, allStats.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
246 Assert.AreEqual(9, stats.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
247 Assert.AreEqual("M", stats[0].ParentSlotName);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
248 Assert.AreEqual("4", stats[0].SlotValueString);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
249 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
250 }
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
251
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
252 [Test()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
253 public void TestSingleUnitArmyWithNoStatsReturnsUnitWithBlankStats()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
254 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
255 SetDefaultGameSystem();
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
256 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
257 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
258 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
259 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
260 Assert.AreEqual(1, unitTypes.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
261 UnitType unitType = unitTypes[0];
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
262 Stat[] stats = unitType.UnitStatsArrays[0];
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
263 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
264
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
265 foreach (Stat stat in stats)
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
266 {
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
267 Assert.AreEqual("", stat.SlotValueString);
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
268 }
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
269
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
270 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
271 }
50
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
272
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
273 [Test()]
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
274 public void TestSingleUnitArmyWithNoCategoriesUsesMainCategory()
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
275 {
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
276 SetDefaultGameSystem();
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
277 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
278 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
279 Category category = race.GetCategory("cat1");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
280 UnitType[] unitTypes = race.GetUnitTypes(category);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
281 Assert.AreEqual(1, unitTypes.Length);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
282 UnitType unitType = unitTypes[0];
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
283 Assert.That(unitType.MainCategory, Is.EqualTo(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
284 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
285 Assert.That(unitType.Categories, Has.Member(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
286 }
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
287
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
288 [Test()]
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
289 public void TestSingleUnitArmyWithOneCategoryAndSameMainCategoryHasOneCategory()
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
290 {
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
291 SetDefaultGameSystem();
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
292 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
293 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
294 Category category = race.GetCategory("cat1");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
295 UnitType[] unitTypes = race.GetUnitTypes(category);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
296 Assert.AreEqual(1, unitTypes.Length);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
297 UnitType unitType = unitTypes[0];
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
298 Assert.That(unitType.MainCategory, Is.EqualTo(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
299 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
300 Assert.That(unitType.Categories, Has.Member(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
301 }
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
302
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
303 [Test()]
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
304 public void TestSingleUnitArmyWithOneCategoryAndDifferentMainCategoryHasTwoCategories()
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
305 {
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
306 SetDefaultGameSystem();
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
307 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
308 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
309 Category category = race.GetCategory("cat1");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
310 UnitType[] unitTypes = race.GetUnitTypes(category);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
311 Assert.AreEqual(1, unitTypes.Length);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
312 UnitType unitType = unitTypes[0];
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
313 Assert.That(unitType.MainCategory, Is.EqualTo(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
314 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
315 Assert.That(unitType.Categories, Has.Member(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
316 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
317 }
51
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
318
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
319 [Test()]
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
320 public void TestSingleUnitArmyWithMultipleCategoriesIsInEachCategory()
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
321 {
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
322 SetDefaultGameSystem();
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
323 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
324 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
325 UnitType unitType = race.GetUnitType("Empire1");
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
326 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
327 Category cat1 = race.GetCategory("cat1");
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
328 Category cat2 = race.GetCategory("cat2");
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
329 Assert.That(unitType.MainCategory, Is.EqualTo(cat1));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
330 Assert.That(unitType.Categories, Has.Member(cat1));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
331 Assert.That(unitType.Categories, Has.Member(cat2));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
332 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
333 UnitType[] unitTypesCat2 = race.GetUnitTypes(cat2);
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
334 Assert.That(unitTypesCat2, Has.Length(1));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
335 Assert.That(unitTypesCat2, Is.All.EqualTo(unitType));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
336 }
65
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
337
72
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
338 [Test()]
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
339 public void TestValidCategoriesLoadsCorrectly()
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
340 {
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
341 SetDefaultGameSystem();
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
342 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-race-factory/valid-categories.racex"));
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
343 Assert.That(race.Categories, Has.Length(5));
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
344 }
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
345
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
346 [Test()]
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
347 public void TestDuplicateCategoryIDErrors()
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
348 {
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
349 TestFileValidationFailure("testdata/xml-race-factory/duplicate-category-ids.racex");
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
350 }
d1d79adcb11d Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents: 66
diff changeset
351
147
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
352 [Test()]
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
353 public void TestExtendedRequirementsPassValidation()
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
354 {
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
355 SetDefaultGameSystem();
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
356 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-race-factory/extended-requirements.racex"));
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
357 Assert.That(race.Categories, Has.Length(5));
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
358 }
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
359
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
360 [Test()]
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
361 public void TestLoadingSimpleRequirement()
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
362 {
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
363 SetDefaultGameSystem();
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
364 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-race-factory/simple-requirement.racex"));
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
365 UnitType unitType = race.GetUnitType("Empire1");
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
366 Assert.That(unitType.GetRequirements(), Has.Length(1));
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
367 }
1de37b5c8107 Re #346: Add core schema support for requirements
IBBoard <dev@ibboard.co.uk>
parents: 80
diff changeset
368
149
71b9364f0276 Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 147
diff changeset
369 [Test()]
71b9364f0276 Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 147
diff changeset
370 public void TestLoadingRequirementType()
71b9364f0276 Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 147
diff changeset
371 {
71b9364f0276 Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 147
diff changeset
372 SetDefaultGameSystem();
71b9364f0276 Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 147
diff changeset
373 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-race-factory/simple-requirement.racex"));
71b9364f0276 Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 147
diff changeset
374 UnitType unitType = race.GetUnitType("Empire1");
71b9364f0276 Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 147
diff changeset
375 Assert.That(unitType.GetRequirements()[0], Is.InstanceOfType(typeof(UnitRequiresAtLeastNUnitsRequirement)));
71b9364f0276 Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 147
diff changeset
376 }
71b9364f0276 Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents: 147
diff changeset
377
203
2b27447ae74e Re #352: Test/fix cyclic references in unit types
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
378 [Test]
2b27447ae74e Re #352: Test/fix cyclic references in unit types
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
379 public void TestCyclicReferenceDoesNotCrash()
2b27447ae74e Re #352: Test/fix cyclic references in unit types
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
380 {
2b27447ae74e Re #352: Test/fix cyclic references in unit types
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
381 SetDefaultGameSystem();
2b27447ae74e Re #352: Test/fix cyclic references in unit types
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
382 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-race-factory/cyclic.racex"));
2b27447ae74e Re #352: Test/fix cyclic references in unit types
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
383 UnitType unitType = race.GetUnitType("Empire1");
204
ea104de9189e Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 203
diff changeset
384 Assert.That(unitType.GetRequirements()[0], Is.InstanceOfType(typeof(UnitRequiresNoMoreThanNOfUnitTypeRequirement)));
203
2b27447ae74e Re #352: Test/fix cyclic references in unit types
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
385 }
2b27447ae74e Re #352: Test/fix cyclic references in unit types
IBBoard <dev@ibboard.co.uk>
parents: 158
diff changeset
386
65
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
387 private void TestFileValidationFailure(string filePath)
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
388 {
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
389 SetDefaultGameSystem();
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
390 FileInfo raceFile = new FileInfo(filePath);
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
391
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
392 try
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
393 {
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
394 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
395 Assert.Fail("Excepted exception not thrown");
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
396 }
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
397 catch (InvalidFileException ex)
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
398 {
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
399 Console.WriteLine(ex.Message);
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
400 Exception innerException = ex.InnerException;
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
401 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
402 }
fa536aee66d7 Fixes #296: Fix handling of equipment slot with no limit
IBBoard <dev@ibboard.co.uk>
parents: 64
diff changeset
403 }
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
404
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
405 private static void SetDefaultGameSystem()
47
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
406 {
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
407 SetDefaultGameSystem(new FileInfo("testdata/default.systemx"));
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
408 }
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
409
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
410 public static void SetDefaultGameSystem(FileInfo systemFile)
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
411 {
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
412 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), systemFile);
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
413 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
414 WarFoundryLoader.SetDefault(fixedLoader);
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
415 }
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
416 }
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
417 }