# HG changeset patch # User IBBoard # Date 1276545473 0 # Node ID 6efa080b500f1a1c4b185f3f80ccfc5ca234f714 # Parent c642d217036eccc345e359fdea4ab15c45cfbe25 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 diff -r c642d217036e -r 6efa080b500f API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs --- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs Sat Jun 12 20:40:18 2010 +0000 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs Mon Jun 14 19:57:53 2010 +0000 @@ -34,15 +34,13 @@ 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))); - //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException; - //Assert.That(schemaEx.LineNumber, Is.EqualTo(17)); - //Assert.That(schemaEx.LinePosition, Is.EqualTo(6)); } } @@ -51,42 +49,85 @@ { SetDefaultGameSystem(); FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex"); + try { SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); - Assert.Fail(); + Assert.Fail("Excepted exception not thrown"); } 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()] public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors() { SetDefaultGameSystem(); + FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-slot-reference.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 TestCompleteLoadingOnRaceWithIncorrectEquipmentIDError() + { + SetDefaultGameSystem(); FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-reference.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))); - //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException; - //Assert.That(schemaEx.LineNumber, Is.EqualTo(6)); - //Assert.That(schemaEx.LinePosition, Is.EqualTo(6)); + } + } + + [Test()] + public void TestCompleteLoadingOnRaceWithIncorrectContainedUnitIDError() + { + SetDefaultGameSystem(); + FileInfo raceFile = new FileInfo("testdata/invalid-contained-unit-reference.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 TestCompleteLoadingOnRaceWithCorrectContainedUnitIDLoadsData() + { + SetDefaultGameSystem(); + FileInfo raceFile = new FileInfo("testdata/valid-contained-unit-reference.racex"); + Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); + UnitType unitType = race.GetUnitType("Empire1"); + Assert.That(unitType.ContainedUnitTypes, Has.Length(1)); } [Test()] diff -r c642d217036e -r 6efa080b500f IBBoard.WarFoundry.API.Tests.csproj --- a/IBBoard.WarFoundry.API.Tests.csproj Sat Jun 12 20:40:18 2010 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Mon Jun 14 19:57:53 2010 +0000 @@ -149,6 +149,15 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + diff -r c642d217036e -r 6efa080b500f testdata/invalid-contained-unit-reference.racex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/invalid-contained-unit-reference.racex Mon Jun 14 19:57:53 2010 +0000 @@ -0,0 +1,21 @@ + + + + + + 4 + 6 + 6 + 4 + 4 + 3 + 6 + 4 + 9 + + + + + + + \ No newline at end of file diff -r c642d217036e -r 6efa080b500f testdata/single-unit-with-invalid-equipment-reference.racex --- a/testdata/single-unit-with-invalid-equipment-reference.racex Sat Jun 12 20:40:18 2010 +0000 +++ b/testdata/single-unit-with-invalid-equipment-reference.racex Mon Jun 14 19:57:53 2010 +0000 @@ -13,11 +13,8 @@ 4 9 - - - - + diff -r c642d217036e -r 6efa080b500f testdata/single-unit-with-invalid-equipment-slot-reference.racex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/single-unit-with-invalid-equipment-slot-reference.racex Mon Jun 14 19:57:53 2010 +0000 @@ -0,0 +1,27 @@ + + + + + + 4 + 6 + 6 + 4 + 4 + 3 + 6 + 4 + 9 + + + + + + + + + + + + + \ No newline at end of file diff -r c642d217036e -r 6efa080b500f testdata/valid-contained-unit-reference.racex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/valid-contained-unit-reference.racex Mon Jun 14 19:57:53 2010 +0000 @@ -0,0 +1,34 @@ + + + + + + 4 + 6 + 6 + 4 + 4 + 3 + 6 + 4 + 9 + + + + + + + + 4 + 2 + 2 + 2 + 2 + 1 + 2 + 1 + 5 + + + + \ No newline at end of file