changeset 163:b0b41bf8ad68 Ticket341-DefaultArmySize

Re #101: Make army names and sizes modifiable after creation * Add unit tests for new command
author IBBoard <dev@ibboard.co.uk>
date Mon, 29 Aug 2011 16:48:29 +0100
parents c28ff466d009
children 7b90f41f27e5
files API/Commands/EditArmyCommandTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 2 files changed, 124 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Commands/EditArmyCommandTest.cs	Mon Aug 29 16:48:29 2011 +0100
@@ -0,0 +1,121 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NUnit.Framework;
+using IBBoard.WarFoundry.API.Objects;
+using IBBoard.WarFoundry.API.Objects.Mock;
+using NUnit.Framework.SyntaxHelpers;
+
+namespace IBBoard.WarFoundry.API.Commands
+{
+	[TestFixture]
+	public class EditArmyCommandTest
+	{
+		[Test]
+		public void TestChangingNameOnlyChangesName()
+		{
+			Army army = CreateArmy();
+			EditArmyCommand cmd = new EditArmyCommand(army);
+			string newName = "Something New";
+			int maxSize = army.MaxPoints;
+			cmd.NewName = newName;
+			cmd.Execute();
+			Assert.That(army.Name, Is.EqualTo(newName));
+			Assert.That(army.MaxPoints, Is.EqualTo(maxSize));
+		}
+
+		[Test]
+		public void TestUndoNameChangeGivesOldName()
+		{
+			Army army = CreateArmy();
+			EditArmyCommand cmd = new EditArmyCommand(army);
+			string oldName = army.Name;
+			cmd.NewName = "Something New";
+			cmd.Execute();
+			cmd.Undo();
+			Assert.That(army.Name, Is.EqualTo(oldName));
+		}
+
+		[Test]
+		public void TestChangingSizeOnlyChangesSize()
+		{
+			Army army = CreateArmy();
+			EditArmyCommand cmd = new EditArmyCommand(army);
+			string oldName = army.Name;
+			int maxSize = 1337;
+			cmd.NewSize = maxSize;
+			cmd.Execute();
+			Assert.That(army.MaxPoints, Is.EqualTo(maxSize));
+			Assert.That(army.Name, Is.EqualTo(oldName));
+		}
+
+		[Test]
+		public void TestUndoSizeChangeGivesOldSize()
+		{
+			Army army = CreateArmy();
+			EditArmyCommand cmd = new EditArmyCommand(army);
+			int oldSize = army.MaxPoints;
+			cmd.NewSize = 1337;
+			cmd.Execute();
+			cmd.Undo();
+			Assert.That(army.MaxPoints, Is.EqualTo(oldSize));
+		}
+
+		[Test]
+		public void TestChangingBothChangesBoth()
+		{
+			Army army = CreateArmy();
+			EditArmyCommand cmd = new EditArmyCommand(army);
+			string newName = "Something New";
+			cmd.NewName = newName;
+			int maxSize = 1337;
+			cmd.NewSize = maxSize;
+			cmd.Execute();
+			Assert.That(army.MaxPoints, Is.EqualTo(maxSize));
+			Assert.That(army.Name, Is.EqualTo(newName));
+		}
+
+		[Test]
+		public void TestUndoChangeBothGivesOldValues()
+		{
+			Army army = CreateArmy();
+			EditArmyCommand cmd = new EditArmyCommand(army);
+			int oldSize = army.MaxPoints;
+			string oldName = army.Name;
+			cmd.NewName = "Something New";
+			cmd.NewSize = 1337;
+			cmd.Execute();
+			cmd.Undo();
+			Assert.That(army.MaxPoints, Is.EqualTo(oldSize));
+			Assert.That(army.Name, Is.EqualTo(oldName));
+		}
+
+		[Test]
+		public void TestCanExecuteRequiresArmyAndAtLeastOneValue()
+		{
+			EditArmyCommand cmd = new EditArmyCommand(null);
+			Assert.That(cmd.CanExecute(), Is.False);
+			Army army = CreateArmy();
+			cmd = new EditArmyCommand(army);
+			Assert.That(cmd.CanExecute(), Is.False);
+			cmd.NewName = "NonNull";
+			Assert.That(cmd.CanExecute(), Is.True);
+			cmd.NewName = null;
+			Assert.That(cmd.CanExecute(), Is.False);
+			cmd.NewSize = 1000;
+			Assert.That(cmd.CanExecute(), Is.True);
+			cmd.NewSize = 0;
+			Assert.That(cmd.CanExecute(), Is.False);
+			cmd.NewSize = -1;
+			Assert.That(cmd.CanExecute(), Is.False);
+			cmd.NewSize = 1;
+			Assert.That(cmd.CanExecute(), Is.True);
+		}
+
+
+		static Army CreateArmy()
+		{
+			return new Army(new MockRace(), "default name", 1000);
+		}
+	}
+}
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Aug 21 20:40:41 2011 +0100
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Mon Aug 29 16:48:29 2011 +0100
@@ -106,6 +106,7 @@
     <Compile Include="API\MockRequirementFactory.cs" />
     <Compile Include="API\Factories\Requirement\Mock\MockRequirement.cs" />
     <Compile Include="API\Savers\Xml\WarFoundryXmlFileSaverTests.cs" />
+    <Compile Include="API\Commands\EditArmyCommandTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
@@ -299,6 +300,7 @@
     </None>
   </ItemGroup>
   <ItemGroup>
+    <Reference Include="System" />
     <Reference Include="System.Xml" />
     <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
       <SpecificVersion>False</SpecificVersion>
@@ -364,7 +366,5 @@
       <Install>true</Install>
     </BootstrapperPackage>
   </ItemGroup>
-  <ItemGroup>
-    <Folder Include="API\Savers\Xml\" />
-  </ItemGroup>
+  <ItemGroup />
 </Project>
\ No newline at end of file