# HG changeset patch # User IBBoard # Date 1276372308 0 # Node ID 745820ad76564683e70e4dd56f5685a3d95d4bdd # Parent c6e5b8a1948dc6d436e7beb5fb18e86c3c1374ee Re #274: Crash when missing unit member ID * Add more specific tests for key and keyref for member type * Remove ExpectedException with unknown message Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type * Add explanation of why tests aren't as perfect as they could be diff -r c6e5b8a1948d -r 745820ad7656 API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs --- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs Sat Jun 12 15:14:06 2010 +0000 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs Sat Jun 12 19:51:48 2010 +0000 @@ -2,17 +2,19 @@ // // 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.Collections.Generic; +using System.IO; +using System.Xml.Schema; using IBBoard.IO; using IBBoard.WarFoundry.API.Objects; using NUnit.Framework; -using System.Collections.Generic; -using System.IO; using NUnit.Framework.SyntaxHelpers; namespace IBBoard.WarFoundry.API.Factories.Xml { - - + //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. [TestFixture()] public class WarFoundryXmlRaceFactoryTest { @@ -33,13 +35,24 @@ } [Test()] - [ExpectedException(typeof(InvalidFileException), ExpectedMessage="TBD")] public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError() { SetDefaultGameSystem(); FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex"); - Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); - race.EnsureFullyLoaded(); + try + { + SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); + Assert.Fail(); + } + catch (InvalidFileException ex) + { + 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()] diff -r c6e5b8a1948d -r 745820ad7656 testdata/default.systemx --- a/testdata/default.systemx Sat Jun 12 15:14:06 2010 +0000 +++ b/testdata/default.systemx Sat Jun 12 19:51:48 2010 +0000 @@ -7,8 +7,8 @@ - - + +