annotate SilverlightValidation/SilverlightValidation.Tests/ViewModels/UserViewModelTests.cs @ 98:d0c2cac12376

Latest version
author stevenhollidge <stevenhollidge@hotmail.com>
date Sat, 05 May 2012 22:53:40 +0100
parents 1adc1ae981ea
children
rev   line source
97
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
1 using System;
98
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
2 using FluentAssertions.EventMonitoring;
97
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
3 using NUnit.Framework;
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
4 using SilverlightValidation.Models;
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
5 using SilverlightValidation.Validators;
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
6 using SilverlightValidation.ViewModels;
96
188f8b366e87 Unit test project correctly setup as normal class library DLL.
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
7
188f8b366e87 Unit test project correctly setup as normal class library DLL.
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
8 namespace SilverlightValidation.Tests.ViewModels
188f8b366e87 Unit test project correctly setup as normal class library DLL.
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
9 {
188f8b366e87 Unit test project correctly setup as normal class library DLL.
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
10 [TestFixture]
188f8b366e87 Unit test project correctly setup as normal class library DLL.
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
11 class UserViewModelTests
188f8b366e87 Unit test project correctly setup as normal class library DLL.
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
12 {
98
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
13 #region Constructor
97
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
14
96
188f8b366e87 Unit test project correctly setup as normal class library DLL.
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
15 [Test]
97
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
16 public void Constructor_WhenTwoNulls_ThenArgumentNullExceptionForModel()
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
17 {
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
18 Assert.Throws<ArgumentNullException>(() => new UserViewModel(null, null), "model");
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
19 }
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
20
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
21 [Test]
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
22 public void Constructor_WhenFirstParameterIsNull_ThenArgumentNullExceptionForModel()
96
188f8b366e87 Unit test project correctly setup as normal class library DLL.
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
23 {
97
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
24 Assert.Throws<ArgumentNullException>(() => new UserViewModel(null, new UserModelValidator()), "model");
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
25 }
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
26
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
27 [Test]
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
28 public void Constructor_WhenSecondParameterIsNull_ThenArgumentNullExceptionForValidator()
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
29 {
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
30 Assert.Throws<ArgumentNullException>(() => new UserViewModel(new UserModel(), null), "validator");
96
188f8b366e87 Unit test project correctly setup as normal class library DLL.
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
31 }
97
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
32
98
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
33 #endregion
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
34
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
35 #region INotifyPropertyChanged
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
36
97
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
37 [Test]
98
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
38 public void PropertyChange_WhenDateOfBirthUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue()
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
39 {
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
40 // arrange
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
41 var vm = CreateDefaultUserViewModel();
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
42 vm.MonitorEvents();
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
43
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
44 // act
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
45 vm.DateOfBirth = new DateTime(1977, 01, 01);
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
46
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
47 // assert
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
48 vm.ShouldRaisePropertyChangeFor(x => x.DateOfBirth);
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
49 Assert.IsTrue(vm.IsChanged);
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
50 }
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
51
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
52 [Test]
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
53 public void PropertyChange_WhenDescriptionUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue()
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
54 {
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
55 // arrange
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
56 var vm = CreateDefaultUserViewModel();
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
57 vm.MonitorEvents();
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
58
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
59 // act
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
60 vm.Description = "New description";
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
61
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
62 // assert
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
63 vm.ShouldRaisePropertyChangeFor(x => x.Description);
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
64 Assert.IsTrue(vm.IsChanged);
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
65 }
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
66
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
67 #endregion
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
68
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
69 #region INotifyDataErrorInfo
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
70
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
71 #endregion
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
72
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
73 #region Commands
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
74
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
75 #endregion
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
76
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
77 #region Helpers
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
78
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
79 private static UserViewModel CreateDefaultUserViewModel()
97
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
80 {
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
81 var vm = new UserViewModel(new UserModel(), new UserModelValidator());
98
d0c2cac12376 Latest version
stevenhollidge <stevenhollidge@hotmail.com>
parents: 97
diff changeset
82 return vm;
97
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
83 }
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
84
1adc1ae981ea Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents: 96
diff changeset
85 #endregion
96
188f8b366e87 Unit test project correctly setup as normal class library DLL.
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
86 }
188f8b366e87 Unit test project correctly setup as normal class library DLL.
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
87 }