# HG changeset patch # User stevenhollidge # Date 1336305646 -3600 # Node ID 62477c2e8837a15af9a45e14382ba9dc7cecb0cf # Parent 1c9fc59af18671be284afc25b0de08a9355f142c Command tests diff -r 1c9fc59af186 -r 62477c2e8837 SilverlightValidation/SilverlightValidation.PL/ViewModels/UserViewModel.cs --- 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( - new UserViewResponseMessage() { UserViewModel = this }); + Messenger.Default.Send(new UserViewResponseMessage() { UserViewModel = this }); } } @@ -184,8 +183,7 @@ private void CancelCommandExecute(object obj) { - Messenger.Default.Send( - new UserViewResponseMessage() { UserViewModel = null }); + Messenger.Default.Send(new UserViewResponseMessage() { UserViewModel = null }); } #endregion diff -r 1c9fc59af186 -r 62477c2e8837 SilverlightValidation/SilverlightValidation.Tests/ViewModels/UserViewModelFixture.cs --- 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()