comparison API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 58:c642d217036e

Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type * Simplify "non-existant ability" unit test by removing SystemX file * Remove line number checks, since Mono exception line numbers are end of file when the exception is a missing key ** * Re-implement equipment slot check test ** previous line numbers were taken from errors saying that keyref's key definition couldn't be found, not an error saying that the keyref value didn't exist
author IBBoard <dev@ibboard.co.uk>
date Sat, 12 Jun 2010 20:40:18 +0000
parents 745820ad7656
children 6efa080b500f
comparison
equal deleted inserted replaced
57:745820ad7656 58:c642d217036e
13 13
14 namespace IBBoard.WarFoundry.API.Factories.Xml 14 namespace IBBoard.WarFoundry.API.Factories.Xml
15 { 15 {
16 //It would be better to explicitly check that some of these errors are certain types of schema validation error, but Mono and .Net have 16 //It would be better to explicitly check that some of these errors are certain types of schema validation error, but Mono and .Net have
17 //different exception messages for the same text and just have one class for all schema exceptions of all types. 17 //different exception messages for the same text and just have one class for all schema exceptions of all types.
18 //We can't even check line numbers because Mono embeds them in the text and the actual line number is the end of the file.
18 [TestFixture()] 19 [TestFixture()]
19 public class WarFoundryXmlRaceFactoryTest 20 public class WarFoundryXmlRaceFactoryTest
20 { 21 {
21 [TearDown()] 22 [TearDown()]
22 public void AfterTestCleanup() 23 public void AfterTestCleanup()
23 { 24 {
24 WarFoundryLoader.SetDefault(null); 25 WarFoundryLoader.SetDefault(null);
25 } 26 }
26 27
27 [Test()] 28 [Test()]
28 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Ability for Empire General with ID leaderOfMen did not exist in race definition")]
29 public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors() 29 public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors()
30 { 30 {
31 SetDefaultGameSystem(new FileInfo("testdata/race-with-non-existant-ability.systemx")); 31 SetDefaultGameSystem();
32 FileInfo raceFile = new FileInfo("testdata/race-with-non-existant-ability.racex"); 32 FileInfo raceFile = new FileInfo("testdata/race-with-non-existant-ability.racex");
33 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 33
34 race.EnsureFullyLoaded(); 34 try
35 {
36 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
37 }
38 catch (InvalidFileException ex)
39 {
40 Console.WriteLine(ex.Message);
41 Exception innerException = ex.InnerException;
42 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
43 //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException;
44 //Assert.That(schemaEx.LineNumber, Is.EqualTo(17));
45 //Assert.That(schemaEx.LinePosition, Is.EqualTo(6));
46 }
35 } 47 }
36 48
37 [Test()] 49 [Test()]
38 public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError() 50 public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError()
39 { 51 {
44 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 56 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
45 Assert.Fail(); 57 Assert.Fail();
46 } 58 }
47 catch (InvalidFileException ex) 59 catch (InvalidFileException ex)
48 { 60 {
61 Console.WriteLine(ex.Message);
49 Exception innerException = ex.InnerException; 62 Exception innerException = ex.InnerException;
50 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException))); 63 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
51 XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException; 64 //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException;
52 Assert.That(schemaEx.LineNumber, Is.EqualTo(6)); 65 //Assert.That(schemaEx.LineNumber, Is.EqualTo(6));
53 Assert.That(schemaEx.LinePosition, Is.EqualTo(6)); 66 //Assert.That(schemaEx.LinePosition, Is.EqualTo(6));
54 } 67 }
55 68
56 } 69 }
57 70
58 [Test()] 71 [Test()]
59 [ExpectedException(typeof(InvalidFileException), ExpectedMessage = "TBD")]
60 public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors() 72 public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors()
61 { 73 {
62 SetDefaultGameSystem(); 74 SetDefaultGameSystem();
63 FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-reference.racex"); 75 FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-reference.racex");
64 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 76
65 race.EnsureFullyLoaded(); 77 try
78 {
79 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
80 }
81 catch (InvalidFileException ex)
82 {
83 Console.WriteLine(ex.Message);
84 Exception innerException = ex.InnerException;
85 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
86 //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException;
87 //Assert.That(schemaEx.LineNumber, Is.EqualTo(6));
88 //Assert.That(schemaEx.LinePosition, Is.EqualTo(6));
89 }
66 } 90 }
67 91
68 [Test()] 92 [Test()]
69 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")] 93 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")]
70 public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors() 94 public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors()