Mercurial > repos > IBBoard.WarFoundry.API.Tests
annotate API/Factories/Xml/WarFoundryXmlSystemFactoryTest.cs @ 75:72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
* Add a unit test for the failure
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 30 Oct 2010 14:45:45 +0000 |
parents | a2095a3685fc |
children | 052148dc0a2f |
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. |
75
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
4 |
67
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 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
|
7 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
|
8 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
|
9 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
|
10 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
|
11 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
|
12 |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 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
|
14 { |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 [TestFixture()] |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 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
|
17 { |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 [Test()] |
75
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
19 public void TestBug311InvalidVersionToExtract788() |
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
20 { |
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
21 FileInfo repackFile = new FileInfo("testdata/zip-format/Repack.system"); |
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
22 Assert.That(WarFoundryXmlFactory.GetFactory().CanHandleFileAsGameSystem(repackFile), Is.True); |
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
23 Assert.That(WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(repackFile), Has.Count(1)); |
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
24 } |
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
25 |
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
26 [Test()] |
67
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 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
|
28 { |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 } |
75
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
36 |
67
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 [Test()] |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 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
|
39 { |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 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
|
41 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
|
42 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
|
43 } |
75
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
44 |
67
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 [Test()] |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 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
|
47 { |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 } |
75
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
52 |
68
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
53 [Test()] |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
54 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
|
55 { |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
56 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
|
57 } |
75
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
58 |
70
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
59 [Test()] |
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
60 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
|
61 { |
90a9f13b9627
Fixes #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
62 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
|
63 } |
75
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
64 |
71
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
65 [Test()] |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
66 public void TestValidCategoriesLoadsCorrectly() |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
67 { |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
68 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
|
69 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
|
70 } |
75
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
71 |
71
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
72 [Test()] |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
73 public void TestDuplicateCategoryIDErrors() |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
74 { |
a2095a3685fc
Re #297: Move Categories over to key/keyref from ID/IDREF
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
75 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
|
76 } |
75
72479ca6feb4
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
77 |
68
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
78 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
|
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 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
|
81 |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
82 try |
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 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
|
85 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
|
86 } |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
87 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
|
88 { |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 } |
a82f164e26e3
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
67
diff
changeset
|
93 } |
67
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
94 } |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
95 } |
d3191c44f163
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
96 |