Mercurial > repos > IBBoard.WarFoundry.API.Tests
annotate API/Factories/Xml/WarFoundryXmlSystemFactoryTest.cs @ 71:a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
* Initial tests for system category handling
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 07 Jul 2010 19:01:32 +0000 |
parents | 90a9f13b9627 |
children | 72479ca6feb4 |
rev | line source |
---|---|
67
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (WarFoundryXmlSystemFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2010 IBBoard |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
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. |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using System; |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using NUnit.Framework; |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.IO; |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using IBBoard.WarFoundry.API.Objects; |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using NUnit.Framework.SyntaxHelpers; |
68
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
9 using IBBoard.IO; |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
10 using System.Xml.Schema; |
67
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 namespace IBBoard.WarFoundry.API.Factories.Xml |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 { |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 [TestFixture()] |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 public class WarFoundryXmlSystemFactoryTest |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 { |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 [Test()] |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 public void TestGettingDefaultStatsIDFullyLoadsGameSystem() |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 { |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-default-stats-one-stats-set.systemx")); |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 Assert.That(system.IsFullyLoaded, Is.False); |
70
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
22 string defaultStatsID = system.StandardSystemStatsID; |
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
23 Assert.That(defaultStatsID, Is.Not.Null); |
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
24 Assert.That(defaultStatsID, Is.Not.Empty); |
67
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 Assert.That(system.IsFullyLoaded, Is.True); |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 } |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 [Test()] |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 public void TestValidDefaultStatsIDLoadsCorrectly() |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 { |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-default-stats-one-stats-set.systemx")); |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 Assert.That(system.StandardSystemStatsID, Is.EqualTo("defaultStats")); |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 Assert.That(system.SystemStats, Has.Length(1)); |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 } |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 [Test()] |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 public void TestValidDefaultStatsIDLoadsCorrectlyWithMultipleStatsSets() |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 { |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-default-stats-multiple-stats-set.systemx")); |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 Assert.That(system.StandardSystemStatsID, Is.EqualTo("defaultStats")); |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 Assert.That(system.SystemStats, Has.Length(2)); |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 } |
68
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
43 |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
44 [Test()] |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
45 public void TestIncorrectDefaultStatsIDErrors() |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
46 { |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
47 TestFileValidationFailure("testdata/xml-system-factory/invalid-default-stats.systemx"); |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
48 } |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
49 |
70
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
50 [Test()] |
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
51 public void TestDuplicateStatsIDErrors() |
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
52 { |
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
53 TestFileValidationFailure("testdata/xml-system-factory/duplicate-stats-set-id.systemx"); |
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
54 } |
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
55 |
71
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
56 [Test()] |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
57 public void TestValidCategoriesLoadsCorrectly() |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
58 { |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
59 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-categories.systemx")); |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
60 Assert.That(system.Categories, Has.Length(5)); |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
61 } |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
62 |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
63 [Test()] |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
64 public void TestDuplicateCategoryIDErrors() |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
65 { |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
66 TestFileValidationFailure("testdata/xml-system-factory/duplicate-category-ids.systemx"); |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
67 } |
70
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
68 |
68
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
69 private void TestFileValidationFailure(string filePath) |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
70 { |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
71 FileInfo systemFile = new FileInfo(filePath); |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
72 |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
73 try |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
74 { |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
75 SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), systemFile); |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
76 Assert.Fail("Excepted exception not thrown"); |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
77 } |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
78 catch (InvalidFileException ex) |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
79 { |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
80 Console.WriteLine(ex.Message); |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
81 Exception innerException = ex.InnerException; |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
82 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException))); |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
83 } |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
84 } |
67
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
85 } |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
86 } |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
87 |