annotate API/Exporters/XmlSaveTest.cs @ 171:14d0450f295d

* Fix file path in test case to work on Linux * Switch to using XmlUnit in binary form (because license allows it)
author IBBoard <dev@ibboard.co.uk>
date Tue, 13 Sep 2011 20:49:06 +0100
parents e29650db551f
children c026c02583ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
169
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
1 // This file (UnitTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
2 //
e29650db551f XSL Test case
dkulinski
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.
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
4
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
5 using System;
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
6 using System.Xml;
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
7 using System.Xml.Xsl;
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
8 using NUnit.Framework;
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
9 using XmlUnit;
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
10 using IBBoard.WarFoundry.API.Objects.Mock;
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
11 using IBBoard.WarFoundry.API.Util;
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
12 using IBBoard.WarFoundry.API.Exporters;
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
13 using IBBoard.Limits;
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
14
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
15 namespace IBBoard.WarFoundry.API.Objects
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
16 {
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
17 [TestFixture()]
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
18 public class XmlSaveTest
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
19 {
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
20 Army mockArmy;
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
21 string outputFile = "test_output.xml";
171
14d0450f295d * Fix file path in test case to work on Linux
IBBoard <dev@ibboard.co.uk>
parents: 169
diff changeset
22 string goldFile = "testdata/xml_output.xml";
169
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
23
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
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>";
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
25 string goldOutput = "<testTopLevel><armyName>Mock Army</armyName></testTopLevel>";
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
26 [TestFixtureSetUp()]
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
27 public void XmlTestSetup()
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
28 {
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
29 mockArmy = MockArmy.GetMockArmy();
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
30 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5);
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
31 UnitType unitType = equip.EquipmentForUnit;
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
32 Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(unitType.MainCategory));
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
33 mockArmy.AddUnit(unit);
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
34
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
35 WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(mockArmy, outputFile);
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
36 }
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
37
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
38 // Basic validation of XML output
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
39 [Test()]
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
40 public void TestXmlOutputValid()
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
41 {
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
42 XmlInput dirty = new XmlInput(new XmlTextReader(outputFile));
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
43 XmlAssertion.AssertXmlValid(dirty);
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
44 }
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
45
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
46 // Basic save test and comparison
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
47 [Test()]
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
48 public void TestBasicXmlOutput()
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
49 {
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
50 XmlInput dirty = new XmlInput(new XmlTextReader(outputFile));
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
51 XmlInput gold = new XmlInput(new XmlTextReader(goldFile));
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
52
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
53 XmlAssertion.AssertXmlIdentical(gold, dirty);
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
54
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
55 }
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
56 // Simple transform test
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
57 [Test()]
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
58 public void TestTransformedOutput()
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
59 {
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
60 XmlInput xmlIn = new XmlInput(new XmlTextReader(outputFile));
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
61 XmlInput xslIn = new XmlInput(new XmlTextReader(new System.IO.StringReader(xslt)));
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
62 XmlInput outputCompare = new XmlInput(new XmlTextReader(new System.IO.StringReader(goldOutput)));
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
63
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
64 XmlAssertion.AssertXslTransformResults(xslIn, xmlIn, outputCompare);
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
65 }
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
66 }
e29650db551f XSL Test case
dkulinski
parents:
diff changeset
67 }