Mercurial > repos > IBBoard.WarFoundry.API.Tests
annotate API/Commands/EditArmyCommandTest.cs @ 211:bc782a0d47bf
Re #379: Fix validation of requirements to check for unit
* Finish off validation tests for "N units for M Units" requirement
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 25 Feb 2012 17:02:38 +0000 |
parents | b0b41bf8ad68 |
children |
rev | line source |
---|---|
163
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 using System; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 using System.Collections.Generic; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 using System.Text; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using NUnit.Framework; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using IBBoard.WarFoundry.API.Objects; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using IBBoard.WarFoundry.API.Objects.Mock; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using NUnit.Framework.SyntaxHelpers; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 namespace IBBoard.WarFoundry.API.Commands |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 { |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 [TestFixture] |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 public class EditArmyCommandTest |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 { |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 [Test] |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 public void TestChangingNameOnlyChangesName() |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 { |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 Army army = CreateArmy(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 EditArmyCommand cmd = new EditArmyCommand(army); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 string newName = "Something New"; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 int maxSize = army.MaxPoints; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 cmd.NewName = newName; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 cmd.Execute(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 Assert.That(army.Name, Is.EqualTo(newName)); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 Assert.That(army.MaxPoints, Is.EqualTo(maxSize)); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 } |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 [Test] |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 public void TestUndoNameChangeGivesOldName() |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 { |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 Army army = CreateArmy(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 EditArmyCommand cmd = new EditArmyCommand(army); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 string oldName = army.Name; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 cmd.NewName = "Something New"; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 cmd.Execute(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 cmd.Undo(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 Assert.That(army.Name, Is.EqualTo(oldName)); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 } |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 [Test] |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 public void TestChangingSizeOnlyChangesSize() |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 { |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 Army army = CreateArmy(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 EditArmyCommand cmd = new EditArmyCommand(army); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 string oldName = army.Name; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 int maxSize = 1337; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 cmd.NewSize = maxSize; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 cmd.Execute(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 Assert.That(army.MaxPoints, Is.EqualTo(maxSize)); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 Assert.That(army.Name, Is.EqualTo(oldName)); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 } |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 [Test] |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 public void TestUndoSizeChangeGivesOldSize() |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 { |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 Army army = CreateArmy(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 EditArmyCommand cmd = new EditArmyCommand(army); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 int oldSize = army.MaxPoints; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 cmd.NewSize = 1337; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
59 cmd.Execute(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
60 cmd.Undo(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
61 Assert.That(army.MaxPoints, Is.EqualTo(oldSize)); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
62 } |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
64 [Test] |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
65 public void TestChangingBothChangesBoth() |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
66 { |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 Army army = CreateArmy(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
68 EditArmyCommand cmd = new EditArmyCommand(army); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
69 string newName = "Something New"; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
70 cmd.NewName = newName; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
71 int maxSize = 1337; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 cmd.NewSize = maxSize; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
73 cmd.Execute(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 Assert.That(army.MaxPoints, Is.EqualTo(maxSize)); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
75 Assert.That(army.Name, Is.EqualTo(newName)); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
76 } |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
77 |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
78 [Test] |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
79 public void TestUndoChangeBothGivesOldValues() |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
80 { |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
81 Army army = CreateArmy(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
82 EditArmyCommand cmd = new EditArmyCommand(army); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
83 int oldSize = army.MaxPoints; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
84 string oldName = army.Name; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
85 cmd.NewName = "Something New"; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
86 cmd.NewSize = 1337; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
87 cmd.Execute(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
88 cmd.Undo(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
89 Assert.That(army.MaxPoints, Is.EqualTo(oldSize)); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
90 Assert.That(army.Name, Is.EqualTo(oldName)); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
91 } |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
92 |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
93 [Test] |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
94 public void TestCanExecuteRequiresArmyAndAtLeastOneValue() |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
95 { |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
96 EditArmyCommand cmd = new EditArmyCommand(null); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
97 Assert.That(cmd.CanExecute(), Is.False); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
98 Army army = CreateArmy(); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
99 cmd = new EditArmyCommand(army); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
100 Assert.That(cmd.CanExecute(), Is.False); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
101 cmd.NewName = "NonNull"; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
102 Assert.That(cmd.CanExecute(), Is.True); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
103 cmd.NewName = null; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
104 Assert.That(cmd.CanExecute(), Is.False); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
105 cmd.NewSize = 1000; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
106 Assert.That(cmd.CanExecute(), Is.True); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
107 cmd.NewSize = 0; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
108 Assert.That(cmd.CanExecute(), Is.False); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
109 cmd.NewSize = -1; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
110 Assert.That(cmd.CanExecute(), Is.False); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
111 cmd.NewSize = 1; |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
112 Assert.That(cmd.CanExecute(), Is.True); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
113 } |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
114 |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
115 |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
116 static Army CreateArmy() |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
117 { |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
118 return new Army(new MockRace(), "default name", 1000); |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
119 } |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
120 } |
b0b41bf8ad68
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
121 } |