view API/Exporters/XmlSaveTest.cs @ 169:e29650db551f xsl-test

XSL Test case
author dkulinski
date Thu, 08 Sep 2011 17:34:11 -0600
parents
children 14d0450f295d
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 = MockArmy.GetMockArmy();
            UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5);
            UnitType unitType = equip.EquipmentForUnit;
            Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(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);
        }
	}
}