changeset 227:d8cd6b259a9f

Re #359: Add "only contained" attribute to unit types * Test to make sure sub-units are removed from the army
author IBBoard <dev@ibboard.co.uk>
date Mon, 16 Apr 2012 20:45:45 +0100
parents 763ce93f1bfb
children 7c21ca1482cb
files API/Commands/RemoveUnitCommandTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 2 files changed, 52 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Commands/RemoveUnitCommandTest.cs	Mon Apr 16 20:45:45 2012 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +// This file (RemoveUnitCommandTest.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;
    1.10 +using NUnit.Framework.SyntaxHelpers;
    1.11 +using IBBoard.WarFoundry.API.Objects.Mock;
    1.12 +
    1.13 +
    1.14 +namespace IBBoard.WarFoundry.API.Commands
    1.15 +{
    1.16 +	[TestFixture()]
    1.17 +	public class RemoveUnitCommandTest
    1.18 +	{
    1.19 +		private MockRace mockRace;
    1.20 +		private UnitType unitType1;
    1.21 +		private UnitType containedType;
    1.22 +		
    1.23 +		[TestFixtureSetUp()]
    1.24 +		public void SetupRace()
    1.25 +		{
    1.26 +			mockRace = new MockRace();
    1.27 +			unitType1 = new MockUnitType("type1", "Unit Type 1");
    1.28 +			mockRace.AddUnitType(unitType1);
    1.29 +			containedType = new MockContainedUnitType();
    1.30 +			unitType1.AddContainedUnitType(containedType);
    1.31 +			mockRace.AddUnitType(containedType);
    1.32 +		}
    1.33 +
    1.34 +		[Test()]
    1.35 +		public void TestRemovingUnitWithContainedUnits()
    1.36 +		{
    1.37 +			Army army = new Army(mockRace, "Test", 1000);
    1.38 +			Unit unit1 = new Unit(unitType1, army.GetCategory(unitType1.MainCategory));
    1.39 +			army.AddUnit(unit1);
    1.40 +			Unit unit2 = new Unit(containedType, army.GetCategory(containedType.MainCategory));
    1.41 +			army.AddUnit(unit2);
    1.42 +			unit1.AddContainedUnit(unit2);
    1.43 +			Assert.That(army.GetUnits(), Has.Length(2));
    1.44 +			RemoveUnitCommand cmd = new RemoveUnitCommand(unit1);
    1.45 +			cmd.Execute();
    1.46 +			Assert.That(army.GetUnits(), Has.Length(0));
    1.47 +			cmd.Undo();			
    1.48 +			Assert.That(army.GetUnits(), Has.Length(2));
    1.49 +			cmd.Redo();
    1.50 +			Assert.That(army.GetUnits(), Has.Length(0));
    1.51 +		}
    1.52 +	}
    1.53 +}
    1.54 +
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Apr 15 20:53:15 2012 +0100
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Mon Apr 16 20:45:45 2012 +0100
     2.3 @@ -123,6 +123,7 @@
     2.4      <Compile Include="API\Objects\Requirement\AbstractRaceUnitRequirementTest.cs" />
     2.5      <Compile Include="API\Objects\Mock\MockContainedUnitType.cs" />
     2.6      <Compile Include="API\Objects\ArmyCategoryTests.cs" />
     2.7 +    <Compile Include="API\Commands\RemoveUnitCommandTest.cs" />
     2.8    </ItemGroup>
     2.9    <ItemGroup>
    2.10      <None Include="app.config" />