169
|
1 // This file (UnitTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 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.
|
|
4
|
|
5 using System;
|
|
6 using System.Xml;
|
|
7 using System.Xml.Xsl;
|
|
8 using NUnit.Framework;
|
|
9 using XmlUnit;
|
|
10 using IBBoard.WarFoundry.API.Objects.Mock;
|
|
11 using IBBoard.WarFoundry.API.Util;
|
|
12 using IBBoard.WarFoundry.API.Exporters;
|
|
13 using IBBoard.Limits;
|
|
14
|
|
15 namespace IBBoard.WarFoundry.API.Objects
|
|
16 {
|
|
17 [TestFixture()]
|
|
18 public class XmlSaveTest
|
|
19 {
|
|
20 Army mockArmy;
|
|
21 string outputFile = "test_output.xml";
|
|
22 string goldFile = "testdata\\xml_output.xml";
|
|
23
|
|
24 string xslt = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:output method=\"xml\" indent=\"no\" omit-xml-declaration=\"yes\"/><xsl:template match=\"/\"><testTopLevel><armyName><xsl:value-of select=\"army/name\"/></armyName></testTopLevel></xsl:template></xsl:stylesheet>";
|
|
25 string goldOutput = "<testTopLevel><armyName>Mock Army</armyName></testTopLevel>";
|
|
26 [TestFixtureSetUp()]
|
|
27 public void XmlTestSetup()
|
|
28 {
|
|
29 mockArmy = MockArmy.GetMockArmy();
|
|
30 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5);
|
|
31 UnitType unitType = equip.EquipmentForUnit;
|
|
32 Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(unitType.MainCategory));
|
|
33 mockArmy.AddUnit(unit);
|
|
34
|
|
35 WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(mockArmy, outputFile);
|
|
36 }
|
|
37
|
|
38 // Basic validation of XML output
|
|
39 [Test()]
|
|
40 public void TestXmlOutputValid()
|
|
41 {
|
|
42 XmlInput dirty = new XmlInput(new XmlTextReader(outputFile));
|
|
43 XmlAssertion.AssertXmlValid(dirty);
|
|
44 }
|
|
45
|
|
46 // Basic save test and comparison
|
|
47 [Test()]
|
|
48 public void TestBasicXmlOutput()
|
|
49 {
|
|
50 XmlInput dirty = new XmlInput(new XmlTextReader(outputFile));
|
|
51 XmlInput gold = new XmlInput(new XmlTextReader(goldFile));
|
|
52
|
|
53 XmlAssertion.AssertXmlIdentical(gold, dirty);
|
|
54
|
|
55 }
|
|
56 // Simple transform test
|
|
57 [Test()]
|
|
58 public void TestTransformedOutput()
|
|
59 {
|
|
60 XmlInput xmlIn = new XmlInput(new XmlTextReader(outputFile));
|
|
61 XmlInput xslIn = new XmlInput(new XmlTextReader(new System.IO.StringReader(xslt)));
|
|
62 XmlInput outputCompare = new XmlInput(new XmlTextReader(new System.IO.StringReader(goldOutput)));
|
|
63
|
|
64 XmlAssertion.AssertXslTransformResults(xslIn, xmlIn, outputCompare);
|
|
65 }
|
|
66 }
|
|
67 }
|