annotate SilverlightValidation/SilverlightValidation.Tests/ViewModels/UserViewModel_Commands.cs @ 120:48c389520e5d

initial commit
author stevenh7776
date Thu, 31 May 2012 14:12:43 +0100
parents 11994ccdc50b
children
rev   line source
109
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
1 using GalaSoft.MvvmLight.Messaging;
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
2 using Microsoft.VisualStudio.TestTools.UnitTesting;
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
3 using SilverlightValidation.Messages;
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
4 using SilverlightValidation.Tests.Helpers;
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
5
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
6 namespace SilverlightValidation.Tests.ViewModels
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
7 {
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
8 [TestClass]
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
9 public class UserViewModel_Commands
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
10 {
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
11 [TestMethod]
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
12 public void WhenNewViewModel_ThenOkCommandIsExecutable()
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
13 {
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
14 // arrange
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
15 var vm = Helper.CreateDefaultUserViewModel();
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
16
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
17 // assert
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
18 Assert.IsTrue(vm.OkCommand.CanExecute(null));
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
19 }
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
20
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
21 [TestMethod]
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
22 public void WhenNewViewModel_WithOkExecuted_ThenShouldNotRaiseEvent()
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
23 {
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
24 // arrange
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
25 var vm = Helper.CreateDefaultUserViewModel();
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
26 bool hasMessage = false;
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
27 Messenger.Default.Register<UserViewResponseMessage>(this, message => { hasMessage = true; });
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
28
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
29 // act
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
30 vm.OkCommand.Execute(null);
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
31
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
32 // assert
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
33 Assert.IsFalse(hasMessage);
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
34 }
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
35
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
36 [TestMethod]
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
37 public void WhenNewViewModel_WithOkExecutedAndUsernameUpdatedWithInvalidData_ThenShouldNotRaiseEvent()
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
38 {
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
39 // arrange
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
40 var vm = Helper.CreateDefaultUserViewModel();
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
41 bool hasMessage = false;
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
42 Messenger.Default.Register<UserViewResponseMessage>(this, message => { hasMessage = true; });
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
43
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
44 // act
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
45 var shortData = "a";
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
46 vm.Username = shortData;
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
47 vm.OkCommand.Execute(null);
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
48
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
49 // assert
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
50 Assert.IsFalse(hasMessage);
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
51 }
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
52
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
53 [TestMethod]
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
54 public void WhenNewViewModel_WithOkExecutedAndUsernameUpdated_ThenShouldRaiseEvent()
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
55 {
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
56 // arrange
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
57 var vm = Helper.CreateValidUserViewModel();
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
58 bool hasMessage = false;
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
59 Messenger.Default.Register<UserViewResponseMessage>(this, message => { hasMessage = true; });
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
60
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
61 // act
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
62 vm.Username = "updated";
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
63 vm.OkCommand.Execute(null);
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
64
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
65 // assert
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
66 Assert.IsTrue(vm.IsChanged);
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
67 Assert.IsTrue(hasMessage);
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
68 }
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
69
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
70 [TestMethod]
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
71 public void WhenNewViewModel_ThenCancelCommandIsExecutable()
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
72 {
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
73 // arrange
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
74 var vm = Helper.CreateDefaultUserViewModel();
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
75
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
76 // assert
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
77 Assert.IsTrue(vm.CancelCommand.CanExecute(null));
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
78 }
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
79
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
80 [TestMethod]
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
81 public void WhenNewViewModel_WithCancelExecuted_ThenShouldRaiseEvent()
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
82 {
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
83 // arrange
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
84 var vm = Helper.CreateDefaultUserViewModel();
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
85 bool hasMessage = false;
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
86 Messenger.Default.Register<UserViewResponseMessage>(this, message => { hasMessage = true; });
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
87
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
88 // act
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
89 vm.CancelCommand.Execute(null);
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
90
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
91 // assert
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
92 Assert.IsTrue(hasMessage);
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
93 }
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
94
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
95 }
11994ccdc50b First wave of tests complete
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
96 }