changeset 51:9d68b5dd70b3

Re #270: Add multiple categories to API * Add test for unit being in multiple categories Also: * Add assertions in other tests that unit is cached in army
author IBBoard <dev@ibboard.co.uk>
date Wed, 19 May 2010 19:22:20 +0000
parents d3519f38a0f4
children 97ea355f9564
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/single-unit-two-categories.racex
diffstat 3 files changed, 49 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Tue May 18 19:57:44 2010 +0000
+++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Wed May 19 19:22:20 2010 +0000
@@ -71,6 +71,7 @@
 			SetDefaultGameSystem();
 			FileInfo raceFile = new FileInfo("testdata/single-unit-race.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			Assert.That(race.GetUnitType("Empire1"), Is.Not.Null);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
 			Assert.AreEqual(1, unitTypes.Length);
 			UnitType unitType = unitTypes[0];
@@ -87,6 +88,7 @@
 			SetDefaultGameSystem();
 			FileInfo raceFile = new FileInfo("testdata/single-unit-type-referencing-race.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			Assert.That(race.GetUnitType("Empire1"), Is.Not.Null);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
 			Assert.AreEqual(1, unitTypes.Length);
 			UnitType unitType = unitTypes[0];
@@ -103,6 +105,7 @@
 			SetDefaultGameSystem();
 			FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			Assert.That(race.GetUnitType("Empire1"), Is.Not.Null);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
 			Assert.AreEqual(1, unitTypes.Length);
 			UnitType unitType = unitTypes[0];
@@ -122,6 +125,7 @@
 			SetDefaultGameSystem();
 			FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race-with-override.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			Assert.That(race.GetUnitType("Empire1"), Is.Not.Null);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
 			Assert.AreEqual(1, unitTypes.Length);
 			UnitType unitType = unitTypes[0];
@@ -140,6 +144,7 @@
 			SetDefaultGameSystem();
 			FileInfo raceFile = new FileInfo("testdata/single-unit-no-stats-race.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			Assert.That(race.GetUnitType("Empire1"), Is.Not.Null);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
 			Assert.AreEqual(1, unitTypes.Length);
 			UnitType unitType = unitTypes[0];
@@ -199,6 +204,25 @@
 			Assert.That(unitType.Categories, Has.Member(category));
 			Assert.That(unitType.Categories, Has.Member(race.GetCategory("cat2")));
 		}
+
+		[Test()]
+		public void TestSingleUnitArmyWithMultipleCategoriesIsInEachCategory()
+		{
+			SetDefaultGameSystem();
+			FileInfo raceFile = new FileInfo("testdata/single-unit-two-categories.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			UnitType unitType = race.GetUnitType("Empire1");
+			Assert.That(unitType.Categories.Length, Is.EqualTo(2));
+			Category cat1 = race.GetCategory("cat1");
+			Category cat2 = race.GetCategory("cat2");
+			Assert.That(unitType.MainCategory, Is.EqualTo(cat1));
+			Assert.That(unitType.Categories, Has.Member(cat1));
+			Assert.That(unitType.Categories, Has.Member(cat2));
+			Assert.That(race.GetUnitTypes(cat1), Is.All.EqualTo(unitType));
+			UnitType[] unitTypesCat2 = race.GetUnitTypes(cat2);
+			Assert.That(unitTypesCat2, Has.Length(1));
+			Assert.That(unitTypesCat2, Is.All.EqualTo(unitType));
+		}
 		
 		private static void SetDefaultGameSystem()
 		{
--- a/IBBoard.WarFoundry.API.Tests.csproj	Tue May 18 19:57:44 2010 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Wed May 19 19:22:20 2010 +0000
@@ -121,6 +121,9 @@
     <None Include="testdata\single-unit-one-category-different-main-category.racex">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="testdata\single-unit-two-categories.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/single-unit-two-categories.racex	Wed May 19 19:22:20 2010 +0000
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="EmpireAlt" name="Empire (Extended)" system="default" lang="en">
+	<units>
+		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
+			<stats>
+				<stat name="M">4</stat>
+				<stat name="WS">6</stat>
+				<stat name="BS">6</stat>
+				<stat name="S">4</stat>
+				<stat name="T">4</stat>
+				<stat name="W">3</stat>
+				<stat name="I">6</stat>
+				<stat name="A">4</stat>
+				<stat name="Ld">9</stat>
+			</stats>
+			<unitCategories>
+				<unitCategory catID="cat1" />
+				<unitCategory catID="cat2" />
+			</unitCategories>
+		</unit>
+	</units>
+</race>
\ No newline at end of file