Mercurial > silverbladetech
comparison SilverlightValidation/SilverlightValidation.Tests/ViewModels/UserViewModelFixture.cs @ 102:db05a55e3536
INPC tests added
author | stevenhollidge <stevenhollidge@hotmail.com> |
---|---|
date | Sun, 06 May 2012 12:13:29 +0100 |
parents | SilverlightValidation/SilverlightValidation.Tests/ViewModels/UserViewModelTests.cs@d0c2cac12376 |
children | 62477c2e8837 |
comparison
equal
deleted
inserted
replaced
101:2372846797f0 | 102:db05a55e3536 |
---|---|
1 using System; | |
2 using FluentAssertions.EventMonitoring; | |
3 using NUnit.Framework; | |
4 using SilverlightValidation.Models; | |
5 using SilverlightValidation.Tests.Fakes; | |
6 using SilverlightValidation.Validators; | |
7 using SilverlightValidation.ViewModels; | |
8 | |
9 namespace SilverlightValidation.Tests.ViewModels | |
10 { | |
11 [TestFixture] | |
12 class UserViewModelFixture | |
13 { | |
14 #region Constructor | |
15 | |
16 [Test] | |
17 public void WhenConstructed_WithTwoNulls_ThenArgumentNullExceptionForModel() | |
18 { | |
19 Assert.Throws<ArgumentNullException>(() => new UserViewModel(null, null), "model"); | |
20 } | |
21 | |
22 [Test] | |
23 public void WhenConstructed_WithNullFirstParam_ThenArgumentNullExceptionForModel() | |
24 { | |
25 Assert.Throws<ArgumentNullException>(() => new UserViewModel(null, UserModelValidator.Create()), "model"); | |
26 } | |
27 | |
28 [Test] | |
29 public void WhenConstructed_WithNullSecondParam_ThenArgumentNullExceptionForValidator() | |
30 { | |
31 Assert.Throws<ArgumentNullException>(() => new UserViewModel(UserModel.Create(), null), "validator"); | |
32 } | |
33 | |
34 [Test] | |
35 public void WhenConstructed_WithGenericParams_ThenInstantiatesViewModel() | |
36 { | |
37 var vm = new UserViewModel(UserModel.Create(), UserModelValidator.Create()); | |
38 Assert.IsNotNull(vm); | |
39 } | |
40 | |
41 #endregion | |
42 | |
43 #region INotifyPropertyChanged | |
44 | |
45 [Test] | |
46 public void WhenPropertyChanged_WithValidDateOfBirthUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue() | |
47 { | |
48 // arrange | |
49 var vm = CreateDefaultUserViewModel(); | |
50 | |
51 // act | |
52 vm.DateOfBirth = new DateTime(1977, 01, 01); | |
53 | |
54 // assert | |
55 vm.ShouldRaisePropertyChangeFor(x => x.DateOfBirth); | |
56 Assert.IsTrue(vm.IsChanged); | |
57 } | |
58 | |
59 | |
60 [Test] | |
61 public void WhenPropertyChanged_WithInvalidDateOfBirthUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue() | |
62 { | |
63 // arrange | |
64 var vm = CreateDefaultUserViewModel(); | |
65 | |
66 // act | |
67 vm.DateOfBirth = new DateTime(1800, 01, 01); | |
68 | |
69 // assert | |
70 vm.ShouldRaisePropertyChangeFor(x => x.DateOfBirth); | |
71 Assert.IsTrue(vm.IsChanged); | |
72 } | |
73 | |
74 [Test] | |
75 public void WhenPropertyChanged_WithDescriptionUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue() | |
76 { | |
77 // arrange | |
78 var vm = CreateDefaultUserViewModel(); | |
79 | |
80 // act | |
81 vm.Description = "New description"; | |
82 | |
83 // assert | |
84 vm.ShouldRaisePropertyChangeFor(x => x.Description); | |
85 Assert.IsTrue(vm.IsChanged); | |
86 } | |
87 | |
88 [Test] | |
89 public void WhenPropertyChanged_WithValidEmailUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue() | |
90 { | |
91 // arrange | |
92 var vm = CreateDefaultUserViewModel(); | |
93 | |
94 // act | |
95 vm.Email = "test@domain.com"; | |
96 | |
97 // assert | |
98 vm.ShouldRaisePropertyChangeFor(x => x.Email); | |
99 Assert.IsTrue(vm.IsChanged); | |
100 } | |
101 | |
102 [Test] | |
103 public void WhenPropertyChanged_WithInvalidEmailUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue() | |
104 { | |
105 // arrange | |
106 var vm = CreateDefaultUserViewModel(); | |
107 | |
108 // act | |
109 vm.Email = "invalid email"; | |
110 | |
111 // assert | |
112 vm.ShouldRaisePropertyChangeFor(x => x.Email); | |
113 Assert.IsTrue(vm.IsChanged); | |
114 } | |
115 | |
116 [Test] | |
117 public void WhenPropertyChanged_WithValidUsernameUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue() | |
118 { | |
119 // arrange | |
120 var vm = CreateDefaultUserViewModel(); | |
121 | |
122 // act | |
123 vm.Username = "dummy"; | |
124 | |
125 // assert | |
126 vm.ShouldRaisePropertyChangeFor(x => x.Username); | |
127 Assert.IsTrue(vm.IsChanged); | |
128 } | |
129 | |
130 [Test] | |
131 public void WhenPropertyChanged_WithInvalidUsernameUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue() | |
132 { | |
133 // arrange | |
134 var vm = CreateDefaultUserViewModel(); | |
135 | |
136 // act | |
137 vm.Username = "invalidusernametoolong"; | |
138 | |
139 // assert | |
140 vm.ShouldRaisePropertyChangeFor(x => x.Username); | |
141 Assert.IsTrue(vm.IsChanged); | |
142 } | |
143 | |
144 [Test] | |
145 public void WhenPropertyChanged_WithValidPasswordUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue() | |
146 { | |
147 // arrange | |
148 var vm = CreateDefaultUserViewModel(); | |
149 | |
150 // act | |
151 vm.Password = "dummy"; | |
152 | |
153 // assert | |
154 vm.ShouldRaisePropertyChangeFor(x => x.Password); | |
155 Assert.IsTrue(vm.IsChanged); | |
156 } | |
157 | |
158 [Test] | |
159 public void WhenPropertyChanged_WithInvalidPasswordUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue() | |
160 { | |
161 // arrange | |
162 var vm = CreateDefaultUserViewModel(); | |
163 | |
164 // act | |
165 vm.Password = "invalidpasswordtoolong"; | |
166 | |
167 // assert | |
168 vm.ShouldRaisePropertyChangeFor(x => x.Password); | |
169 Assert.IsTrue(vm.IsChanged); | |
170 } | |
171 | |
172 #endregion | |
173 | |
174 #region Helpers | |
175 | |
176 private static UserViewModel CreateDefaultUserViewModel() | |
177 { | |
178 var vm = new UserViewModel(UserModel.Create(), UserModelValidatorFake.Create()); | |
179 vm.MonitorEvents(); | |
180 return vm; | |
181 } | |
182 | |
183 #endregion | |
184 } | |
185 } |