annotate API/Factories/Xml/WarFoundryXmlArmyParserTest.cs @ 76:fb60ff2002fd WarFoundry_v0.1.1

Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller * Add the data files as well! no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sat, 30 Oct 2010 14:46:06 +0000
parents 97ea355f9564
children e173c5512067
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (WarFoundryXmlArmyParserTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2010 IBBoard
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
97ea355f9564 Re #270: Add multiple categories to API
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.
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using IBBoard.WarFoundry.API.Factories.Mock;
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using IBBoard.WarFoundry.API.Objects;
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using NUnit.Framework;
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.IO;
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using NUnit.Framework.SyntaxHelpers;
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 namespace IBBoard.WarFoundry.API.Factories.Xml
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 {
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 [TestFixture()]
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 public class WarFoundryXmlArmyParserTest
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 {
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 [TearDown()]
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 public void AfterTestCleanup()
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 WarFoundryLoader.SetDefault(null);
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 }
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 [Test()]
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 public void TestUnitFromNonMainCategoryIsInCorrectCategory()
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 {
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 FixedObjectWarFoundryLoader loader = new FixedObjectWarFoundryLoader();
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 WarFoundryLoader.SetDefault(loader);
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 loader.SetGameSystem(system);
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/single-unit-two-categories.racex"));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 loader.SetRace(race);
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 WarFoundryXmlArmyParser parser = new WarFoundryXmlArmyParser(null, SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/unit-in-non-main-category.armyx")));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 Army army = parser.GetArmy();
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 Unit unit = army.GetUnits()[0];
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 Category cat2 = army.Race.GetCategory("cat2");
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 Assert.That(army.GetUnits(cat2), Has.Member(unit));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 Assert.That(unit.Category.Category, Is.EqualTo(cat2));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 Assert.That(army.GetUnits(army.Race.GetCategory("cat1")), Has.No.Member(unit));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 }
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 [Test()]
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 public void TestUnitFromMainCategoryIsInCorrectCategory()
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 {
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 FixedObjectWarFoundryLoader loader = new FixedObjectWarFoundryLoader();
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 WarFoundryLoader.SetDefault(loader);
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 loader.SetGameSystem(system);
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/single-unit-two-categories.racex"));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 loader.SetRace(race);
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 WarFoundryXmlArmyParser parser = new WarFoundryXmlArmyParser(null, SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/unit-in-specified-main-category.armyx")));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 Army army = parser.GetArmy();
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 Unit unit = army.GetUnits()[0];
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 Category cat1 = army.Race.GetCategory("cat1");
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 Assert.That(army.GetUnits(cat1), Has.Member(unit));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 Assert.That(unit.Category.Category, Is.EqualTo(cat1));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 }
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 [Test()]
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 public void TestUnitFromDefaultCategoryIsInCorrectCategory()
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 {
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 FixedObjectWarFoundryLoader loader = new FixedObjectWarFoundryLoader();
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 WarFoundryLoader.SetDefault(loader);
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 loader.SetGameSystem(system);
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/single-unit-two-categories.racex"));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 loader.SetRace(race);
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 WarFoundryXmlArmyParser parser = new WarFoundryXmlArmyParser(null, SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/unit-in-default-category.armyx")));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 Army army = parser.GetArmy();
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 Unit unit = army.GetUnits()[0];
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 Category cat1 = army.Race.GetCategory("cat1");
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 Assert.That(army.GetUnits(cat1), Has.Member(unit));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 Assert.That(unit.Category.Category, Is.EqualTo(cat1));
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 }
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 }
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 }
97ea355f9564 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74