comparison API/Factories/Xml/WarFoundryXmlArmyParserTest.cs @ 52:97ea355f9564

Re #270: Add multiple categories to API * Add tests for army loading to make sure that units go back in same category
author IBBoard <dev@ibboard.co.uk>
date Wed, 19 May 2010 20:05:52 +0000
parents
children e173c5512067
comparison
equal deleted inserted replaced
51:9d68b5dd70b3 52:97ea355f9564
1 // This file (WarFoundryXmlArmyParserTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2010 IBBoard
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.
4 using IBBoard.WarFoundry.API.Factories.Mock;
5 using IBBoard.WarFoundry.API.Objects;
6 using NUnit.Framework;
7 using System.IO;
8 using NUnit.Framework.SyntaxHelpers;
9
10 namespace IBBoard.WarFoundry.API.Factories.Xml
11 {
12 [TestFixture()]
13 public class WarFoundryXmlArmyParserTest
14 {
15 [TearDown()]
16 public void AfterTestCleanup()
17 {
18 WarFoundryLoader.SetDefault(null);
19 }
20
21 [Test()]
22 public void TestUnitFromNonMainCategoryIsInCorrectCategory()
23 {
24 FixedObjectWarFoundryLoader loader = new FixedObjectWarFoundryLoader();
25 WarFoundryLoader.SetDefault(loader);
26 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
27 loader.SetGameSystem(system);
28 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/single-unit-two-categories.racex"));
29 loader.SetRace(race);
30 WarFoundryXmlArmyParser parser = new WarFoundryXmlArmyParser(null, SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/unit-in-non-main-category.armyx")));
31 Army army = parser.GetArmy();
32 Unit unit = army.GetUnits()[0];
33 Category cat2 = army.Race.GetCategory("cat2");
34 Assert.That(army.GetUnits(cat2), Has.Member(unit));
35 Assert.That(unit.Category.Category, Is.EqualTo(cat2));
36 Assert.That(army.GetUnits(army.Race.GetCategory("cat1")), Has.No.Member(unit));
37 }
38
39 [Test()]
40 public void TestUnitFromMainCategoryIsInCorrectCategory()
41 {
42 FixedObjectWarFoundryLoader loader = new FixedObjectWarFoundryLoader();
43 WarFoundryLoader.SetDefault(loader);
44 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
45 loader.SetGameSystem(system);
46 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/single-unit-two-categories.racex"));
47 loader.SetRace(race);
48 WarFoundryXmlArmyParser parser = new WarFoundryXmlArmyParser(null, SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/unit-in-specified-main-category.armyx")));
49 Army army = parser.GetArmy();
50 Unit unit = army.GetUnits()[0];
51 Category cat1 = army.Race.GetCategory("cat1");
52 Assert.That(army.GetUnits(cat1), Has.Member(unit));
53 Assert.That(unit.Category.Category, Is.EqualTo(cat1));
54 }
55
56 [Test()]
57 public void TestUnitFromDefaultCategoryIsInCorrectCategory()
58 {
59 FixedObjectWarFoundryLoader loader = new FixedObjectWarFoundryLoader();
60 WarFoundryLoader.SetDefault(loader);
61 GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
62 loader.SetGameSystem(system);
63 Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/single-unit-two-categories.racex"));
64 loader.SetRace(race);
65 WarFoundryXmlArmyParser parser = new WarFoundryXmlArmyParser(null, SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/unit-in-default-category.armyx")));
66 Army army = parser.GetArmy();
67 Unit unit = army.GetUnits()[0];
68 Category cat1 = army.Race.GetCategory("cat1");
69 Assert.That(army.GetUnits(cat1), Has.Member(unit));
70 Assert.That(unit.Category.Category, Is.EqualTo(cat1));
71 }
72 }
73 }
74