Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
changeset 58:c642d217036e
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
* Simplify "non-existant ability" unit test by removing SystemX file
* Remove line number checks, since Mono exception line numbers are end of file when the exception is a missing key **
* Re-implement equipment slot check test
** previous line numbers were taken from errors saying that keyref's key definition couldn't be found, not an error saying that the keyref value didn't exist
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 12 Jun 2010 20:40:18 +0000 |
parents | 745820ad7656 |
children | 6efa080b500f |
files | API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/race-with-non-existant-ability.racex testdata/race-with-non-existant-ability.systemx |
diffstat | 4 files changed, 36 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs Sat Jun 12 19:51:48 2010 +0000 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs Sat Jun 12 20:40:18 2010 +0000 @@ -15,6 +15,7 @@ { //It would be better to explicitly check that some of these errors are certain types of schema validation error, but Mono and .Net have //different exception messages for the same text and just have one class for all schema exceptions of all types. + //We can't even check line numbers because Mono embeds them in the text and the actual line number is the end of the file. [TestFixture()] public class WarFoundryXmlRaceFactoryTest { @@ -25,13 +26,24 @@ } [Test()] - [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Ability for Empire General with ID leaderOfMen did not exist in race definition")] public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors() { - SetDefaultGameSystem(new FileInfo("testdata/race-with-non-existant-ability.systemx")); + SetDefaultGameSystem(); FileInfo raceFile = new FileInfo("testdata/race-with-non-existant-ability.racex"); - Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); - race.EnsureFullyLoaded(); + + try + { + SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); + } + 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)); + } } [Test()] @@ -46,23 +58,35 @@ } 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)); + //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException; + //Assert.That(schemaEx.LineNumber, Is.EqualTo(6)); + //Assert.That(schemaEx.LinePosition, Is.EqualTo(6)); } } [Test()] - [ExpectedException(typeof(InvalidFileException), ExpectedMessage = "TBD")] public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors() { SetDefaultGameSystem(); FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-reference.racex"); - Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); - race.EnsureFullyLoaded(); + + try + { + SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); + } + 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()]
--- a/IBBoard.WarFoundry.API.Tests.csproj Sat Jun 12 19:51:48 2010 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Sat Jun 12 20:40:18 2010 +0000 @@ -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"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> @@ -79,9 +79,6 @@ <None Include="testdata\race-with-non-existant-ability.racex"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> - <None Include="testdata\race-with-non-existant-ability.systemx"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </None> <None Include="testdata\extended-data.racex"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None>
--- a/testdata/race-with-non-existant-ability.racex Sat Jun 12 19:51:48 2010 +0000 +++ b/testdata/race-with-non-existant-ability.racex Sat Jun 12 20:40:18 2010 +0000 @@ -1,5 +1,5 @@ <?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"> +<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>
--- a/testdata/race-with-non-existant-ability.systemx Sat Jun 12 19:51:48 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<system xmlns="http://ibboard.co.uk/warfoundry/system" xmlns:cats="http://ibboard.co.uk/warfoundry/cats" id="nonexistant" name="NonExistant Race Game System" warn="false"> - <categories> - <cats:cat id="cat1" name="Characters" minPercentage="0" maxPercentage="50" /> - <cats:cat id="cat2" name="Regiments" minPercentage="25" maxPercentage="100" /> - <cats:cat id="cat3" name="War Machines" minPercentage="0" maxPercentage="25" /> - <cats:cat id="cat4" name="Monsters" minPercentage="0" maxPercentage="25" /> - <cats:cat id="cat5" name="Allies" minPercentage="0" maxPercentage="25" /> - </categories> - <sysStatsList defaultStats="whDefault"> - <sysStats id="whDefault"> - <sysStat name="M"/> - <sysStat name="WS"/> - <sysStat name="BS"/> - <sysStat name="S"/> - <sysStat name="T"/> - <sysStat name="W"/> - <sysStat name="I"/> - <sysStat name="A"/> - <sysStat name="Ld"/> - </sysStats> - </sysStatsList> -</system>