Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
changeset 170:3a626ea2604a
* Merge Clutch's unit test work
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 13 Sep 2011 20:29:40 +0100 |
parents | 6dce5122caca (current diff) e29650db551f (diff) |
children | 14d0450f295d |
files | IBBoard.WarFoundry.API.Tests.csproj |
diffstat | 3 files changed, 96 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Exporters/XmlSaveTest.cs Tue Sep 13 20:29:40 2011 +0100 @@ -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 Wed Sep 07 20:52:10 2011 +0100 +++ b/IBBoard.WarFoundry.API.Tests.csproj Tue Sep 13 20:29:40 2011 +0100 @@ -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" /> @@ -328,6 +329,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> @@ -371,5 +376,14 @@ <Install>true</Install> </BootstrapperPackage> </ItemGroup> - <ItemGroup /> + <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 Tue Sep 13 20:29:40 2011 +0100 @@ -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