Mercurial > repos > IBBoard.WarFoundry.API.Tests
view API/Exporters/XmlSaveTest.cs @ 230:d6883a522c70
Re #419: Remove assumptions of a file-based install
* Make sure Race files aren't identified as GameSystem files
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 11 Jul 2012 20:54:12 +0100 |
parents | c026c02583ca |
children |
line wrap: on
line source
// This file (UnitTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard // // 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. using System; using System.Xml; using System.Xml.Xsl; using NUnit.Framework; using XmlUnit; using IBBoard.WarFoundry.API.Objects.Mock; using IBBoard.WarFoundry.API.Util; using IBBoard.WarFoundry.API.Exporters; using IBBoard.Limits; namespace IBBoard.WarFoundry.API.Objects { [TestFixture()] public class XmlSaveTest { Army mockArmy; string outputFile = "test_output.xml"; string goldFile = "testdata/xml_output.xml"; 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>"; string goldOutput = "<testTopLevel><armyName>Mock Army</armyName></testTopLevel>"; [TestFixtureSetUp()] public void XmlTestSetup() { mockArmy = new MockArmy(); UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5); UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(mockArmy, unitType.MainCategory)); mockArmy.AddUnit(unit); WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(mockArmy, outputFile); } // Basic validation of XML output [Test()] public void TestXmlOutputValid() { XmlInput dirty = new XmlInput(new XmlTextReader(outputFile)); XmlAssertion.AssertXmlValid(dirty); } // Basic save test and comparison [Test()] public void TestBasicXmlOutput() { XmlInput dirty = new XmlInput(new XmlTextReader(outputFile)); XmlInput gold = new XmlInput(new XmlTextReader(goldFile)); XmlAssertion.AssertXmlIdentical(gold, dirty); } // Simple transform test [Test()] public void TestTransformedOutput() { XmlInput xmlIn = new XmlInput(new XmlTextReader(outputFile)); XmlInput xslIn = new XmlInput(new XmlTextReader(new System.IO.StringReader(xslt))); XmlInput outputCompare = new XmlInput(new XmlTextReader(new System.IO.StringReader(goldOutput))); XmlAssertion.AssertXslTransformResults(xslIn, xmlIn, outputCompare); } } }