Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 59:6efa080b500f
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
* Add unit tests and data for unit containership
* Add unit test and data for unit equipment
* Correct name of test data for equipment slot unit test
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 14 Jun 2010 19:57:53 +0000 |
parents | c642d217036e |
children | f2348c00e633 |
files | API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/invalid-contained-unit-reference.racex testdata/single-unit-with-invalid-equipment-reference.racex testdata/single-unit-with-invalid-equipment-slot-reference.racex testdata/valid-contained-unit-reference.racex |
diffstat | 6 files changed, 145 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs Sat Jun 12 20:40:18 2010 +0000 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs Mon Jun 14 19:57:53 2010 +0000 @@ -34,15 +34,13 @@ try { SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); + Assert.Fail("Excepted exception not thrown"); } catch (InvalidFileException ex) { Console.WriteLine(ex.Message); Exception innerException = ex.InnerException; Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException))); - //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException; - //Assert.That(schemaEx.LineNumber, Is.EqualTo(17)); - //Assert.That(schemaEx.LinePosition, Is.EqualTo(6)); } } @@ -51,42 +49,85 @@ { SetDefaultGameSystem(); FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex"); + try { SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); - Assert.Fail(); + Assert.Fail("Excepted exception not thrown"); } catch (InvalidFileException ex) { Console.WriteLine(ex.Message); Exception innerException = ex.InnerException; Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException))); - //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException; - //Assert.That(schemaEx.LineNumber, Is.EqualTo(6)); - //Assert.That(schemaEx.LinePosition, Is.EqualTo(6)); - } - + } } [Test()] public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors() { SetDefaultGameSystem(); + FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-slot-reference.racex"); + + try + { + SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); + Assert.Fail("Excepted exception not thrown"); + } + catch (InvalidFileException ex) + { + Console.WriteLine(ex.Message); + Exception innerException = ex.InnerException; + Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException))); + } + } + + [Test()] + public void TestCompleteLoadingOnRaceWithIncorrectEquipmentIDError() + { + SetDefaultGameSystem(); FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-reference.racex"); try { SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); + Assert.Fail("Excepted exception not thrown"); } catch (InvalidFileException ex) { Console.WriteLine(ex.Message); Exception innerException = ex.InnerException; Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException))); - //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException; - //Assert.That(schemaEx.LineNumber, Is.EqualTo(6)); - //Assert.That(schemaEx.LinePosition, Is.EqualTo(6)); + } + } + + [Test()] + public void TestCompleteLoadingOnRaceWithIncorrectContainedUnitIDError() + { + SetDefaultGameSystem(); + FileInfo raceFile = new FileInfo("testdata/invalid-contained-unit-reference.racex"); + + try + { + SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); + Assert.Fail("Excepted exception not thrown"); } + catch (InvalidFileException ex) + { + Console.WriteLine(ex.Message); + Exception innerException = ex.InnerException; + Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException))); + } + } + + [Test()] + public void TestCompleteLoadingOnRaceWithCorrectContainedUnitIDLoadsData() + { + SetDefaultGameSystem(); + FileInfo raceFile = new FileInfo("testdata/valid-contained-unit-reference.racex"); + Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); + UnitType unitType = race.GetUnitType("Empire1"); + Assert.That(unitType.ContainedUnitTypes, Has.Length(1)); } [Test()]
--- a/IBBoard.WarFoundry.API.Tests.csproj Sat Jun 12 20:40:18 2010 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Mon Jun 14 19:57:53 2010 +0000 @@ -149,6 +149,15 @@ <None Include="WarFoundryTests.nunit"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="testdata\single-unit-with-invalid-equipment-slot-reference.racex"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="testdata\invalid-contained-unit-reference.racex"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="testdata\valid-contained-unit-reference.racex"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> </ItemGroup> <ItemGroup> <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/invalid-contained-unit-reference.racex Mon Jun 14 19:57:53 2010 +0000 @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="Empire" name="Empire" system="default"> + <units> + <unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1"> + <stats> + <stat name="M">4</stat> + <stat name="WS">6</stat> + <stat name="BS">6</stat> + <stat name="S">4</stat> + <stat name="T">4</stat> + <stat name="W">3</stat> + <stat name="I">6</stat> + <stat name="A">4</stat> + <stat name="Ld">9</stat> + </stats> + <contains> + <containedUnit containedID="Empire2" /> + </contains> + </unit> + </units> +</race> \ No newline at end of file
--- a/testdata/single-unit-with-invalid-equipment-reference.racex Sat Jun 12 20:40:18 2010 +0000 +++ b/testdata/single-unit-with-invalid-equipment-reference.racex Mon Jun 14 19:57:53 2010 +0000 @@ -13,11 +13,8 @@ <stat name="A">4</stat> <stat name="Ld">9</stat> </stats> - <equipmentSlots> - <equipmentSlot name="slot1"/> - </equipmentSlots> <unitEquipment> - <unitEquipmentItem id="equip1" equipmentSlot="slot2"/> + <unitEquipmentItem id="equip2"/> </unitEquipment> </unit> </units>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/single-unit-with-invalid-equipment-slot-reference.racex Mon Jun 14 19:57:53 2010 +0000 @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="Empire" name="Empire" system="nonexistant"> + <units> + <unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1"> + <stats> + <stat name="M">4</stat> + <stat name="WS">6</stat> + <stat name="BS">6</stat> + <stat name="S">4</stat> + <stat name="T">4</stat> + <stat name="W">3</stat> + <stat name="I">6</stat> + <stat name="A">4</stat> + <stat name="Ld">9</stat> + </stats> + <equipmentSlots> + <equipmentSlot name="slot1"/> + </equipmentSlots> + <unitEquipment> + <unitEquipmentItem id="equip1" equipmentSlot="slot2"/> + </unitEquipment> + </unit> + </units> + <equipment> + <equipmentItem id="equip1" name="sword" cost="1"/> + </equipment> +</race> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/valid-contained-unit-reference.racex Mon Jun 14 19:57:53 2010 +0000 @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="Empire" name="Empire" system="default"> + <units> + <unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1"> + <stats> + <stat name="M">4</stat> + <stat name="WS">6</stat> + <stat name="BS">6</stat> + <stat name="S">4</stat> + <stat name="T">4</stat> + <stat name="W">3</stat> + <stat name="I">6</stat> + <stat name="A">4</stat> + <stat name="Ld">9</stat> + </stats> + <contains> + <containedUnit containedID="Empire2" /> + </contains> + </unit> + <unit id="Empire2" typeName="Minion" cat="cat1" points="0"> + <stats> + <stat name="M">4</stat> + <stat name="WS">2</stat> + <stat name="BS">2</stat> + <stat name="S">2</stat> + <stat name="T">2</stat> + <stat name="W">1</stat> + <stat name="I">2</stat> + <stat name="A">1</stat> + <stat name="Ld">5</stat> + </stats> + </unit> + </units> +</race> \ No newline at end of file