changeset 50:d3519f38a0f4

Re #270: Add multiple categories to API * Add unit tests and test data for handling multiple categories and existing method
author IBBoard <dev@ibboard.co.uk>
date Tue, 18 May 2010 19:57:44 +0000
parents 24a40c49b6ae
children 9d68b5dd70b3
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/single-unit-no-category.racex testdata/single-unit-one-category-different-main-category.racex testdata/single-unit-one-category-same-main-category.racex
diffstat 5 files changed, 116 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Tue May 18 19:33:27 2010 +0000
+++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Tue May 18 19:57:44 2010 +0000
@@ -7,6 +7,7 @@
 using NUnit.Framework;
 using System.Collections.Generic;
 using System.IO;
+using NUnit.Framework.SyntaxHelpers;
 
 namespace IBBoard.WarFoundry.API.Factories.Xml
 {
@@ -152,6 +153,52 @@
 			
 			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
 		}
+
+		[Test()]
+		public void TestSingleUnitArmyWithNoCategoriesUsesMainCategory()
+		{
+			SetDefaultGameSystem();
+			FileInfo raceFile = new FileInfo("testdata/single-unit-no-category.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			Category category = race.GetCategory("cat1");
+			UnitType[] unitTypes = race.GetUnitTypes(category);
+			Assert.AreEqual(1, unitTypes.Length);
+			UnitType unitType = unitTypes[0];
+			Assert.That(unitType.MainCategory, Is.EqualTo(category));
+			Assert.That(unitType.Categories.Length, Is.EqualTo(1));
+			Assert.That(unitType.Categories, Has.Member(category));
+		}
+
+		[Test()]
+		public void TestSingleUnitArmyWithOneCategoryAndSameMainCategoryHasOneCategory()
+		{
+			SetDefaultGameSystem();
+			FileInfo raceFile = new FileInfo("testdata/single-unit-one-category-same-main-category.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			Category category = race.GetCategory("cat1");
+			UnitType[] unitTypes = race.GetUnitTypes(category);
+			Assert.AreEqual(1, unitTypes.Length);
+			UnitType unitType = unitTypes[0];
+			Assert.That(unitType.MainCategory, Is.EqualTo(category));
+			Assert.That(unitType.Categories.Length, Is.EqualTo(1));
+			Assert.That(unitType.Categories, Has.Member(category));
+		}
+
+		[Test()]
+		public void TestSingleUnitArmyWithOneCategoryAndDifferentMainCategoryHasTwoCategories()
+		{
+			SetDefaultGameSystem();
+			FileInfo raceFile = new FileInfo("testdata/single-unit-one-category-different-main-category.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			Category category = race.GetCategory("cat1");
+			UnitType[] unitTypes = race.GetUnitTypes(category);
+			Assert.AreEqual(1, unitTypes.Length);
+			UnitType unitType = unitTypes[0];
+			Assert.That(unitType.MainCategory, Is.EqualTo(category));
+			Assert.That(unitType.Categories.Length, Is.EqualTo(2));
+			Assert.That(unitType.Categories, Has.Member(category));
+			Assert.That(unitType.Categories, Has.Member(race.GetCategory("cat2")));
+		}
 		
 		private static void SetDefaultGameSystem()
 		{
--- a/IBBoard.WarFoundry.API.Tests.csproj	Tue May 18 19:33:27 2010 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Tue May 18 19:57:44 2010 +0000
@@ -112,6 +112,15 @@
     <None Include="testdata\single-unit-with-invalid-equipment-reference.racex">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="testdata\single-unit-no-category.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\single-unit-one-category-same-main-category.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\single-unit-one-category-different-main-category.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-no-category.racex	Tue May 18 19:57:44 2010 +0000
@@ -0,0 +1,18 @@
+<?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>
+		</unit>
+	</units>
+</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/single-unit-one-category-different-main-category.racex	Tue May 18 19:57:44 2010 +0000
@@ -0,0 +1,21 @@
+<?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="cat2" />
+			</unitCategories>
+		</unit>
+	</units>
+</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/single-unit-one-category-same-main-category.racex	Tue May 18 19:57:44 2010 +0000
@@ -0,0 +1,21 @@
+<?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" />
+			</unitCategories>
+		</unit>
+	</units>
+</race>
\ No newline at end of file