changeset 59:6efa080b500f

Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type * Add unit tests and data for unit containership * Add unit test and data for unit equipment * Correct name of test data for equipment slot unit test
author IBBoard <dev@ibboard.co.uk>
date Mon, 14 Jun 2010 19:57:53 +0000
parents c642d217036e
children f2348c00e633
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/invalid-contained-unit-reference.racex testdata/single-unit-with-invalid-equipment-reference.racex testdata/single-unit-with-invalid-equipment-slot-reference.racex testdata/valid-contained-unit-reference.racex
diffstat 6 files changed, 145 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sat Jun 12 20:40:18 2010 +0000
     1.2 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Mon Jun 14 19:57:53 2010 +0000
     1.3 @@ -34,15 +34,13 @@
     1.4  			try
     1.5  			{
     1.6  				SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
     1.7 +				Assert.Fail("Excepted exception not thrown");
     1.8  			}
     1.9  			catch (InvalidFileException ex)
    1.10  			{
    1.11  				Console.WriteLine(ex.Message);
    1.12  				Exception innerException = ex.InnerException;
    1.13  				Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
    1.14 -				//XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException;
    1.15 -				//Assert.That(schemaEx.LineNumber, Is.EqualTo(17));
    1.16 -				//Assert.That(schemaEx.LinePosition, Is.EqualTo(6));
    1.17  			}
    1.18  		}
    1.19  		
    1.20 @@ -51,42 +49,85 @@
    1.21  		{
    1.22  			SetDefaultGameSystem();
    1.23  			FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex");
    1.24 +			
    1.25  			try
    1.26  			{
    1.27  				SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);			
    1.28 -				Assert.Fail();
    1.29 +				Assert.Fail("Excepted exception not thrown");
    1.30  			}
    1.31  			catch (InvalidFileException ex)
    1.32  			{
    1.33  				Console.WriteLine(ex.Message);
    1.34  				Exception innerException = ex.InnerException;
    1.35  				Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
    1.36 -				//XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException;
    1.37 -				//Assert.That(schemaEx.LineNumber, Is.EqualTo(6));
    1.38 -				//Assert.That(schemaEx.LinePosition, Is.EqualTo(6));
    1.39 -			}
    1.40 -			
    1.41 +			}			
    1.42  		}
    1.43  
    1.44  		[Test()]
    1.45  		public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors()
    1.46  		{
    1.47  			SetDefaultGameSystem();
    1.48 +			FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-slot-reference.racex");
    1.49 +			
    1.50 +			try
    1.51 +			{
    1.52 +				SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.53 +				Assert.Fail("Excepted exception not thrown");
    1.54 +			}
    1.55 +			catch (InvalidFileException ex)
    1.56 +			{
    1.57 +				Console.WriteLine(ex.Message);
    1.58 +				Exception innerException = ex.InnerException;
    1.59 +				Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
    1.60 +			}
    1.61 +		}
    1.62 +
    1.63 +		[Test()]
    1.64 +		public void TestCompleteLoadingOnRaceWithIncorrectEquipmentIDError()
    1.65 +		{
    1.66 +			SetDefaultGameSystem();
    1.67  			FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-reference.racex");
    1.68  			
    1.69  			try
    1.70  			{
    1.71  				SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.72 +				Assert.Fail("Excepted exception not thrown");
    1.73  			}
    1.74  			catch (InvalidFileException ex)
    1.75  			{
    1.76  				Console.WriteLine(ex.Message);
    1.77  				Exception innerException = ex.InnerException;
    1.78  				Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
    1.79 -				//XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException;
    1.80 -				//Assert.That(schemaEx.LineNumber, Is.EqualTo(6));
    1.81 -				//Assert.That(schemaEx.LinePosition, Is.EqualTo(6));
    1.82 +			}			
    1.83 +		}
    1.84 +
    1.85 +		[Test()]
    1.86 +		public void TestCompleteLoadingOnRaceWithIncorrectContainedUnitIDError()
    1.87 +		{
    1.88 +			SetDefaultGameSystem();
    1.89 +			FileInfo raceFile = new FileInfo("testdata/invalid-contained-unit-reference.racex");
    1.90 +			
    1.91 +			try
    1.92 +			{
    1.93 +				SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.94 +				Assert.Fail("Excepted exception not thrown");
    1.95  			}
    1.96 +			catch (InvalidFileException ex)
    1.97 +			{
    1.98 +				Console.WriteLine(ex.Message);
    1.99 +				Exception innerException = ex.InnerException;
   1.100 +				Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
   1.101 +			}
   1.102 +		}
   1.103 +
   1.104 +		[Test()]
   1.105 +		public void TestCompleteLoadingOnRaceWithCorrectContainedUnitIDLoadsData()
   1.106 +		{
   1.107 +			SetDefaultGameSystem();
   1.108 +			FileInfo raceFile = new FileInfo("testdata/valid-contained-unit-reference.racex");
   1.109 +			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
   1.110 +			UnitType unitType = race.GetUnitType("Empire1");
   1.111 +			Assert.That(unitType.ContainedUnitTypes, Has.Length(1));
   1.112  		}
   1.113  		
   1.114  		[Test()]
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Jun 12 20:40:18 2010 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Mon Jun 14 19:57:53 2010 +0000
     2.3 @@ -149,6 +149,15 @@
     2.4      <None Include="WarFoundryTests.nunit">
     2.5        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     2.6      </None>
     2.7 +    <None Include="testdata\single-unit-with-invalid-equipment-slot-reference.racex">
     2.8 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     2.9 +    </None>
    2.10 +    <None Include="testdata\invalid-contained-unit-reference.racex">
    2.11 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.12 +    </None>
    2.13 +    <None Include="testdata\valid-contained-unit-reference.racex">
    2.14 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.15 +    </None>
    2.16    </ItemGroup>
    2.17    <ItemGroup>
    2.18      <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/testdata/invalid-contained-unit-reference.racex	Mon Jun 14 19:57:53 2010 +0000
     3.3 @@ -0,0 +1,21 @@
     3.4 +<?xml version="1.0" encoding="UTF-8"?>
     3.5 +<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="Empire" name="Empire" system="default">
     3.6 +	<units>
     3.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     3.8 +			<stats>
     3.9 +				<stat name="M">4</stat>
    3.10 +				<stat name="WS">6</stat>
    3.11 +				<stat name="BS">6</stat>
    3.12 +				<stat name="S">4</stat>
    3.13 +				<stat name="T">4</stat>
    3.14 +				<stat name="W">3</stat>
    3.15 +				<stat name="I">6</stat>
    3.16 +				<stat name="A">4</stat>
    3.17 +				<stat name="Ld">9</stat>
    3.18 +			</stats>
    3.19 +			<contains>
    3.20 +				<containedUnit containedID="Empire2" />
    3.21 +			</contains>
    3.22 +		</unit>
    3.23 +	</units>
    3.24 +</race>
    3.25 \ No newline at end of file
     4.1 --- a/testdata/single-unit-with-invalid-equipment-reference.racex	Sat Jun 12 20:40:18 2010 +0000
     4.2 +++ b/testdata/single-unit-with-invalid-equipment-reference.racex	Mon Jun 14 19:57:53 2010 +0000
     4.3 @@ -13,11 +13,8 @@
     4.4  				<stat name="A">4</stat>
     4.5  				<stat name="Ld">9</stat>
     4.6  			</stats>
     4.7 -			<equipmentSlots>
     4.8 -				<equipmentSlot name="slot1"/>
     4.9 -			</equipmentSlots>
    4.10  			<unitEquipment>
    4.11 -				<unitEquipmentItem id="equip1" equipmentSlot="slot2"/>
    4.12 +				<unitEquipmentItem id="equip2"/>
    4.13  			</unitEquipment>
    4.14  		</unit>
    4.15  	</units>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/testdata/single-unit-with-invalid-equipment-slot-reference.racex	Mon Jun 14 19:57:53 2010 +0000
     5.3 @@ -0,0 +1,27 @@
     5.4 +<?xml version="1.0" encoding="UTF-8"?>
     5.5 +<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="Empire" name="Empire" system="nonexistant">
     5.6 +	<units>
     5.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     5.8 +			<stats>
     5.9 +				<stat name="M">4</stat>
    5.10 +				<stat name="WS">6</stat>
    5.11 +				<stat name="BS">6</stat>
    5.12 +				<stat name="S">4</stat>
    5.13 +				<stat name="T">4</stat>
    5.14 +				<stat name="W">3</stat>
    5.15 +				<stat name="I">6</stat>
    5.16 +				<stat name="A">4</stat>
    5.17 +				<stat name="Ld">9</stat>
    5.18 +			</stats>
    5.19 +			<equipmentSlots>
    5.20 +				<equipmentSlot name="slot1"/>
    5.21 +			</equipmentSlots>
    5.22 +			<unitEquipment>
    5.23 +				<unitEquipmentItem id="equip1" equipmentSlot="slot2"/>
    5.24 +			</unitEquipment>
    5.25 +		</unit>
    5.26 +	</units>
    5.27 +	<equipment>
    5.28 +		<equipmentItem id="equip1" name="sword" cost="1"/>
    5.29 +	</equipment>
    5.30 +</race>
    5.31 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/testdata/valid-contained-unit-reference.racex	Mon Jun 14 19:57:53 2010 +0000
     6.3 @@ -0,0 +1,34 @@
     6.4 +<?xml version="1.0" encoding="UTF-8"?>
     6.5 +<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="Empire" name="Empire" system="default">
     6.6 +	<units>
     6.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     6.8 +			<stats>
     6.9 +				<stat name="M">4</stat>
    6.10 +				<stat name="WS">6</stat>
    6.11 +				<stat name="BS">6</stat>
    6.12 +				<stat name="S">4</stat>
    6.13 +				<stat name="T">4</stat>
    6.14 +				<stat name="W">3</stat>
    6.15 +				<stat name="I">6</stat>
    6.16 +				<stat name="A">4</stat>
    6.17 +				<stat name="Ld">9</stat>
    6.18 +			</stats>
    6.19 +			<contains>
    6.20 +				<containedUnit containedID="Empire2" />
    6.21 +			</contains>
    6.22 +		</unit>
    6.23 +		<unit id="Empire2" typeName="Minion" cat="cat1" points="0">
    6.24 +			<stats>
    6.25 +				<stat name="M">4</stat>
    6.26 +				<stat name="WS">2</stat>
    6.27 +				<stat name="BS">2</stat>
    6.28 +				<stat name="S">2</stat>
    6.29 +				<stat name="T">2</stat>
    6.30 +				<stat name="W">1</stat>
    6.31 +				<stat name="I">2</stat>
    6.32 +				<stat name="A">1</stat>
    6.33 +				<stat name="Ld">5</stat>
    6.34 +			</stats>
    6.35 +		</unit>
    6.36 +	</units>
    6.37 +</race>
    6.38 \ No newline at end of file