view API/Factories/Xml/WarFoundryXmlSystemFactoryTest.cs @ 228:7c21ca1482cb

Re #419: Remove assumptions of a file-based install * Update tests to use new "loadable object" and "loadable object source" wrappers
author IBBoard <dev@ibboard.co.uk>
date Sat, 07 Jul 2012 21:02:53 +0100
parents 052148dc0a2f
children 833f72be715a
line source
1 // This file (WarFoundryXmlSystemFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2010 IBBoard
2 //
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.
5 using System;
6 using NUnit.Framework;
7 using System.IO;
8 using IBBoard.WarFoundry.API.Objects;
9 using NUnit.Framework.SyntaxHelpers;
10 using IBBoard.IO;
11 using System.Xml.Schema;
12 using IBBoard.WarFoundry.API.Loading;
14 namespace IBBoard.WarFoundry.API.Factories.Xml
15 {
16 [TestFixture()]
17 public class WarFoundryXmlSystemFactoryTest
18 {
19 [Test()]
20 public void TestBug311InvalidVersionToExtract788()
21 {
22 ILoadableObject repackFile = new LoadableFileObject("testdata/zip-format/Repack.system");
23 Assert.That(WarFoundryXmlFactory.GetFactory().CanHandleFileAsGameSystem(repackFile), Is.True);
24 Assert.That(WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(repackFile), Has.Count(1));
25 }
27 [Test()]
28 public void TestGettingDefaultStatsIDFullyLoadsGameSystem()
29 {
30 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-default-stats-one-stats-set.systemx"));
31 Assert.That(system.IsFullyLoaded, Is.False);
32 string defaultStatsID = system.StandardSystemStatsID;
33 Assert.That(defaultStatsID, Is.Not.Null);
34 Assert.That(defaultStatsID, Is.Not.Empty);
35 Assert.That(system.IsFullyLoaded, Is.True);
36 }
38 [Test()]
39 public void TestValidDefaultStatsIDLoadsCorrectly()
40 {
41 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-default-stats-one-stats-set.systemx"));
42 Assert.That(system.StandardSystemStatsID, Is.EqualTo("defaultStats"));
43 Assert.That(system.SystemStats, Has.Length(1));
44 }
46 [Test()]
47 public void TestValidDefaultStatsIDLoadsCorrectlyWithMultipleStatsSets()
48 {
49 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-default-stats-multiple-stats-set.systemx"));
50 Assert.That(system.StandardSystemStatsID, Is.EqualTo("defaultStats"));
51 Assert.That(system.SystemStats, Has.Length(2));
52 }
54 [Test()]
55 public void TestIncorrectDefaultStatsIDErrors()
56 {
57 TestFileValidationFailure("testdata/xml-system-factory/invalid-default-stats.systemx");
58 }
60 [Test()]
61 public void TestDuplicateStatsIDErrors()
62 {
63 TestFileValidationFailure("testdata/xml-system-factory/duplicate-stats-set-id.systemx");
64 }
66 [Test()]
67 public void TestValidCategoriesLoadsCorrectly()
68 {
69 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-categories.systemx"));
70 Assert.That(system.Categories, Has.Length(5));
71 }
73 [Test()]
74 public void TestDuplicateCategoryIDErrors()
75 {
76 TestFileValidationFailure("testdata/xml-system-factory/duplicate-category-ids.systemx");
77 }
79 [Test()]
80 public void TestLoadingPointsNamesAndAbbreviations()
81 {
82 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/points-strings/names.systemx"));
83 Assert.That(system.SystemPtsAbbrevPlural, Is.EqualTo("ptii"));
84 Assert.That(system.SystemPtsAbbrevSingle, Is.EqualTo("ptus"));
85 Assert.That(system.SystemPtsNamePlural, Is.EqualTo("pointii"));
86 Assert.That(system.SystemPtsNameSingle, Is.EqualTo("pointus"));
87 }
89 [Test()]
90 public void TestLoadingDefaultPointsNamesAndAbbreviations()
91 {
92 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
93 Assert.That(system.SystemPtsAbbrevPlural, Is.EqualTo("pts"));
94 Assert.That(system.SystemPtsAbbrevSingle, Is.EqualTo("pt"));
95 Assert.That(system.SystemPtsNamePlural, Is.EqualTo("points"));
96 Assert.That(system.SystemPtsNameSingle, Is.EqualTo("point"));
97 }
99 private void TestFileValidationFailure(string filePath)
100 {
101 FileInfo systemFile = new FileInfo(filePath);
103 try
104 {
105 SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), systemFile);
106 Assert.Fail("Excepted exception not thrown");
107 }
108 catch (InvalidFileException ex)
109 {
110 Console.WriteLine(ex.Message);
111 Exception innerException = ex.InnerException;
112 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
113 }
114 }
115 }
116 }