Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 65:fa536aee66d7
Fixes #296: Fix handling of equipment slot with no limit
* Test the handling of slots without limits
Also:
* Compact testing by extracting out a common "test validation fails" method
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 04 Jul 2010 13:53:45 +0000 |
parents | 6f638d6f400f |
children | f671ead260b1 |
files | API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/xml-race-factory/single-unit-with-no-equipment-slot-limit.racex |
diffstat | 3 files changed, 62 insertions(+), 112 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs Sun Jul 04 12:55:21 2010 +0000 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs Sun Jul 04 13:53:45 2010 +0000 @@ -28,39 +28,13 @@ [Test()] public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors() { - SetDefaultGameSystem(); - FileInfo raceFile = new FileInfo("testdata/xml-race-factory/non-existant-ability.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))); - } + TestFileValidationFailure("testdata/xml-race-factory/non-existant-ability.racex"); } [Test()] public void TestCompleteLoadingOnRaceWithDuplicateAbilityIdErrors() { - SetDefaultGameSystem(); - FileInfo raceFile = new FileInfo("testdata/xml-race-factory/duplicate-ability.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))); - } + TestFileValidationFailure("testdata/xml-race-factory/duplicate-ability.racex"); } [Test()] @@ -79,39 +53,13 @@ [Test()] public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDErrors() { - SetDefaultGameSystem(); - FileInfo raceFile = new FileInfo("testdata/xml-race-factory/non-existant-member-type.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))); - } + TestFileValidationFailure("testdata/xml-race-factory/non-existant-member-type.racex"); } [Test()] public void TestCompleteLoadingOnRaceWithDuplicateMemberTypeIDErrors() { - SetDefaultGameSystem(); - FileInfo raceFile = new FileInfo("testdata/xml-race-factory/duplicate-member-type.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))); - } + TestFileValidationFailure("testdata/xml-race-factory/duplicate-member-type.racex"); } [Test()] @@ -127,20 +75,7 @@ [Test()] public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors() { - SetDefaultGameSystem(); - FileInfo raceFile = new FileInfo("testdata/xml-race-factory/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))); - } + TestFileValidationFailure("testdata/xml-race-factory/single-unit-with-invalid-equipment-slot-reference.racex"); } [Test()] @@ -153,43 +88,23 @@ UnitEquipmentItem unitEquipmentItem = unitType.GetEquipmentItem("Empire1equip1"); Assert.That(unitEquipmentItem.SlotName, Is.EqualTo("slot1")); } + + [Test()] + public void TestCompleteLoadingOnRaceWithNoEquipmentSlotLimitErrors() + { + TestFileValidationFailure("testdata/xml-race-factory/single-unit-with-no-equipment-slot-limit.racex"); + } [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))); - } + TestFileValidationFailure("testdata/single-unit-with-invalid-equipment-reference.racex"); } [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))); - } + TestFileValidationFailure("testdata/invalid-contained-unit-reference.racex"); } [Test()] @@ -205,20 +120,7 @@ [Test()] public void TestCompleteLoadingOnRaceWithDuplicateExtraDataKeyErrors() { - SetDefaultGameSystem(); - FileInfo raceFile = new FileInfo("testdata/xml-race-factory/duplicate-extra-data-key.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))); - } + TestFileValidationFailure("testdata/xml-race-factory/duplicate-extra-data-key.racex"); } [Test()] @@ -402,6 +304,24 @@ Assert.That(unitTypesCat2, Has.Length(1)); Assert.That(unitTypesCat2, Is.All.EqualTo(unitType)); } + + private void TestFileValidationFailure(string filePath) + { + SetDefaultGameSystem(); + FileInfo raceFile = new FileInfo(filePath); + + 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))); + } + } private static void SetDefaultGameSystem() {
--- a/IBBoard.WarFoundry.API.Tests.csproj Sun Jul 04 12:55:21 2010 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Sun Jul 04 13:53:45 2010 +0000 @@ -179,6 +179,9 @@ <None Include="testdata\xml-race-factory\single-unit-with-valid-equipment-slot-reference.racex"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="testdata\xml-race-factory\single-unit-with-no-equipment-slot-limit.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/xml-race-factory/single-unit-with-no-equipment-slot-limit.racex Sun Jul 04 13:53:45 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="slot1"/> + </unitEquipment> + </unit> + </units> + <equipment> + <equipmentItem id="equip1" name="sword" cost="1"/> + </equipment> +</race> \ No newline at end of file