changeset 162: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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Commands/EditArmyCommandTest.cs	Mon Aug 29 16:48:29 2011 +0100
     1.3 @@ -0,0 +1,121 @@
     1.4 +´╗┐using System;
     1.5 +using System.Collections.Generic;
     1.6 +using System.Text;
     1.7 +using NUnit.Framework;
     1.8 +using IBBoard.WarFoundry.API.Objects;
     1.9 +using IBBoard.WarFoundry.API.Objects.Mock;
    1.10 +using NUnit.Framework.SyntaxHelpers;
    1.11 +
    1.12 +namespace IBBoard.WarFoundry.API.Commands
    1.13 +{
    1.14 +	[TestFixture]
    1.15 +	public class EditArmyCommandTest
    1.16 +	{
    1.17 +		[Test]
    1.18 +		public void TestChangingNameOnlyChangesName()
    1.19 +		{
    1.20 +			Army army = CreateArmy();
    1.21 +			EditArmyCommand cmd = new EditArmyCommand(army);
    1.22 +			string newName = "Something New";
    1.23 +			int maxSize = army.MaxPoints;
    1.24 +			cmd.NewName = newName;
    1.25 +			cmd.Execute();
    1.26 +			Assert.That(army.Name, Is.EqualTo(newName));
    1.27 +			Assert.That(army.MaxPoints, Is.EqualTo(maxSize));
    1.28 +		}
    1.29 +
    1.30 +		[Test]
    1.31 +		public void TestUndoNameChangeGivesOldName()
    1.32 +		{
    1.33 +			Army army = CreateArmy();
    1.34 +			EditArmyCommand cmd = new EditArmyCommand(army);
    1.35 +			string oldName = army.Name;
    1.36 +			cmd.NewName = "Something New";
    1.37 +			cmd.Execute();
    1.38 +			cmd.Undo();
    1.39 +			Assert.That(army.Name, Is.EqualTo(oldName));
    1.40 +		}
    1.41 +
    1.42 +		[Test]
    1.43 +		public void TestChangingSizeOnlyChangesSize()
    1.44 +		{
    1.45 +			Army army = CreateArmy();
    1.46 +			EditArmyCommand cmd = new EditArmyCommand(army);
    1.47 +			string oldName = army.Name;
    1.48 +			int maxSize = 1337;
    1.49 +			cmd.NewSize = maxSize;
    1.50 +			cmd.Execute();
    1.51 +			Assert.That(army.MaxPoints, Is.EqualTo(maxSize));
    1.52 +			Assert.That(army.Name, Is.EqualTo(oldName));
    1.53 +		}
    1.54 +
    1.55 +		[Test]
    1.56 +		public void TestUndoSizeChangeGivesOldSize()
    1.57 +		{
    1.58 +			Army army = CreateArmy();
    1.59 +			EditArmyCommand cmd = new EditArmyCommand(army);
    1.60 +			int oldSize = army.MaxPoints;
    1.61 +			cmd.NewSize = 1337;
    1.62 +			cmd.Execute();
    1.63 +			cmd.Undo();
    1.64 +			Assert.That(army.MaxPoints, Is.EqualTo(oldSize));
    1.65 +		}
    1.66 +
    1.67 +		[Test]
    1.68 +		public void TestChangingBothChangesBoth()
    1.69 +		{
    1.70 +			Army army = CreateArmy();
    1.71 +			EditArmyCommand cmd = new EditArmyCommand(army);
    1.72 +			string newName = "Something New";
    1.73 +			cmd.NewName = newName;
    1.74 +			int maxSize = 1337;
    1.75 +			cmd.NewSize = maxSize;
    1.76 +			cmd.Execute();
    1.77 +			Assert.That(army.MaxPoints, Is.EqualTo(maxSize));
    1.78 +			Assert.That(army.Name, Is.EqualTo(newName));
    1.79 +		}
    1.80 +
    1.81 +		[Test]
    1.82 +		public void TestUndoChangeBothGivesOldValues()
    1.83 +		{
    1.84 +			Army army = CreateArmy();
    1.85 +			EditArmyCommand cmd = new EditArmyCommand(army);
    1.86 +			int oldSize = army.MaxPoints;
    1.87 +			string oldName = army.Name;
    1.88 +			cmd.NewName = "Something New";
    1.89 +			cmd.NewSize = 1337;
    1.90 +			cmd.Execute();
    1.91 +			cmd.Undo();
    1.92 +			Assert.That(army.MaxPoints, Is.EqualTo(oldSize));
    1.93 +			Assert.That(army.Name, Is.EqualTo(oldName));
    1.94 +		}
    1.95 +
    1.96 +		[Test]
    1.97 +		public void TestCanExecuteRequiresArmyAndAtLeastOneValue()
    1.98 +		{
    1.99 +			EditArmyCommand cmd = new EditArmyCommand(null);
   1.100 +			Assert.That(cmd.CanExecute(), Is.False);
   1.101 +			Army army = CreateArmy();
   1.102 +			cmd = new EditArmyCommand(army);
   1.103 +			Assert.That(cmd.CanExecute(), Is.False);
   1.104 +			cmd.NewName = "NonNull";
   1.105 +			Assert.That(cmd.CanExecute(), Is.True);
   1.106 +			cmd.NewName = null;
   1.107 +			Assert.That(cmd.CanExecute(), Is.False);
   1.108 +			cmd.NewSize = 1000;
   1.109 +			Assert.That(cmd.CanExecute(), Is.True);
   1.110 +			cmd.NewSize = 0;
   1.111 +			Assert.That(cmd.CanExecute(), Is.False);
   1.112 +			cmd.NewSize = -1;
   1.113 +			Assert.That(cmd.CanExecute(), Is.False);
   1.114 +			cmd.NewSize = 1;
   1.115 +			Assert.That(cmd.CanExecute(), Is.True);
   1.116 +		}
   1.117 +
   1.118 +
   1.119 +		static Army CreateArmy()
   1.120 +		{
   1.121 +			return new Army(new MockRace(), "default name", 1000);
   1.122 +		}
   1.123 +	}
   1.124 +}
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Aug 21 20:40:41 2011 +0100
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Mon Aug 29 16:48:29 2011 +0100
     2.3 @@ -106,6 +106,7 @@
     2.4      <Compile Include="API\MockRequirementFactory.cs" />
     2.5      <Compile Include="API\Factories\Requirement\Mock\MockRequirement.cs" />
     2.6      <Compile Include="API\Savers\Xml\WarFoundryXmlFileSaverTests.cs" />
     2.7 +    <Compile Include="API\Commands\EditArmyCommandTest.cs" />
     2.8    </ItemGroup>
     2.9    <ItemGroup>
    2.10      <None Include="app.config" />
    2.11 @@ -299,6 +300,7 @@
    2.12      </None>
    2.13    </ItemGroup>
    2.14    <ItemGroup>
    2.15 +    <Reference Include="System" />
    2.16      <Reference Include="System.Xml" />
    2.17      <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
    2.18        <SpecificVersion>False</SpecificVersion>
    2.19 @@ -364,7 +366,5 @@
    2.20        <Install>true</Install>
    2.21      </BootstrapperPackage>
    2.22    </ItemGroup>
    2.23 -  <ItemGroup>
    2.24 -    <Folder Include="API\Savers\Xml\" />
    2.25 -  </ItemGroup>
    2.26 +  <ItemGroup />
    2.27  </Project>
    2.28 \ No newline at end of file