annotate API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 60:f2348c00e633

Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type * Add tests and test data for extra data keys
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 Jun 2010 15:50:35 +0000
parents 6efa080b500f
children 27625216d8d6
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;
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 namespace IBBoard.WarFoundry.API.Factories.Xml
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
57
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
16 //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
17 //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
18 //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
19 [TestFixture()]
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 public class WarFoundryXmlRaceFactoryTest
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 {
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
22 [TearDown()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
23 public void AfterTestCleanup()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
24 {
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
25 WarFoundryLoader.SetDefault(null);
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
26 }
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
27
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 [Test()]
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
29 public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors()
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 {
58
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
31 SetDefaultGameSystem();
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
32 FileInfo raceFile = new FileInfo("testdata/race-with-non-existant-ability.racex");
58
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
33
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
34 try
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
35 {
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
36 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
37 Assert.Fail("Excepted exception not thrown");
58
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
38 }
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
39 catch (InvalidFileException ex)
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
40 {
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
41 Console.WriteLine(ex.Message);
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
42 Exception innerException = ex.InnerException;
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
43 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
44 }
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
45 }
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
46
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
47 [Test()]
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
48 public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError()
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
49 {
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
50 SetDefaultGameSystem();
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
51 FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.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
52
57
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
53 try
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
54 {
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
55 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
56 Assert.Fail("Excepted exception not thrown");
57
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
57 }
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
58 catch (InvalidFileException ex)
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
59 {
58
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
60 Console.WriteLine(ex.Message);
57
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
61 Exception innerException = ex.InnerException;
745820ad7656 Re #274: Crash when missing unit member ID
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
62 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
63 }
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 }
47
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
65
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
66 [Test()]
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
67 public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors()
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
68 {
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
69 SetDefaultGameSystem();
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
70 FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-slot-reference.racex");
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
71
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
72 try
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
73 {
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
74 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
75 Assert.Fail("Excepted exception not thrown");
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
76 }
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
77 catch (InvalidFileException ex)
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
78 {
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
79 Console.WriteLine(ex.Message);
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
80 Exception innerException = ex.InnerException;
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
81 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
82 }
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
83 }
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
84
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
85 [Test()]
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
86 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
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 SetDefaultGameSystem();
47
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
89 FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-reference.racex");
58
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
90
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
91 try
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
92 {
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
93 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
94 Assert.Fail("Excepted exception not thrown");
58
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
95 }
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
96 catch (InvalidFileException ex)
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
97 {
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
98 Console.WriteLine(ex.Message);
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
99 Exception innerException = ex.InnerException;
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
100 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
101 }
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
102 }
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
103
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
104 [Test()]
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
105 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
106 {
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
107 SetDefaultGameSystem();
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
108 FileInfo raceFile = new FileInfo("testdata/invalid-contained-unit-reference.racex");
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
109
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
110 try
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
111 {
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
112 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
113 Assert.Fail("Excepted exception not thrown");
58
c642d217036e Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 57
diff changeset
114 }
59
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
115 catch (InvalidFileException ex)
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
116 {
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
117 Console.WriteLine(ex.Message);
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
118 Exception innerException = ex.InnerException;
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
119 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
120 }
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
121 }
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
122
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
123 [Test()]
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
124 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
125 {
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
126 SetDefaultGameSystem();
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
127 FileInfo raceFile = new FileInfo("testdata/valid-contained-unit-reference.racex");
6efa080b500f Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
128 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
129 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
130 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
131 }
60
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
132
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
133 [Test()]
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
134 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
135 {
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
136 SetDefaultGameSystem();
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
137 FileInfo raceFile = new FileInfo("testdata/xml-race-factory/duplicate-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
138
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
139 try
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
140 {
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
141 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
142 Assert.Fail("Excepted exception not thrown");
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
143 }
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
144 catch (InvalidFileException ex)
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
145 {
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
146 Console.WriteLine(ex.Message);
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
147 Exception innerException = ex.InnerException;
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
148 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
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 }
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
151
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
152 [Test()]
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
153 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
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 SetDefaultGameSystem();
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
156 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
157 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
158 UnitType unitType = race.GetUnitType("Empire1");
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
159 Assert.That(unitType.GetExtraData("data1"), Is.EqualTo(""));
f2348c00e633 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
160 }
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
161
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
162 [Test()]
35
4302e6b2c5c1 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 33
diff changeset
163 [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
164 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
165 {
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 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
167 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
168 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
169 enumerator.Reset();
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170 enumerator.MoveNext();
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 Race race = (Race)enumerator.Current;
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
172 race.EnsureFullyLoaded();
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173 }
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
174
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
175 [Test()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
176 public void TestSingleUnitArmyLoadsSuccessfully()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
177 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
178 SetDefaultGameSystem();
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
179 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
180 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
181 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
182 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
183 Assert.AreEqual(1, unitTypes.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
184 UnitType unitType = unitTypes[0];
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
185 Stat[] stats = unitType.UnitStatsArrays[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
186 Assert.AreEqual(9, stats.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
187 Assert.AreEqual("M", stats[0].ParentSlotName);
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
188 Assert.AreEqual("4", stats[0].SlotValueString);
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
189 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
190 }
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
191
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
192 [Test()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
193 public void TestSingleUnitArmyWithMemberTypeReferenceLoadsSuccessfully()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
194 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
195 SetDefaultGameSystem();
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
196 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
197 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
198 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
199 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
200 Assert.AreEqual(1, unitTypes.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
201 UnitType unitType = unitTypes[0];
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
202 Stat[] stats = unitType.UnitStatsArrays[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
203 Assert.AreEqual(9, stats.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
204 Assert.AreEqual("M", stats[0].ParentSlotName);
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
205 Assert.AreEqual("4", stats[0].SlotValueString);
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
206 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
207 }
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
208
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
209 [Test()]
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
210 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesLoadsSuccessfully()
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
211 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
212 SetDefaultGameSystem();
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
213 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
214 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
215 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
216 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
217 Assert.AreEqual(1, unitTypes.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
218 UnitType unitType = unitTypes[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
219 Stat[][] stats = unitType.UnitStatsArrays;
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
220 Assert.AreEqual(2, stats.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
221 Assert.AreEqual("M", stats[0][0].ParentSlotName);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
222 Assert.AreEqual("4", stats[0][0].SlotValueString);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
223 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
224 Assert.AreEqual("M", stats[1][0].ParentSlotName);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
225 Assert.AreEqual("8", stats[1][0].SlotValueString);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
226 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
227 }
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
228
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
229 [Test()]
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
230 public void TestSingleUnitArmyWithMultipleMemberTypeReferencesAndOverrideLoadsSuccessfully()
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
231 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
232 SetDefaultGameSystem();
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
233 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
234 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
235 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
236 UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
237 Assert.AreEqual(1, unitTypes.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
238 UnitType unitType = unitTypes[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
239 Stat[][] allStats = unitType.UnitStatsArrays;
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
240 Stat[] stats = allStats[0];
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
241 Assert.AreEqual(1, allStats.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
242 Assert.AreEqual(9, stats.Length);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
243 Assert.AreEqual("M", stats[0].ParentSlotName);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
244 Assert.AreEqual("4", stats[0].SlotValueString);
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
245 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
246 }
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
247
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
248 [Test()]
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
249 public void TestSingleUnitArmyWithNoStatsReturnsUnitWithBlankStats()
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
250 {
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
251 SetDefaultGameSystem();
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
252 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
253 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
254 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
255 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
256 Assert.AreEqual(1, unitTypes.Length);
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
257 UnitType unitType = unitTypes[0];
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
258 Stat[] stats = unitType.UnitStatsArrays[0];
43
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
259 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
260
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
261 foreach (Stat stat in stats)
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
262 {
00abd1c2f7d6 Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
263 Assert.AreEqual("", stat.SlotValueString);
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
44
0de5d86bc1cb Re #268: Restructure stats for re-use
IBBoard <dev@ibboard.co.uk>
parents: 43
diff changeset
266 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
267 }
50
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
268
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
269 [Test()]
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
270 public void TestSingleUnitArmyWithNoCategoriesUsesMainCategory()
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
271 {
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
272 SetDefaultGameSystem();
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
273 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
274 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
275 Category category = race.GetCategory("cat1");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
276 UnitType[] unitTypes = race.GetUnitTypes(category);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
277 Assert.AreEqual(1, unitTypes.Length);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
278 UnitType unitType = unitTypes[0];
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
279 Assert.That(unitType.MainCategory, Is.EqualTo(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
280 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
281 Assert.That(unitType.Categories, Has.Member(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
282 }
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
283
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
284 [Test()]
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
285 public void TestSingleUnitArmyWithOneCategoryAndSameMainCategoryHasOneCategory()
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 SetDefaultGameSystem();
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
288 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
289 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
290 Category category = race.GetCategory("cat1");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
291 UnitType[] unitTypes = race.GetUnitTypes(category);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
292 Assert.AreEqual(1, unitTypes.Length);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
293 UnitType unitType = unitTypes[0];
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
294 Assert.That(unitType.MainCategory, Is.EqualTo(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
295 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
296 Assert.That(unitType.Categories, Has.Member(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
297 }
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
298
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
299 [Test()]
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
300 public void TestSingleUnitArmyWithOneCategoryAndDifferentMainCategoryHasTwoCategories()
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 SetDefaultGameSystem();
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
303 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
304 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
305 Category category = race.GetCategory("cat1");
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
306 UnitType[] unitTypes = race.GetUnitTypes(category);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
307 Assert.AreEqual(1, unitTypes.Length);
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
308 UnitType unitType = unitTypes[0];
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
309 Assert.That(unitType.MainCategory, Is.EqualTo(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
310 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
311 Assert.That(unitType.Categories, Has.Member(category));
d3519f38a0f4 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 47
diff changeset
312 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
313 }
51
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
314
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
315 [Test()]
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
316 public void TestSingleUnitArmyWithMultipleCategoriesIsInEachCategory()
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
317 {
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
318 SetDefaultGameSystem();
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
319 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
320 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
321 UnitType unitType = race.GetUnitType("Empire1");
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
322 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
323 Category cat1 = race.GetCategory("cat1");
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
324 Category cat2 = race.GetCategory("cat2");
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
325 Assert.That(unitType.MainCategory, Is.EqualTo(cat1));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
326 Assert.That(unitType.Categories, Has.Member(cat1));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
327 Assert.That(unitType.Categories, Has.Member(cat2));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
328 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
329 UnitType[] unitTypesCat2 = race.GetUnitTypes(cat2);
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
330 Assert.That(unitTypesCat2, Has.Length(1));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
331 Assert.That(unitTypesCat2, Is.All.EqualTo(unitType));
9d68b5dd70b3 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 50
diff changeset
332 }
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
333
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
334 private static void SetDefaultGameSystem()
47
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
335 {
b4b4bde843d7 Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 45
diff changeset
336 SetDefaultGameSystem(new FileInfo("testdata/default.systemx"));
45
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
337 }
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
338
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
339 public static void SetDefaultGameSystem(FileInfo systemFile)
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
340 {
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
341 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), systemFile);
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
342 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
343 WarFoundryLoader.SetDefault(fixedLoader);
04d7cd276b1d Re #274: crash when missing unitMember id
IBBoard <dev@ibboard.co.uk>
parents: 44
diff changeset
344 }
33
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
345 }
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
346 }