changeset 226:763ce93f1bfb

Re #359: Add "only contained" attribute to unit types * Add tests for "main units" methods not getting nested units
author IBBoard <dev@ibboard.co.uk>
date Sun, 15 Apr 2012 20:53:15 +0100
parents c6313a2c08a2
children d8cd6b259a9f
files API/Objects/ArmyCategoryTests.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 2 files changed, 78 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Objects/ArmyCategoryTests.cs	Sun Apr 15 20:53:15 2012 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +// This file (ArmyCategoryTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard
     1.5 +// 
     1.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.
     1.7 +using System;
     1.8 +using NUnit.Framework;
     1.9 +using IBBoard.WarFoundry.API.Objects.Mock;
    1.10 +using IBBoard.WarFoundry.API.Objects.Requirement;
    1.11 +using IBBoard.WarFoundry.API.Objects.Requirement.Mock;
    1.12 +using NUnit.Framework.SyntaxHelpers;
    1.13 +
    1.14 +
    1.15 +namespace IBBoard.WarFoundry.API.Objects
    1.16 +{
    1.17 +	[TestFixture()]
    1.18 +	public class ArmyCategoryTests
    1.19 +	{
    1.20 +		private MockRace mockRace;
    1.21 +		private UnitType unitType1;
    1.22 +		private IRequirement unitType1Requirement;
    1.23 +		private UnitType unitType2;
    1.24 +		private IRequirement unitType2Requirement;
    1.25 +		private UnitType unitType3;
    1.26 +		private IRequirement unitType3Requirement;
    1.27 +		private UnitType containedType;
    1.28 +
    1.29 +		[TestFixtureSetUp()]
    1.30 +		public void SetupRace()
    1.31 +		{
    1.32 +			mockRace = new MockRace();
    1.33 +			unitType1 = new MockUnitType("type1", "Unit Type 1");
    1.34 +			mockRace.AddUnitType(unitType1);
    1.35 +			unitType1Requirement = new PassingRequirement();
    1.36 +			unitType1.AddRequirement(unitType1Requirement);
    1.37 +			unitType2 = new MockUnitType("type2", "Unit Type 2");
    1.38 +			mockRace.AddUnitType(unitType2);
    1.39 +			unitType2Requirement = new FailingRequirement();
    1.40 +			unitType2.AddRequirement(unitType2Requirement);
    1.41 +			unitType3 = new MockUnitType("type3", "Unit Type 3");
    1.42 +			mockRace.AddUnitType(unitType3);
    1.43 +			unitType3Requirement = new NotApplicableRequirement();
    1.44 +			unitType3.AddRequirement(unitType3Requirement);
    1.45 +			containedType = new MockContainedUnitType();
    1.46 +			unitType1.AddContainedUnitType(containedType);
    1.47 +			mockRace.AddUnitType(containedType);
    1.48 +		}
    1.49 +
    1.50 +		[Test()]
    1.51 +		public void TestGetUnitsGetsAllUnitsIncludingContained()
    1.52 +		{
    1.53 +			Army army = new Army(mockRace, "Test", 1000);
    1.54 +			Unit unit1 = new Unit(unitType1, army.GetCategory(unitType1.MainCategory));
    1.55 +			army.AddUnit(unit1);
    1.56 +			Unit unit2 = new Unit(containedType, army.GetCategory(containedType.MainCategory));
    1.57 +			army.AddUnit(unit2);
    1.58 +			unit1.AddContainedUnit(unit2);
    1.59 +			ArmyCategory category = army.GetCategory(MockCategory.GetCategory());
    1.60 +			Assert.That(category.GetUnits(), Has.Length(2));
    1.61 +			Assert.That(category.GetUnits(), Has.Member(unit1));
    1.62 +			Assert.That(category.GetUnits(), Has.Member(unit2));
    1.63 +		}
    1.64 +
    1.65 +		[Test()]
    1.66 +		public void TestGetMainUnitsGetsNoContainedUnits()
    1.67 +		{
    1.68 +			Army army = new Army(mockRace, "Test", 1000);
    1.69 +			Unit unit1 = new Unit(unitType1, army.GetCategory(unitType1.MainCategory));
    1.70 +			army.AddUnit(unit1);
    1.71 +			Unit unit2 = new Unit(containedType, army.GetCategory(containedType.MainCategory));
    1.72 +			army.AddUnit(unit2);
    1.73 +			unit1.AddContainedUnit(unit2);
    1.74 +			ArmyCategory category = army.GetCategory(MockCategory.GetCategory());
    1.75 +			Assert.That(category.GetMainUnits(), Has.Length(1));
    1.76 +			Assert.That(category.GetMainUnits(), Has.Member(unit1));
    1.77 +		}
    1.78 +	}
    1.79 +}
    1.80 +
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Apr 14 19:57:32 2012 +0100
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Apr 15 20:53:15 2012 +0100
     2.3 @@ -122,6 +122,7 @@
     2.4      <Compile Include="API\Objects\Requirement\AbstractUnitTypeUnitRequirementTest.cs" />
     2.5      <Compile Include="API\Objects\Requirement\AbstractRaceUnitRequirementTest.cs" />
     2.6      <Compile Include="API\Objects\Mock\MockContainedUnitType.cs" />
     2.7 +    <Compile Include="API\Objects\ArmyCategoryTests.cs" />
     2.8    </ItemGroup>
     2.9    <ItemGroup>
    2.10      <None Include="app.config" />