changeset 60:f2348c00e633

Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type * Add tests and test data for extra data keys
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 Jun 2010 15:50:35 +0000
parents 6efa080b500f
children 27625216d8d6
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/xml-race-factory/different-extra-data-key.racex testdata/xml-race-factory/duplicate-extra-data-key.racex
diffstat 4 files changed, 82 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Mon Jun 14 19:57:53 2010 +0000
+++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sat Jun 19 15:50:35 2010 +0000
@@ -129,6 +129,35 @@
 			UnitType unitType = race.GetUnitType("Empire1");
 			Assert.That(unitType.ContainedUnitTypes, Has.Length(1));
 		}
+
+		[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)));
+			}
+		}
+
+		[Test()]
+		public void TestCompleteLoadingOnRaceWithDifferentExtraDataKeysLoadsData()
+		{
+			SetDefaultGameSystem();
+			FileInfo raceFile = new FileInfo("testdata/xml-race-factory/different-extra-data-key.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			UnitType unitType = race.GetUnitType("Empire1");
+			Assert.That(unitType.GetExtraData("data1"), Is.EqualTo(""));
+		}
 		
 		[Test()]
 		[ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")]
--- a/IBBoard.WarFoundry.API.Tests.csproj	Mon Jun 14 19:57:53 2010 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Jun 19 15:50:35 2010 +0000
@@ -158,6 +158,12 @@
     <None Include="testdata\valid-contained-unit-reference.racex">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="testdata\xml-race-factory\different-extra-data-key.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\xml-race-factory\duplicate-extra-data-key.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
@@ -187,4 +193,7 @@
     </MonoDevelop>
     <VisualStudio />
   </ProjectExtensions>
+  <ItemGroup>
+    <Folder Include="testdata\xml-race-factory\" />
+  </ItemGroup>
 </Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/xml-race-factory/different-extra-data-key.racex	Sat Jun 19 15:50:35 2010 +0000
@@ -0,0 +1,22 @@
+<?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="default">
+	<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>
+			<extraData>
+				<data id="data1"></data>
+				<data id="data2"></data>
+			</extraData>
+		</unit>
+	</units>
+</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/xml-race-factory/duplicate-extra-data-key.racex	Sat Jun 19 15:50:35 2010 +0000
@@ -0,0 +1,22 @@
+<?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="default">
+	<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>
+			<extraData>
+				<data id="data1"></data>
+				<data id="data1"></data>
+			</extraData>
+		</unit>
+	</units>
+</race>
\ No newline at end of file