changeset 106:62477c2e8837

Command tests
author stevenhollidge <stevenhollidge@hotmail.com>
date Sun, 06 May 2012 13:00:46 +0100
parents 1c9fc59af186
children 572886951353
files SilverlightValidation/SilverlightValidation.PL/ViewModels/UserViewModel.cs SilverlightValidation/SilverlightValidation.Tests/ViewModels/UserViewModelFixture.cs
diffstat 2 files changed, 39 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/SilverlightValidation/SilverlightValidation.PL/ViewModels/UserViewModel.cs	Sun May 06 12:32:35 2012 +0100
+++ b/SilverlightValidation/SilverlightValidation.PL/ViewModels/UserViewModel.cs	Sun May 06 13:00:46 2012 +0100
@@ -168,8 +168,7 @@
             if (IsChanged && !HasErrors)
             {
                 // save here
-                Messenger.Default.Send<UserViewResponseMessage>(
-                    new UserViewResponseMessage() { UserViewModel = this });
+                Messenger.Default.Send(new UserViewResponseMessage() { UserViewModel = this });
             }
         }
 
@@ -184,8 +183,7 @@
 
         private void CancelCommandExecute(object obj)
         {
-            Messenger.Default.Send<UserViewResponseMessage>(
-                new UserViewResponseMessage() { UserViewModel = null });
+            Messenger.Default.Send(new UserViewResponseMessage() { UserViewModel = null });
         }
         
         #endregion
--- a/SilverlightValidation/SilverlightValidation.Tests/ViewModels/UserViewModelFixture.cs	Sun May 06 12:32:35 2012 +0100
+++ b/SilverlightValidation/SilverlightValidation.Tests/ViewModels/UserViewModelFixture.cs	Sun May 06 13:00:46 2012 +0100
@@ -171,6 +171,43 @@
 
         #endregion
 
+        #region Commands
+
+        [Test]
+        public void WhenNewViewModel_ThenOkCommandIsExecutable()
+        {
+            // arrange
+            var vm = CreateDefaultUserViewModel();
+
+            // assert
+            Assert.IsTrue(vm.OkCommand.CanExecute(null));
+        }
+
+        [Test]
+        public void WhenNewViewModel_ThenCancelCommandIsExecutable()
+        {
+            // arrange
+            var vm = CreateDefaultUserViewModel();
+
+            // assert
+            Assert.IsTrue(vm.CancelCommand.CanExecute(null));
+        }
+
+        [Test]
+        public void WhenNewViewModel_WithCancelExecuted_ThenShouldRaiseEvent()
+        {
+            // arrange
+            var vm = CreateDefaultUserViewModel();
+
+            // act
+            vm.CancelCommand.Execute(null);
+
+            // assert
+            vm.ShouldRaise("UserViewResponseMessage");
+        }
+        
+        #endregion
+
         #region Helpers
 
         private static UserViewModel CreateDefaultUserViewModel()