# HG changeset patch # User IBBoard # Date 1334429852 -3600 # Node ID c6313a2c08a2367f88ab025b0d670e3ce90e443c # Parent 49480e1a8f90b4b291b9f153c40c40a592b98985 Re #359: Add "only contained" attribute to unit types * Add missing class * Add tests for loading files and test data diff -r 49480e1a8f90 -r c6313a2c08a2 API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs --- 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(); diff -r 49480e1a8f90 -r c6313a2c08a2 API/Objects/Mock/MockContainedUnitType.cs --- /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; + } + } +} + diff -r 49480e1a8f90 -r c6313a2c08a2 IBBoard.WarFoundry.API.Tests.csproj --- 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 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + diff -r 49480e1a8f90 -r c6313a2c08a2 testdata/xml-race-factory/with-contained-only-unit.racex --- /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 @@ + + + + + + 4 + 6 + 6 + 4 + 4 + 3 + 6 + 4 + 9 + + + + + + + + 4 + 2 + 2 + 2 + 2 + 1 + 2 + 1 + 5 + + + + \ No newline at end of file diff -r 49480e1a8f90 -r c6313a2c08a2 testdata/xml-race-factory/with-mixed-contained-units.racex --- /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 @@ + + + + + + 4 + 6 + 6 + 4 + 4 + 3 + 6 + 4 + 9 + + + + + + + + + 4 + 2 + 2 + 2 + 2 + 1 + 2 + 1 + 5 + + + + + 4 + 2 + 2 + 2 + 2 + 1 + 2 + 1 + 5 + + + + \ No newline at end of file