# HG changeset patch # User IBBoard # Date 1315942180 -3600 # Node ID 3a626ea2604adefb268c34cd4013c001f0b66255 # Parent 6dce5122caca3ac56c9344e773bda38fa6b21c08# Parent e29650db551fa056128e08bc53fab0024d73dea4 * Merge Clutch's unit test work diff -r 6dce5122caca -r 3a626ea2604a API/Exporters/XmlSaveTest.cs --- /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 = ""; + string goldOutput = "Mock Army"; + [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); + } + } +} diff -r 6dce5122caca -r 3a626ea2604a IBBoard.WarFoundry.API.Tests.csproj --- 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 @@ --> + @@ -328,6 +329,10 @@ {C52AFD32-B869-4E14-AACE-2846AD2CC742} IBBoard.NUnit + + {E66FAEFC-4599-4AAB-A57F-0BB2554FA5B6} + Xmlunit + @@ -371,5 +376,14 @@ true - + + + + + + + PreserveNewest + Designer + + \ No newline at end of file diff -r 6dce5122caca -r 3a626ea2604a testdata/xml_output.xml --- /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 @@ + + + Mock Race + Mock Army + 2000 + 0 + + + + + + + + \ No newline at end of file