changeset 225:c6313a2c08a2

Re #359: Add "only contained" attribute to unit types * Add missing class * Add tests for loading files and test data
author IBBoard <dev@ibboard.co.uk>
date Sat, 14 Apr 2012 19:57:32 +0100
parents 49480e1a8f90
children 763ce93f1bfb
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs API/Objects/Mock/MockContainedUnitType.cs IBBoard.WarFoundry.API.Tests.csproj testdata/xml-race-factory/with-contained-only-unit.racex testdata/xml-race-factory/with-mixed-contained-units.racex
diffstat 5 files changed, 132 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sat Apr 14 16:58:20 2012 +0100
     1.2 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sat Apr 14 19:57:32 2012 +0100
     1.3 @@ -384,6 +384,30 @@
     1.4  			Assert.That(unitType.GetRequirements()[0], Is.InstanceOfType(typeof(UnitRequiresNoMoreThanNOfUnitTypeRequirement)));
     1.5  		}
     1.6  
     1.7 +		[Test]
     1.8 +		public void TestContainedUnitsAreLoaded()
     1.9 +		{
    1.10 +			SetDefaultGameSystem();
    1.11 +			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-race-factory/with-contained-only-unit.racex"));
    1.12 +			Assert.That(race.GetUnitType("Empire2"), Is.Not.Null);
    1.13 +			UnitType unitType1 = race.GetUnitType("Empire1");
    1.14 +			Assert.That(race.GetUnitTypes(race.GetCategory("cat1")), Has.Length(1));
    1.15 +			Assert.That(race.GetUnitTypes(race.GetCategory("cat1")), Has.Member(unitType1));
    1.16 +		}
    1.17 +
    1.18 +		[Test]
    1.19 +		public void TestMixedContainedUnitsAreLoaded()
    1.20 +		{
    1.21 +			SetDefaultGameSystem();
    1.22 +			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-race-factory/with-mixed-contained-units.racex"));
    1.23 +			Assert.That(race.GetUnitType("Empire2"), Is.Not.Null);
    1.24 +			UnitType unitType1 = race.GetUnitType("Empire1");
    1.25 +			UnitType unitType3 = race.GetUnitType("Empire3");
    1.26 +			Assert.That(race.GetUnitTypes(race.GetCategory("cat1")), Has.Length(2));
    1.27 +			Assert.That(race.GetUnitTypes(race.GetCategory("cat1")), Has.Member(unitType1));
    1.28 +			Assert.That(race.GetUnitTypes(race.GetCategory("cat1")), Has.Member(unitType3));
    1.29 +		}
    1.30 +
    1.31  		private void TestFileValidationFailure(string filePath)
    1.32  		{
    1.33  			SetDefaultGameSystem();
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/API/Objects/Mock/MockContainedUnitType.cs	Sat Apr 14 19:57:32 2012 +0100
     2.3 @@ -0,0 +1,20 @@
     2.4 +// This file (MockContainedUnitType.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard
     2.5 +// 
     2.6 +// 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.
     2.7 +using System;
     2.8 +namespace IBBoard.WarFoundry.API.Objects.Mock
     2.9 +{
    2.10 +	public class MockContainedUnitType : MockUnitType
    2.11 +	{
    2.12 +		public MockContainedUnitType() : this("mockcontainedunittype", "Mock Contained Unit Type")
    2.13 +		{
    2.14 +			//Do nothing special
    2.15 +		}
    2.16 +
    2.17 +		public MockContainedUnitType(string id, string name) : base(id, name)
    2.18 +		{
    2.19 +			IsContainedOnly = true;
    2.20 +		}
    2.21 +	}
    2.22 +}
    2.23 +
     3.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Apr 14 16:58:20 2012 +0100
     3.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Apr 14 19:57:32 2012 +0100
     3.3 @@ -323,6 +323,12 @@
     3.4      <None Include="testdata\xml-race-factory\cyclic.racex">
     3.5        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     3.6      </None>
     3.7 +    <None Include="testdata\xml-race-factory\with-contained-only-unit.racex">
     3.8 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     3.9 +    </None>
    3.10 +    <None Include="testdata\xml-race-factory\with-mixed-contained-units.racex">
    3.11 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    3.12 +    </None>
    3.13    </ItemGroup>
    3.14    <ItemGroup>
    3.15      <Reference Include="System" />
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/testdata/xml-race-factory/with-contained-only-unit.racex	Sat Apr 14 19:57:32 2012 +0100
     4.3 @@ -0,0 +1,34 @@
     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="Empire" name="Empire" system="default">
     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 +			<contains>
    4.20 +				<containedUnit containedID="Empire2" />
    4.21 +			</contains>
    4.22 +		</unit>
    4.23 +		<unit id="Empire2" typeName="Minion" cat="cat1" points="0" containedOnly="true">
    4.24 +			<stats>
    4.25 +				<stat name="M">4</stat>
    4.26 +				<stat name="WS">2</stat>
    4.27 +				<stat name="BS">2</stat>
    4.28 +				<stat name="S">2</stat>
    4.29 +				<stat name="T">2</stat>
    4.30 +				<stat name="W">1</stat>
    4.31 +				<stat name="I">2</stat>
    4.32 +				<stat name="A">1</stat>
    4.33 +				<stat name="Ld">5</stat>
    4.34 +			</stats>
    4.35 +		</unit>
    4.36 +	</units>
    4.37 +</race>
    4.38 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/testdata/xml-race-factory/with-mixed-contained-units.racex	Sat Apr 14 19:57:32 2012 +0100
     5.3 @@ -0,0 +1,48 @@
     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="Empire" name="Empire" system="default">
     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 +			<contains>
    5.20 +				<containedUnit containedID="Empire2" />
    5.21 +				<containedUnit containedID="Empire3" />
    5.22 +			</contains>
    5.23 +		</unit>
    5.24 +		<unit id="Empire2" typeName="Minion" cat="cat1" points="0" containedOnly="true">
    5.25 +			<stats>
    5.26 +				<stat name="M">4</stat>
    5.27 +				<stat name="WS">2</stat>
    5.28 +				<stat name="BS">2</stat>
    5.29 +				<stat name="S">2</stat>
    5.30 +				<stat name="T">2</stat>
    5.31 +				<stat name="W">1</stat>
    5.32 +				<stat name="I">2</stat>
    5.33 +				<stat name="A">1</stat>
    5.34 +				<stat name="Ld">5</stat>
    5.35 +			</stats>
    5.36 +		</unit>
    5.37 +		<unit id="Empire3" typeName="Independent Minion" cat="cat1" points="0">
    5.38 +			<stats>
    5.39 +				<stat name="M">4</stat>
    5.40 +				<stat name="WS">2</stat>
    5.41 +				<stat name="BS">2</stat>
    5.42 +				<stat name="S">2</stat>
    5.43 +				<stat name="T">2</stat>
    5.44 +				<stat name="W">1</stat>
    5.45 +				<stat name="I">2</stat>
    5.46 +				<stat name="A">1</stat>
    5.47 +				<stat name="Ld">5</stat>
    5.48 +			</stats>
    5.49 +		</unit>
    5.50 +	</units>
    5.51 +</race>
    5.52 \ No newline at end of file