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 wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sat Apr 14 16:58:20 2012 +0100
+++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sat Apr 14 19:57:32 2012 +0100
@@ -384,6 +384,30 @@
 			Assert.That(unitType.GetRequirements()[0], Is.InstanceOfType(typeof(UnitRequiresNoMoreThanNOfUnitTypeRequirement)));
 		}
 
+		[Test]
+		public void TestContainedUnitsAreLoaded()
+		{
+			SetDefaultGameSystem();
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-race-factory/with-contained-only-unit.racex"));
+			Assert.That(race.GetUnitType("Empire2"), Is.Not.Null);
+			UnitType unitType1 = race.GetUnitType("Empire1");
+			Assert.That(race.GetUnitTypes(race.GetCategory("cat1")), Has.Length(1));
+			Assert.That(race.GetUnitTypes(race.GetCategory("cat1")), Has.Member(unitType1));
+		}
+
+		[Test]
+		public void TestMixedContainedUnitsAreLoaded()
+		{
+			SetDefaultGameSystem();
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-race-factory/with-mixed-contained-units.racex"));
+			Assert.That(race.GetUnitType("Empire2"), Is.Not.Null);
+			UnitType unitType1 = race.GetUnitType("Empire1");
+			UnitType unitType3 = race.GetUnitType("Empire3");
+			Assert.That(race.GetUnitTypes(race.GetCategory("cat1")), Has.Length(2));
+			Assert.That(race.GetUnitTypes(race.GetCategory("cat1")), Has.Member(unitType1));
+			Assert.That(race.GetUnitTypes(race.GetCategory("cat1")), Has.Member(unitType3));
+		}
+
 		private void TestFileValidationFailure(string filePath)
 		{
 			SetDefaultGameSystem();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Mock/MockContainedUnitType.cs	Sat Apr 14 19:57:32 2012 +0100
@@ -0,0 +1,20 @@
+// This file (MockContainedUnitType.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 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 System;
+namespace IBBoard.WarFoundry.API.Objects.Mock
+{
+	public class MockContainedUnitType : MockUnitType
+	{
+		public MockContainedUnitType() : this("mockcontainedunittype", "Mock Contained Unit Type")
+		{
+			//Do nothing special
+		}
+
+		public MockContainedUnitType(string id, string name) : base(id, name)
+		{
+			IsContainedOnly = true;
+		}
+	}
+}
+
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Apr 14 16:58:20 2012 +0100
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Apr 14 19:57:32 2012 +0100
@@ -323,6 +323,12 @@
     <None Include="testdata\xml-race-factory\cyclic.racex">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="testdata\xml-race-factory\with-contained-only-unit.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\xml-race-factory\with-mixed-contained-units.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/xml-race-factory/with-contained-only-unit.racex	Sat Apr 14 19:57:32 2012 +0100
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="Empire" name="Empire" system="default">
+	<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>
+			<contains>
+				<containedUnit containedID="Empire2" />
+			</contains>
+		</unit>
+		<unit id="Empire2" typeName="Minion" cat="cat1" points="0" containedOnly="true">
+			<stats>
+				<stat name="M">4</stat>
+				<stat name="WS">2</stat>
+				<stat name="BS">2</stat>
+				<stat name="S">2</stat>
+				<stat name="T">2</stat>
+				<stat name="W">1</stat>
+				<stat name="I">2</stat>
+				<stat name="A">1</stat>
+				<stat name="Ld">5</stat>
+			</stats>
+		</unit>
+	</units>
+</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/xml-race-factory/with-mixed-contained-units.racex	Sat Apr 14 19:57:32 2012 +0100
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="Empire" name="Empire" system="default">
+	<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>
+			<contains>
+				<containedUnit containedID="Empire2" />
+				<containedUnit containedID="Empire3" />
+			</contains>
+		</unit>
+		<unit id="Empire2" typeName="Minion" cat="cat1" points="0" containedOnly="true">
+			<stats>
+				<stat name="M">4</stat>
+				<stat name="WS">2</stat>
+				<stat name="BS">2</stat>
+				<stat name="S">2</stat>
+				<stat name="T">2</stat>
+				<stat name="W">1</stat>
+				<stat name="I">2</stat>
+				<stat name="A">1</stat>
+				<stat name="Ld">5</stat>
+			</stats>
+		</unit>
+		<unit id="Empire3" typeName="Independent Minion" cat="cat1" points="0">
+			<stats>
+				<stat name="M">4</stat>
+				<stat name="WS">2</stat>
+				<stat name="BS">2</stat>
+				<stat name="S">2</stat>
+				<stat name="T">2</stat>
+				<stat name="W">1</stat>
+				<stat name="I">2</stat>
+				<stat name="A">1</stat>
+				<stat name="Ld">5</stat>
+			</stats>
+		</unit>
+	</units>
+</race>
\ No newline at end of file