annotate API/Factories/Xml/WarFoundryXmlFactoryUtilTest.cs @ 227:d8cd6b259a9f

Re #359: Add "only contained" attribute to unit types * Test to make sure sub-units are removed from the army
author IBBoard <dev@ibboard.co.uk>
date Mon, 16 Apr 2012 20:45:45 +0100
parents b2517bb113d0
children 833f72be715a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (WarFoundryXmlFactoryUtilTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2010 IBBoard
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
feb77f3287ca Re #152: Test and fix extensibility of current schemas
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.
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
42
d4f6e9ac981e Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
6 using System.Xml;
69
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
7 using System.Xml.Schema;
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
8 using IBBoard.IO;
38
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using NUnit.Framework;
69
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
10 using NUnit.Framework.SyntaxHelpers;
38
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 namespace IBBoard.WarFoundry.API.Factories.Xml
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 {
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 [TestFixture()]
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 public class WarFoundryXmlFactoryUtilTest
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 [Test()]
42
d4f6e9ac981e Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
18 public void TestParsingExtendedDataFiles()
38
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 {
69
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
20 TestValidFileLoading("testdata/extended-data.racex");
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
21 TestValidFileLoading("testdata/extended-data.systemx");
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
22 TestValidFileLoading("testdata/extended-data.armyx");
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
23 }
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
24
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
25 [Test()]
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
26 public void TestParsingValidArmyContainedID()
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
27 {
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
28 TestValidFileLoading("testdata/xml-factory-util/valid-contained-id.armyx");
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
29 }
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
30
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
31 private static void TestValidFileLoading(string path)
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
32 {
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
33 XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(path);
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
34 Assert.IsNotNull(document);
42
d4f6e9ac981e Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
35 }
d4f6e9ac981e Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
36
69
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
37 [Test()]
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
38 public void TestArmyFileValidationFailsForDuplicateUnitID()
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
39 {
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
40 TestFileValidationFailure("testdata/xml-factory-util/duplicate-unit-id.armyx");
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
41 }
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
42
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
43 [Test()]
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
44 public void TestArmyFileValidationFailsForInvalidContainedID()
42
d4f6e9ac981e Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents: 38
diff changeset
45 {
69
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
46 TestFileValidationFailure("testdata/xml-factory-util/invalid-contained-id.armyx");
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
47 }
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
48
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
49 private void TestFileValidationFailure(string filePath)
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
50 {
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
51 try
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
52 {
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
53 SingleXmlObjectLoader.CreateDocumentElementFromFile(filePath);
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
54 Assert.Fail("Excepted exception not thrown");
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
55 }
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
56 catch (InvalidFileException ex)
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
57 {
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
58 Console.WriteLine(ex.Message);
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
59 Exception innerException = ex.InnerException;
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
60 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
b2517bb113d0 Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
61 }
38
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 }
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 }
feb77f3287ca Re #152: Test and fix extensibility of current schemas
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 }