changeset 57:745820ad7656

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
author IBBoard <dev@ibboard.co.uk>
date Sat, 12 Jun 2010 19:51:48 +0000
parents c6e5b8a1948d
children c642d217036e
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs testdata/default.systemx
diffstat 2 files changed, 22 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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()]
--- 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 @@
 		<cats:cat id="cat4" name="Monsters" minPercentage="0" maxPercentage="25" />
 		<cats:cat id="cat5" name="Allies" minPercentage="0" maxPercentage="25" />
 	</categories>
-	<sysStatsList defaultStats="default">
-		<sysStats id="default">
+	<sysStatsList defaultStats="defaultStats">
+		<sysStats id="defaultStats">
 			<sysStat name="M"/>
 			<sysStat name="WS"/>
 			<sysStat name="BS"/>