Mercurial > repos > IBBoard.WarFoundry.API.Tests
comparison API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 57:745820ad7656
Re #274: Crash when missing unit member ID
* Add more specific tests for key and keyref for member type
* Remove ExpectedException with unknown message
Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type
* Add explanation of why tests aren't as perfect as they could be
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 12 Jun 2010 19:51:48 +0000 |
parents | 9d68b5dd70b3 |
children | c642d217036e |
comparison
equal
deleted
inserted
replaced
56:c6e5b8a1948d | 57:745820ad7656 |
---|---|
1 // This file (WarFoundryXmlRaceFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard | 1 // This file (WarFoundryXmlRaceFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard |
2 // | 2 // |
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. | 3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
4 | 4 |
5 using System; | |
6 using System.Collections.Generic; | |
7 using System.IO; | |
8 using System.Xml.Schema; | |
5 using IBBoard.IO; | 9 using IBBoard.IO; |
6 using IBBoard.WarFoundry.API.Objects; | 10 using IBBoard.WarFoundry.API.Objects; |
7 using NUnit.Framework; | 11 using NUnit.Framework; |
8 using System.Collections.Generic; | |
9 using System.IO; | |
10 using NUnit.Framework.SyntaxHelpers; | 12 using NUnit.Framework.SyntaxHelpers; |
11 | 13 |
12 namespace IBBoard.WarFoundry.API.Factories.Xml | 14 namespace IBBoard.WarFoundry.API.Factories.Xml |
13 { | 15 { |
14 | 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 |
15 | 17 //different exception messages for the same text and just have one class for all schema exceptions of all types. |
16 [TestFixture()] | 18 [TestFixture()] |
17 public class WarFoundryXmlRaceFactoryTest | 19 public class WarFoundryXmlRaceFactoryTest |
18 { | 20 { |
19 [TearDown()] | 21 [TearDown()] |
20 public void AfterTestCleanup() | 22 public void AfterTestCleanup() |
31 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); | 33 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); |
32 race.EnsureFullyLoaded(); | 34 race.EnsureFullyLoaded(); |
33 } | 35 } |
34 | 36 |
35 [Test()] | 37 [Test()] |
36 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="TBD")] | |
37 public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError() | 38 public void TestCompleteLoadingOnRaceWithIncorrectMemberTypeIDError() |
38 { | 39 { |
39 SetDefaultGameSystem(); | 40 SetDefaultGameSystem(); |
40 FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex"); | 41 FileInfo raceFile = new FileInfo("testdata/single-unit-non-existant-type-referencing-race.racex"); |
41 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); | 42 try |
42 race.EnsureFullyLoaded(); | 43 { |
44 SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); | |
45 Assert.Fail(); | |
46 } | |
47 catch (InvalidFileException ex) | |
48 { | |
49 Exception innerException = ex.InnerException; | |
50 Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException))); | |
51 XmlSchemaValidationException schemaEx = (XmlSchemaValidationException) innerException; | |
52 Assert.That(schemaEx.LineNumber, Is.EqualTo(6)); | |
53 Assert.That(schemaEx.LinePosition, Is.EqualTo(6)); | |
54 } | |
55 | |
43 } | 56 } |
44 | 57 |
45 [Test()] | 58 [Test()] |
46 [ExpectedException(typeof(InvalidFileException), ExpectedMessage = "TBD")] | 59 [ExpectedException(typeof(InvalidFileException), ExpectedMessage = "TBD")] |
47 public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors() | 60 public void TestCompleteLoadingOnRaceWithIncorrectEquipmentSlotErrors() |