Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
view API/Commands/EditArmyCommandTest.cs @ 172:c026c02583ca
* Remove MockArmy.GetMockArmy as it only causes problems in unit tests
* Remove MockArmyCategory as MockArmy change would make it do nothing special
* Close streams as well as files to fix Windows unit test errors
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Sep 2011 11:46:20 +0100 |
parents | b0b41bf8ad68 |
children | e173c5512067 |
line wrap: on
line source
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); } } }