changeset 169:e29650db551f xsl-test

XSL Test case
author dkulinski
date Thu, 08 Sep 2011 17:34:11 -0600
parents 23e7f51386fd
children 3a626ea2604a
files API/Exporters/XmlSaveTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/xml_output.xml
diffstat 3 files changed, 95 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Exporters/XmlSaveTest.cs	Thu Sep 08 17:34:11 2011 -0600
     1.3 @@ -0,0 +1,67 @@
     1.4 +// This file (UnitTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard
     1.5 +// 
     1.6 +// 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.
     1.7 +
     1.8 +using System;
     1.9 +using System.Xml;
    1.10 +using System.Xml.Xsl;
    1.11 +using NUnit.Framework;
    1.12 +using XmlUnit;
    1.13 +using IBBoard.WarFoundry.API.Objects.Mock;
    1.14 +using IBBoard.WarFoundry.API.Util;
    1.15 +using IBBoard.WarFoundry.API.Exporters;
    1.16 +using IBBoard.Limits;
    1.17 +
    1.18 +namespace IBBoard.WarFoundry.API.Objects
    1.19 +{
    1.20 +	[TestFixture()]
    1.21 +	public class XmlSaveTest
    1.22 +	{
    1.23 +        Army mockArmy;
    1.24 +        string outputFile = "test_output.xml";
    1.25 +        string goldFile = "testdata\\xml_output.xml";
    1.26 +
    1.27 +        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>";
    1.28 +        string goldOutput = "<testTopLevel><armyName>Mock Army</armyName></testTopLevel>";
    1.29 +        [TestFixtureSetUp()]
    1.30 +        public void XmlTestSetup()
    1.31 +        {
    1.32 +            mockArmy = MockArmy.GetMockArmy();
    1.33 +            UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5);
    1.34 +            UnitType unitType = equip.EquipmentForUnit;
    1.35 +            Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(unitType.MainCategory));
    1.36 +            mockArmy.AddUnit(unit);
    1.37 +
    1.38 +            WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(mockArmy, outputFile);
    1.39 +        }
    1.40 +
    1.41 +        // Basic validation of XML output
    1.42 +        [Test()]
    1.43 +        public void TestXmlOutputValid()
    1.44 +        {
    1.45 +            XmlInput dirty = new XmlInput(new XmlTextReader(outputFile));
    1.46 +            XmlAssertion.AssertXmlValid(dirty);
    1.47 +        }
    1.48 +
    1.49 +        // Basic save test and comparison
    1.50 +        [Test()]
    1.51 +        public void TestBasicXmlOutput()
    1.52 +        {
    1.53 +            XmlInput dirty = new XmlInput(new XmlTextReader(outputFile));
    1.54 +            XmlInput gold = new XmlInput(new XmlTextReader(goldFile));
    1.55 +
    1.56 +            XmlAssertion.AssertXmlIdentical(gold, dirty);
    1.57 +
    1.58 +        }
    1.59 +        // Simple transform test
    1.60 +        [Test()]
    1.61 +        public void TestTransformedOutput()
    1.62 +        {
    1.63 +            XmlInput xmlIn = new XmlInput(new XmlTextReader(outputFile));
    1.64 +            XmlInput xslIn = new XmlInput(new XmlTextReader(new System.IO.StringReader(xslt)));
    1.65 +            XmlInput outputCompare = new XmlInput(new XmlTextReader(new System.IO.StringReader(goldOutput)));
    1.66 +
    1.67 +            XmlAssertion.AssertXslTransformResults(xslIn, xmlIn, outputCompare);
    1.68 +        }
    1.69 +	}
    1.70 +}
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Aug 14 01:19:12 2011 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Thu Sep 08 17:34:11 2011 -0600
     2.3 @@ -1,4 +1,4 @@
     2.4 -<?xml version="1.0" encoding="utf-8"?>
     2.5 +<?xml version="1.0" encoding="utf-8"?>
     2.6  <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
     2.7    <PropertyGroup>
     2.8      <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     2.9 @@ -58,6 +58,7 @@
    2.10    </Target>
    2.11    -->
    2.12    <ItemGroup>
    2.13 +    <Compile Include="API\Exporters\XmlSaveTest.cs" />
    2.14      <Compile Include="MockObjects\MockRaceZipFile.cs" />
    2.15      <Compile Include="MockObjects\MockSystemZipFile.cs" />
    2.16      <Compile Include="API\WarFoundryLoaderTest.cs" />
    2.17 @@ -183,6 +184,7 @@
    2.18      </None>
    2.19      <None Include="WarFoundryTests.nunit">
    2.20        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.21 +      <SubType>Designer</SubType>
    2.22      </None>
    2.23      <None Include="testdata\xml-race-factory\different-extra-data-key.racex">
    2.24        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.25 @@ -320,6 +322,10 @@
    2.26        <Project>{C52AFD32-B869-4E14-AACE-2846AD2CC742}</Project>
    2.27        <Name>IBBoard.NUnit</Name>
    2.28      </ProjectReference>
    2.29 +    <ProjectReference Include="..\Xmlunit\Xmlunit.csproj">
    2.30 +      <Project>{E66FAEFC-4599-4AAB-A57F-0BB2554FA5B6}</Project>
    2.31 +      <Name>Xmlunit</Name>
    2.32 +    </ProjectReference>
    2.33    </ItemGroup>
    2.34    <ProjectExtensions>
    2.35      <MonoDevelop>
    2.36 @@ -366,4 +372,11 @@
    2.37    <ItemGroup>
    2.38      <Folder Include="API\Savers\Xml\" />
    2.39    </ItemGroup>
    2.40 +  <ItemGroup>
    2.41 +    <Content Include="testdata\transform.xsl" />
    2.42 +    <Content Include="testdata\xml_output.xml">
    2.43 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.44 +      <SubType>Designer</SubType>
    2.45 +    </Content>
    2.46 +  </ItemGroup>
    2.47  </Project>
    2.48 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/testdata/xml_output.xml	Thu Sep 08 17:34:11 2011 -0600
     3.3 @@ -0,0 +1,14 @@
     3.4 +<?xml version="1.0" encoding="utf-8"?>
     3.5 +<army>
     3.6 +  <race>Mock Race</race>
     3.7 +  <name>Mock Army</name>
     3.8 +  <pointsAvailable>2000</pointsAvailable>
     3.9 +  <pointsUsed>0</pointsUsed>
    3.10 +  <category type="Mock Category">
    3.11 +    <unit name="Mock Unit Type" points="0" models="10">
    3.12 +      <statLine>
    3.13 +        <stat name="name" value="Mock Unit Type" />
    3.14 +      </statLine>
    3.15 +    </unit>
    3.16 +  </category>
    3.17 +</army>
    3.18 \ No newline at end of file