Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
diff API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 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 |
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()]