view API/Factories/Xml/WarFoundryXmlArmyParserTest.cs @ 66:f671ead260b1

Re #290: Migrate to using key/keyref definitions instead of ID/IDREF type * Move some test data files to sub-folder * Test duplicate ID validation failures for equipment slots and equipment IDs * Test valid equipment references
author IBBoard <dev@ibboard.co.uk>
date Sun, 04 Jul 2010 14:28:13 +0000
parents 97ea355f9564
children e173c5512067
line wrap: on
line source

//  This file (WarFoundryXmlArmyParserTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2010 IBBoard
// 
//  // 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.
using IBBoard.WarFoundry.API.Factories.Mock;
using IBBoard.WarFoundry.API.Objects;
using NUnit.Framework;
using System.IO;
using NUnit.Framework.SyntaxHelpers;

namespace IBBoard.WarFoundry.API.Factories.Xml
{
	[TestFixture()]
	public class WarFoundryXmlArmyParserTest
	{
		[TearDown()]
		public void AfterTestCleanup()
		{
			WarFoundryLoader.SetDefault(null);
		}
		
		[Test()]
		public void TestUnitFromNonMainCategoryIsInCorrectCategory()
		{
			FixedObjectWarFoundryLoader loader = new FixedObjectWarFoundryLoader();
			WarFoundryLoader.SetDefault(loader);
			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
			loader.SetGameSystem(system);
			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/single-unit-two-categories.racex"));
			loader.SetRace(race);
			WarFoundryXmlArmyParser parser = new WarFoundryXmlArmyParser(null, SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/unit-in-non-main-category.armyx")));
			Army army = parser.GetArmy();
			Unit unit = army.GetUnits()[0];
			Category cat2 = army.Race.GetCategory("cat2");
			Assert.That(army.GetUnits(cat2), Has.Member(unit));
			Assert.That(unit.Category.Category, Is.EqualTo(cat2));
			Assert.That(army.GetUnits(army.Race.GetCategory("cat1")), Has.No.Member(unit));
		}
		
		[Test()]
		public void TestUnitFromMainCategoryIsInCorrectCategory()
		{
			FixedObjectWarFoundryLoader loader = new FixedObjectWarFoundryLoader();
			WarFoundryLoader.SetDefault(loader);
			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
			loader.SetGameSystem(system);
			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/single-unit-two-categories.racex"));
			loader.SetRace(race);
			WarFoundryXmlArmyParser parser = new WarFoundryXmlArmyParser(null, SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/unit-in-specified-main-category.armyx")));
			Army army = parser.GetArmy();
			Unit unit = army.GetUnits()[0];
			Category cat1 = army.Race.GetCategory("cat1");
			Assert.That(army.GetUnits(cat1), Has.Member(unit));
			Assert.That(unit.Category.Category, Is.EqualTo(cat1));
		}

		[Test()]
		public void TestUnitFromDefaultCategoryIsInCorrectCategory()
		{
			FixedObjectWarFoundryLoader loader = new FixedObjectWarFoundryLoader();
			WarFoundryLoader.SetDefault(loader);
			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
			loader.SetGameSystem(system);
			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/single-unit-two-categories.racex"));
			loader.SetRace(race);
			WarFoundryXmlArmyParser parser = new WarFoundryXmlArmyParser(null, SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/unit-in-default-category.armyx")));
			Army army = parser.GetArmy();
			Unit unit = army.GetUnits()[0];
			Category cat1 = army.Race.GetCategory("cat1");
			Assert.That(army.GetUnits(cat1), Has.Member(unit));
			Assert.That(unit.Category.Category, Is.EqualTo(cat1));
		}
	}
}