comparison API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 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
comparison
equal deleted inserted replaced
58:c642d217036e 59:6efa080b500f
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 33
34 try 34 try
35 { 35 {
36 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 36 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
37 } 37 Assert.Fail("Excepted exception not thrown");
38 catch (InvalidFileException ex) 38 }
39 { 39 catch (InvalidFileException ex)
40 Console.WriteLine(ex.Message); 40 {
41 Exception innerException = ex.InnerException; 41 Console.WriteLine(ex.Message);
42 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException))); 42 Exception innerException = ex.InnerException;
43 //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException; 43 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
44 //Assert.That(schemaEx.LineNumber, Is.EqualTo(17));
45 //Assert.That(schemaEx.LinePosition, Is.EqualTo(6));
46 } 44 }
47 } 45 }
48 46
49 [Test()] 47 [Test()]
50 public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError() 48 public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError()
51 { 49 {
52 SetDefaultGameSystem(); 50 SetDefaultGameSystem();
53 FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex"); 51 FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex");
52
54 try 53 try
55 { 54 {
56 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 55 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
57 Assert.Fail(); 56 Assert.Fail("Excepted exception not thrown");
58 } 57 }
59 catch (InvalidFileException ex) 58 catch (InvalidFileException ex)
60 { 59 {
61 Console.WriteLine(ex.Message); 60 Console.WriteLine(ex.Message);
62 Exception innerException = ex.InnerException; 61 Exception innerException = ex.InnerException;
63 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException))); 62 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
64 //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException; 63 }
65 //Assert.That(schemaEx.LineNumber, Is.EqualTo(6));
66 //Assert.That(schemaEx.LinePosition, Is.EqualTo(6));
67 }
68
69 } 64 }
70 65
71 [Test()] 66 [Test()]
72 public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors() 67 public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors()
73 { 68 {
74 SetDefaultGameSystem(); 69 SetDefaultGameSystem();
70 FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-slot-reference.racex");
71
72 try
73 {
74 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
75 Assert.Fail("Excepted exception not thrown");
76 }
77 catch (InvalidFileException ex)
78 {
79 Console.WriteLine(ex.Message);
80 Exception innerException = ex.InnerException;
81 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
82 }
83 }
84
85 [Test()]
86 public void TestCompleteLoadingOnRaceWithIncorrectEquipmentIDError()
87 {
88 SetDefaultGameSystem();
75 FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-reference.racex"); 89 FileInfo raceFile = new FileInfo("testdata/single-unit-with-invalid-equipment-reference.racex");
76 90
77 try 91 try
78 { 92 {
79 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); 93 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
80 } 94 Assert.Fail("Excepted exception not thrown");
81 catch (InvalidFileException ex) 95 }
82 { 96 catch (InvalidFileException ex)
83 Console.WriteLine(ex.Message); 97 {
84 Exception innerException = ex.InnerException; 98 Console.WriteLine(ex.Message);
85 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException))); 99 Exception innerException = ex.InnerException;
86 //XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException; 100 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
87 //Assert.That(schemaEx.LineNumber, Is.EqualTo(6)); 101 }
88 //Assert.That(schemaEx.LinePosition, Is.EqualTo(6)); 102 }
89 } 103
104 [Test()]
105 public void TestCompleteLoadingOnRaceWithIncorrectContainedUnitIDError()
106 {
107 SetDefaultGameSystem();
108 FileInfo raceFile = new FileInfo("testdata/invalid-contained-unit-reference.racex");
109
110 try
111 {
112 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
113 Assert.Fail("Excepted exception not thrown");
114 }
115 catch (InvalidFileException ex)
116 {
117 Console.WriteLine(ex.Message);
118 Exception innerException = ex.InnerException;
119 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
120 }
121 }
122
123 [Test()]
124 public void TestCompleteLoadingOnRaceWithCorrectContainedUnitIDLoadsData()
125 {
126 SetDefaultGameSystem();
127 FileInfo raceFile = new FileInfo("testdata/valid-contained-unit-reference.racex");
128 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
129 UnitType unitType = race.GetUnitType("Empire1");
130 Assert.That(unitType.ContainedUnitTypes, Has.Length(1));
90 } 131 }
91 132
92 [Test()] 133 [Test()]
93 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")] 134 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")]
94 public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors() 135 public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors()