Mercurial > repos > IBBoard.WarFoundry.API.Tests
annotate API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 36:82cd08385bfe
Fixes #228: Crash on invalid ability ID
* Replace zipped Race and System files with unpackaged XML
* Add helper class to create WarFoundry objects from XML files for tests
* Use new helper classes to make test pass
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 24 Dec 2009 20:14:28 +0000 |
parents | 4302e6b2c5c1 |
children | 00abd1c2f7d6 |
rev | line source |
---|---|
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (WarFoundryXmlRaceFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
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. |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.Collections.Generic; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using System.IO; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using System.Xml; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 using NUnit.Framework; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 using IBBoard.WarFoundry.API.Objects; |
35
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
11 using IBBoard.WarFoundry.API.Objects.Mock; |
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 using IBBoard.IO; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 namespace IBBoard.WarFoundry.API.Factories.Xml |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 { |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 [TestFixture()] |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 public class WarFoundryXmlRaceFactoryTest |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 { |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 [Test()] |
35
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
22 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Ability for Empire General with ID leaderOfMen did not exist in race definition")] |
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors () |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 { |
35
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
25 try |
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
26 { |
36
82cd08385bfe
Fixes #228: Crash on invalid ability ID
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
27 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/race-with-non-existant-ability.systemx")); |
82cd08385bfe
Fixes #228: Crash on invalid ability ID
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
28 FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system); |
82cd08385bfe
Fixes #228: Crash on invalid ability ID
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
29 WarFoundryLoader.SetDefault(fixedLoader); |
82cd08385bfe
Fixes #228: Crash on invalid ability ID
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
30 FileInfo raceFile = new FileInfo ("testdata/race-with-non-existant-ability.racex"); |
82cd08385bfe
Fixes #228: Crash on invalid ability ID
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
31 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile); |
35
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
32 Category[] cats = race.Categories; |
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
33 } |
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
34 finally |
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
35 { |
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
36 WarFoundryLoader.SetDefault(null); |
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
37 } |
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 } |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 [Test()] |
35
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
33
diff
changeset
|
41 [ExpectedException(typeof(InvalidFileException), ExpectedMessage="Referenced game system, 'nonexistant-system', did not exist")] |
33
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors () |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 { |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-game-system.race")); |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 Assert.AreEqual(1, objs.Count); |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator(); |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 enumerator.Reset(); |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 enumerator.MoveNext(); |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 Race race = (Race)enumerator.Current; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 Category[] cats = race.Categories; |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 } |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 } |
03a8ab5e90d6
Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 } |