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 wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Exporters/XmlSaveTest.cs	Thu Sep 08 17:34:11 2011 -0600
@@ -0,0 +1,67 @@
+// 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);
+        }
+	}
+}
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Aug 14 01:19:12 2011 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Thu Sep 08 17:34:11 2011 -0600
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -58,6 +58,7 @@
   </Target>
   -->
   <ItemGroup>
+    <Compile Include="API\Exporters\XmlSaveTest.cs" />
     <Compile Include="MockObjects\MockRaceZipFile.cs" />
     <Compile Include="MockObjects\MockSystemZipFile.cs" />
     <Compile Include="API\WarFoundryLoaderTest.cs" />
@@ -183,6 +184,7 @@
     </None>
     <None Include="WarFoundryTests.nunit">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+      <SubType>Designer</SubType>
     </None>
     <None Include="testdata\xml-race-factory\different-extra-data-key.racex">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -320,6 +322,10 @@
       <Project>{C52AFD32-B869-4E14-AACE-2846AD2CC742}</Project>
       <Name>IBBoard.NUnit</Name>
     </ProjectReference>
+    <ProjectReference Include="..\Xmlunit\Xmlunit.csproj">
+      <Project>{E66FAEFC-4599-4AAB-A57F-0BB2554FA5B6}</Project>
+      <Name>Xmlunit</Name>
+    </ProjectReference>
   </ItemGroup>
   <ProjectExtensions>
     <MonoDevelop>
@@ -366,4 +372,11 @@
   <ItemGroup>
     <Folder Include="API\Savers\Xml\" />
   </ItemGroup>
+  <ItemGroup>
+    <Content Include="testdata\transform.xsl" />
+    <Content Include="testdata\xml_output.xml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+      <SubType>Designer</SubType>
+    </Content>
+  </ItemGroup>
 </Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/xml_output.xml	Thu Sep 08 17:34:11 2011 -0600
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<army>
+  <race>Mock Race</race>
+  <name>Mock Army</name>
+  <pointsAvailable>2000</pointsAvailable>
+  <pointsUsed>0</pointsUsed>
+  <category type="Mock Category">
+    <unit name="Mock Unit Type" points="0" models="10">
+      <statLine>
+        <stat name="name" value="Mock Unit Type" />
+      </statLine>
+    </unit>
+  </category>
+</army>
\ No newline at end of file