diff SilverlightValidation/SilverlightValidation.Tests/ViewModels/UserViewModelFixture.cs @ 107:572886951353

Working tests under StatLight
author stevenhollidge <stevenhollidge@hotmail.com>
date Sun, 06 May 2012 16:09:28 +0100
parents 62477c2e8837
children
line wrap: on
line diff
--- a/SilverlightValidation/SilverlightValidation.Tests/ViewModels/UserViewModelFixture.cs	Sun May 06 13:00:46 2012 +0100
+++ b/SilverlightValidation/SilverlightValidation.Tests/ViewModels/UserViewModelFixture.cs	Sun May 06 16:09:28 2012 +0100
@@ -1,6 +1,8 @@
 using System;
 using FluentAssertions.EventMonitoring;
-using NUnit.Framework;
+using GalaSoft.MvvmLight.Messaging;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using SilverlightValidation.Messages;
 using SilverlightValidation.Models;
 using SilverlightValidation.Tests.Fakes;
 using SilverlightValidation.Validators;
@@ -8,30 +10,33 @@
 
 namespace SilverlightValidation.Tests.ViewModels
 {
-    [TestFixture]
-    class UserViewModelFixture
+    [TestClass]
+    public class UserViewModelFixture
     {
         #region Constructor
 
-        [Test]
-        public void WhenConstructed_WithTwoNulls_ThenArgumentNullExceptionForModel()
+        [TestMethod]
+        [ExpectedException(typeof(ArgumentNullException))]
+        public void WhenConstructed_WithTwoNulls_ThenThrowsArgumentNullException()
         {
-            Assert.Throws<ArgumentNullException>(() => new UserViewModel(null, null), "model");
+            new UserViewModel(null, null);
         }
 
-        [Test]
-        public void WhenConstructed_WithNullFirstParam_ThenArgumentNullExceptionForModel()
+        [TestMethod]
+        [ExpectedException(typeof(ArgumentNullException))]
+        public void WhenConstructed_WithNullFirstParam_ThenThrowsArgumentNullException()
         {
-            Assert.Throws<ArgumentNullException>(() => new UserViewModel(null, UserModelValidator.Create()), "model");
+            new UserViewModel(null, UserModelValidator.Create());
         }
 
-        [Test]
-        public void WhenConstructed_WithNullSecondParam_ThenArgumentNullExceptionForValidator()
+        [TestMethod]
+        [ExpectedException(typeof(ArgumentNullException))]
+        public void WhenConstructed_WithNullSecondParam_ThenThrowsArgumentNullException()
         {
-            Assert.Throws<ArgumentNullException>(() => new UserViewModel(UserModel.Create(), null), "validator");
+            new UserViewModel(UserModel.Create(), null);
         }
 
-        [Test]
+        [TestMethod]
         public void WhenConstructed_WithGenericParams_ThenInstantiatesViewModel()
         {
             var vm = new UserViewModel(UserModel.Create(), UserModelValidator.Create());
@@ -42,7 +47,7 @@
 
         #region INotifyPropertyChanged
 
-        [Test]
+        [TestMethod]
         public void WhenPropertyChanged_WithValidDateOfBirthUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue()
         {
             // arrange
@@ -57,7 +62,7 @@
         }
 
 
-        [Test]
+        [TestMethod]
         public void WhenPropertyChanged_WithInvalidDateOfBirthUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue()
         {
             // arrange
@@ -71,7 +76,7 @@
             Assert.IsTrue(vm.IsChanged);
         }
 
-        [Test]
+        [TestMethod]
         public void WhenPropertyChanged_WithDescriptionUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue()
         {
             // arrange
@@ -85,7 +90,7 @@
             Assert.IsTrue(vm.IsChanged);
         }
 
-        [Test]
+        [TestMethod]
         public void WhenPropertyChanged_WithValidEmailUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue()
         {
             // arrange
@@ -99,7 +104,7 @@
             Assert.IsTrue(vm.IsChanged);
         }
 
-        [Test]
+        [TestMethod]
         public void WhenPropertyChanged_WithInvalidEmailUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue()
         {
             // arrange
@@ -113,7 +118,7 @@
             Assert.IsTrue(vm.IsChanged);
         }
 
-        [Test]
+        [TestMethod]
         public void WhenPropertyChanged_WithValidUsernameUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue()
         {
             // arrange
@@ -127,7 +132,7 @@
             Assert.IsTrue(vm.IsChanged);
         }
 
-        [Test]
+        [TestMethod]
         public void WhenPropertyChanged_WithInvalidUsernameUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue()
         {
             // arrange
@@ -141,7 +146,7 @@
             Assert.IsTrue(vm.IsChanged);
         }
 
-        [Test]
+        [TestMethod]
         public void WhenPropertyChanged_WithValidPasswordUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue()
         {
             // arrange
@@ -155,7 +160,7 @@
             Assert.IsTrue(vm.IsChanged);
         }
 
-        [Test]
+        [TestMethod]
         public void WhenPropertyChanged_WithInvalidPasswordUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue()
         {
             // arrange
@@ -173,7 +178,7 @@
 
         #region Commands
 
-        [Test]
+        [TestMethod]
         public void WhenNewViewModel_ThenOkCommandIsExecutable()
         {
             // arrange
@@ -183,7 +188,7 @@
             Assert.IsTrue(vm.OkCommand.CanExecute(null));
         }
 
-        [Test]
+        [TestMethod]
         public void WhenNewViewModel_ThenCancelCommandIsExecutable()
         {
             // arrange
@@ -193,17 +198,19 @@
             Assert.IsTrue(vm.CancelCommand.CanExecute(null));
         }
 
-        [Test]
+        [TestMethod]
         public void WhenNewViewModel_WithCancelExecuted_ThenShouldRaiseEvent()
         {
             // arrange
             var vm = CreateDefaultUserViewModel();
+            bool hasMessage = false;
+            Messenger.Default.Register<UserViewResponseMessage>(this, message => { hasMessage = true; });
 
             // act
             vm.CancelCommand.Execute(null);
 
             // assert
-            vm.ShouldRaise("UserViewResponseMessage");
+            Assert.IsTrue(hasMessage);
         }
         
         #endregion