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 diff
     1.1 --- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Tue May 18 19:33:27 2010 +0000
     1.2 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Tue May 18 19:57:44 2010 +0000
     1.3 @@ -7,6 +7,7 @@
     1.4  using NUnit.Framework;
     1.5  using System.Collections.Generic;
     1.6  using System.IO;
     1.7 +using NUnit.Framework.SyntaxHelpers;
     1.8  
     1.9  namespace IBBoard.WarFoundry.API.Factories.Xml
    1.10  {
    1.11 @@ -152,6 +153,52 @@
    1.12  			
    1.13  			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
    1.14  		}
    1.15 +
    1.16 +		[Test()]
    1.17 +		public void TestSingleUnitArmyWithNoCategoriesUsesMainCategory()
    1.18 +		{
    1.19 +			SetDefaultGameSystem();
    1.20 +			FileInfo raceFile = new FileInfo("testdata/single-unit-no-category.racex");
    1.21 +			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.22 +			Category category = race.GetCategory("cat1");
    1.23 +			UnitType[] unitTypes = race.GetUnitTypes(category);
    1.24 +			Assert.AreEqual(1, unitTypes.Length);
    1.25 +			UnitType unitType = unitTypes[0];
    1.26 +			Assert.That(unitType.MainCategory, Is.EqualTo(category));
    1.27 +			Assert.That(unitType.Categories.Length, Is.EqualTo(1));
    1.28 +			Assert.That(unitType.Categories, Has.Member(category));
    1.29 +		}
    1.30 +
    1.31 +		[Test()]
    1.32 +		public void TestSingleUnitArmyWithOneCategoryAndSameMainCategoryHasOneCategory()
    1.33 +		{
    1.34 +			SetDefaultGameSystem();
    1.35 +			FileInfo raceFile = new FileInfo("testdata/single-unit-one-category-same-main-category.racex");
    1.36 +			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.37 +			Category category = race.GetCategory("cat1");
    1.38 +			UnitType[] unitTypes = race.GetUnitTypes(category);
    1.39 +			Assert.AreEqual(1, unitTypes.Length);
    1.40 +			UnitType unitType = unitTypes[0];
    1.41 +			Assert.That(unitType.MainCategory, Is.EqualTo(category));
    1.42 +			Assert.That(unitType.Categories.Length, Is.EqualTo(1));
    1.43 +			Assert.That(unitType.Categories, Has.Member(category));
    1.44 +		}
    1.45 +
    1.46 +		[Test()]
    1.47 +		public void TestSingleUnitArmyWithOneCategoryAndDifferentMainCategoryHasTwoCategories()
    1.48 +		{
    1.49 +			SetDefaultGameSystem();
    1.50 +			FileInfo raceFile = new FileInfo("testdata/single-unit-one-category-different-main-category.racex");
    1.51 +			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
    1.52 +			Category category = race.GetCategory("cat1");
    1.53 +			UnitType[] unitTypes = race.GetUnitTypes(category);
    1.54 +			Assert.AreEqual(1, unitTypes.Length);
    1.55 +			UnitType unitType = unitTypes[0];
    1.56 +			Assert.That(unitType.MainCategory, Is.EqualTo(category));
    1.57 +			Assert.That(unitType.Categories.Length, Is.EqualTo(2));
    1.58 +			Assert.That(unitType.Categories, Has.Member(category));
    1.59 +			Assert.That(unitType.Categories, Has.Member(race.GetCategory("cat2")));
    1.60 +		}
    1.61  		
    1.62  		private static void SetDefaultGameSystem()
    1.63  		{
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Tue May 18 19:33:27 2010 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Tue May 18 19:57:44 2010 +0000
     2.3 @@ -112,6 +112,15 @@
     2.4      <None Include="testdata\single-unit-with-invalid-equipment-reference.racex">
     2.5        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     2.6      </None>
     2.7 +    <None Include="testdata\single-unit-no-category.racex">
     2.8 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     2.9 +    </None>
    2.10 +    <None Include="testdata\single-unit-one-category-same-main-category.racex">
    2.11 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.12 +    </None>
    2.13 +    <None Include="testdata\single-unit-one-category-different-main-category.racex">
    2.14 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.15 +    </None>
    2.16    </ItemGroup>
    2.17    <ItemGroup>
    2.18      <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/testdata/single-unit-no-category.racex	Tue May 18 19:57:44 2010 +0000
     3.3 @@ -0,0 +1,18 @@
     3.4 +<?xml version="1.0" encoding="UTF-8"?>
     3.5 +<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">
     3.6 +	<units>
     3.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     3.8 +			<stats>
     3.9 +				<stat name="M">4</stat>
    3.10 +				<stat name="WS">6</stat>
    3.11 +				<stat name="BS">6</stat>
    3.12 +				<stat name="S">4</stat>
    3.13 +				<stat name="T">4</stat>
    3.14 +				<stat name="W">3</stat>
    3.15 +				<stat name="I">6</stat>
    3.16 +				<stat name="A">4</stat>
    3.17 +				<stat name="Ld">9</stat>
    3.18 +			</stats>
    3.19 +		</unit>
    3.20 +	</units>
    3.21 +</race>
    3.22 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/testdata/single-unit-one-category-different-main-category.racex	Tue May 18 19:57:44 2010 +0000
     4.3 @@ -0,0 +1,21 @@
     4.4 +<?xml version="1.0" encoding="UTF-8"?>
     4.5 +<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">
     4.6 +	<units>
     4.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     4.8 +			<stats>
     4.9 +				<stat name="M">4</stat>
    4.10 +				<stat name="WS">6</stat>
    4.11 +				<stat name="BS">6</stat>
    4.12 +				<stat name="S">4</stat>
    4.13 +				<stat name="T">4</stat>
    4.14 +				<stat name="W">3</stat>
    4.15 +				<stat name="I">6</stat>
    4.16 +				<stat name="A">4</stat>
    4.17 +				<stat name="Ld">9</stat>
    4.18 +			</stats>
    4.19 +			<unitCategories>
    4.20 +				<unitCategory catID="cat2" />
    4.21 +			</unitCategories>
    4.22 +		</unit>
    4.23 +	</units>
    4.24 +</race>
    4.25 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/testdata/single-unit-one-category-same-main-category.racex	Tue May 18 19:57:44 2010 +0000
     5.3 @@ -0,0 +1,21 @@
     5.4 +<?xml version="1.0" encoding="UTF-8"?>
     5.5 +<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">
     5.6 +	<units>
     5.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     5.8 +			<stats>
     5.9 +				<stat name="M">4</stat>
    5.10 +				<stat name="WS">6</stat>
    5.11 +				<stat name="BS">6</stat>
    5.12 +				<stat name="S">4</stat>
    5.13 +				<stat name="T">4</stat>
    5.14 +				<stat name="W">3</stat>
    5.15 +				<stat name="I">6</stat>
    5.16 +				<stat name="A">4</stat>
    5.17 +				<stat name="Ld">9</stat>
    5.18 +			</stats>
    5.19 +			<unitCategories>
    5.20 +				<unitCategory catID="cat1" />
    5.21 +			</unitCategories>
    5.22 +		</unit>
    5.23 +	</units>
    5.24 +</race>
    5.25 \ No newline at end of file