annotate API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs @ 33:03a8ab5e90d6

Re #236: Race loading should fail cleanly if system doesn't exist * Add tests for race factory * Add test data that references non-existstent system * Make game system names for existing test data more distinct Re #228: Crash with missing abilityID * Initial failing test
author IBBoard <dev@ibboard.co.uk>
date Thu, 24 Dec 2009 14:53:18 +0000
parents
children 4302e6b2c5c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 using IBBoard.IO;
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 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
14 {
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 [TestFixture()]
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 public class WarFoundryXmlRaceFactoryTest
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 {
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 [Test()]
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 [ExpectedException(typeof(FileLoadException))]
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors ()
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 {
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-ability.race"));
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 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
26 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
27 enumerator.Reset();
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 enumerator.MoveNext();
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 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
30 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
31 }
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 [Test()]
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 [ExpectedException(typeof(InvalidFileException))]
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors ()
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 {
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 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
38 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
39 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
40 enumerator.Reset();
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 enumerator.MoveNext();
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 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
43 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
44 }
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 }
03a8ab5e90d6 Re #236: Race loading should fail cleanly if system doesn't exist
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 }