Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
comparison API/Commands/EditArmyCommandTest.cs @ 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 | |
children | e173c5512067 |
comparison
equal
deleted
inserted
replaced
161:c28ff466d009 | 162:b0b41bf8ad68 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.Text; | |
4 using NUnit.Framework; | |
5 using IBBoard.WarFoundry.API.Objects; | |
6 using IBBoard.WarFoundry.API.Objects.Mock; | |
7 using NUnit.Framework.SyntaxHelpers; | |
8 | |
9 namespace IBBoard.WarFoundry.API.Commands | |
10 { | |
11 [TestFixture] | |
12 public class EditArmyCommandTest | |
13 { | |
14 [Test] | |
15 public void TestChangingNameOnlyChangesName() | |
16 { | |
17 Army army = CreateArmy(); | |
18 EditArmyCommand cmd = new EditArmyCommand(army); | |
19 string newName = "Something New"; | |
20 int maxSize = army.MaxPoints; | |
21 cmd.NewName = newName; | |
22 cmd.Execute(); | |
23 Assert.That(army.Name, Is.EqualTo(newName)); | |
24 Assert.That(army.MaxPoints, Is.EqualTo(maxSize)); | |
25 } | |
26 | |
27 [Test] | |
28 public void TestUndoNameChangeGivesOldName() | |
29 { | |
30 Army army = CreateArmy(); | |
31 EditArmyCommand cmd = new EditArmyCommand(army); | |
32 string oldName = army.Name; | |
33 cmd.NewName = "Something New"; | |
34 cmd.Execute(); | |
35 cmd.Undo(); | |
36 Assert.That(army.Name, Is.EqualTo(oldName)); | |
37 } | |
38 | |
39 [Test] | |
40 public void TestChangingSizeOnlyChangesSize() | |
41 { | |
42 Army army = CreateArmy(); | |
43 EditArmyCommand cmd = new EditArmyCommand(army); | |
44 string oldName = army.Name; | |
45 int maxSize = 1337; | |
46 cmd.NewSize = maxSize; | |
47 cmd.Execute(); | |
48 Assert.That(army.MaxPoints, Is.EqualTo(maxSize)); | |
49 Assert.That(army.Name, Is.EqualTo(oldName)); | |
50 } | |
51 | |
52 [Test] | |
53 public void TestUndoSizeChangeGivesOldSize() | |
54 { | |
55 Army army = CreateArmy(); | |
56 EditArmyCommand cmd = new EditArmyCommand(army); | |
57 int oldSize = army.MaxPoints; | |
58 cmd.NewSize = 1337; | |
59 cmd.Execute(); | |
60 cmd.Undo(); | |
61 Assert.That(army.MaxPoints, Is.EqualTo(oldSize)); | |
62 } | |
63 | |
64 [Test] | |
65 public void TestChangingBothChangesBoth() | |
66 { | |
67 Army army = CreateArmy(); | |
68 EditArmyCommand cmd = new EditArmyCommand(army); | |
69 string newName = "Something New"; | |
70 cmd.NewName = newName; | |
71 int maxSize = 1337; | |
72 cmd.NewSize = maxSize; | |
73 cmd.Execute(); | |
74 Assert.That(army.MaxPoints, Is.EqualTo(maxSize)); | |
75 Assert.That(army.Name, Is.EqualTo(newName)); | |
76 } | |
77 | |
78 [Test] | |
79 public void TestUndoChangeBothGivesOldValues() | |
80 { | |
81 Army army = CreateArmy(); | |
82 EditArmyCommand cmd = new EditArmyCommand(army); | |
83 int oldSize = army.MaxPoints; | |
84 string oldName = army.Name; | |
85 cmd.NewName = "Something New"; | |
86 cmd.NewSize = 1337; | |
87 cmd.Execute(); | |
88 cmd.Undo(); | |
89 Assert.That(army.MaxPoints, Is.EqualTo(oldSize)); | |
90 Assert.That(army.Name, Is.EqualTo(oldName)); | |
91 } | |
92 | |
93 [Test] | |
94 public void TestCanExecuteRequiresArmyAndAtLeastOneValue() | |
95 { | |
96 EditArmyCommand cmd = new EditArmyCommand(null); | |
97 Assert.That(cmd.CanExecute(), Is.False); | |
98 Army army = CreateArmy(); | |
99 cmd = new EditArmyCommand(army); | |
100 Assert.That(cmd.CanExecute(), Is.False); | |
101 cmd.NewName = "NonNull"; | |
102 Assert.That(cmd.CanExecute(), Is.True); | |
103 cmd.NewName = null; | |
104 Assert.That(cmd.CanExecute(), Is.False); | |
105 cmd.NewSize = 1000; | |
106 Assert.That(cmd.CanExecute(), Is.True); | |
107 cmd.NewSize = 0; | |
108 Assert.That(cmd.CanExecute(), Is.False); | |
109 cmd.NewSize = -1; | |
110 Assert.That(cmd.CanExecute(), Is.False); | |
111 cmd.NewSize = 1; | |
112 Assert.That(cmd.CanExecute(), Is.True); | |
113 } | |
114 | |
115 | |
116 static Army CreateArmy() | |
117 { | |
118 return new Army(new MockRace(), "default name", 1000); | |
119 } | |
120 } | |
121 } |