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 wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Commands/RemoveUnitCommandTest.cs	Mon Apr 16 20:45:45 2012 +0100
@@ -0,0 +1,51 @@
+// This file (RemoveUnitCommandTest.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;
+using NUnit.Framework;
+using IBBoard.WarFoundry.API.Objects;
+using NUnit.Framework.SyntaxHelpers;
+using IBBoard.WarFoundry.API.Objects.Mock;
+
+
+namespace IBBoard.WarFoundry.API.Commands
+{
+	[TestFixture()]
+	public class RemoveUnitCommandTest
+	{
+		private MockRace mockRace;
+		private UnitType unitType1;
+		private UnitType containedType;
+		
+		[TestFixtureSetUp()]
+		public void SetupRace()
+		{
+			mockRace = new MockRace();
+			unitType1 = new MockUnitType("type1", "Unit Type 1");
+			mockRace.AddUnitType(unitType1);
+			containedType = new MockContainedUnitType();
+			unitType1.AddContainedUnitType(containedType);
+			mockRace.AddUnitType(containedType);
+		}
+
+		[Test()]
+		public void TestRemovingUnitWithContainedUnits()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			Unit unit1 = new Unit(unitType1, army.GetCategory(unitType1.MainCategory));
+			army.AddUnit(unit1);
+			Unit unit2 = new Unit(containedType, army.GetCategory(containedType.MainCategory));
+			army.AddUnit(unit2);
+			unit1.AddContainedUnit(unit2);
+			Assert.That(army.GetUnits(), Has.Length(2));
+			RemoveUnitCommand cmd = new RemoveUnitCommand(unit1);
+			cmd.Execute();
+			Assert.That(army.GetUnits(), Has.Length(0));
+			cmd.Undo();			
+			Assert.That(army.GetUnits(), Has.Length(2));
+			cmd.Redo();
+			Assert.That(army.GetUnits(), Has.Length(0));
+		}
+	}
+}
+
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Apr 15 20:53:15 2012 +0100
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Mon Apr 16 20:45:45 2012 +0100
@@ -123,6 +123,7 @@
     <Compile Include="API\Objects\Requirement\AbstractRaceUnitRequirementTest.cs" />
     <Compile Include="API\Objects\Mock\MockContainedUnitType.cs" />
     <Compile Include="API\Objects\ArmyCategoryTests.cs" />
+    <Compile Include="API\Commands\RemoveUnitCommandTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />