Mercurial > silverbladetech
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 | 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 | 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 | 33 #endregion |
34 | |
35 #region INotifyPropertyChanged | |
36 | |
97
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
96
diff
changeset
|
37 [Test] |
98 | 38 public void PropertyChange_WhenDateOfBirthUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue() |
39 { | |
40 // arrange | |
41 var vm = CreateDefaultUserViewModel(); | |
42 vm.MonitorEvents(); | |
43 | |
44 // act | |
45 vm.DateOfBirth = new DateTime(1977, 01, 01); | |
46 | |
47 // assert | |
48 vm.ShouldRaisePropertyChangeFor(x => x.DateOfBirth); | |
49 Assert.IsTrue(vm.IsChanged); | |
50 } | |
51 | |
52 [Test] | |
53 public void PropertyChange_WhenDescriptionUpdated_ThenFiresChangeEventAndIsChangedEqualsTrue() | |
54 { | |
55 // arrange | |
56 var vm = CreateDefaultUserViewModel(); | |
57 vm.MonitorEvents(); | |
58 | |
59 // act | |
60 vm.Description = "New description"; | |
61 | |
62 // assert | |
63 vm.ShouldRaisePropertyChangeFor(x => x.Description); | |
64 Assert.IsTrue(vm.IsChanged); | |
65 } | |
66 | |
67 #endregion | |
68 | |
69 #region INotifyDataErrorInfo | |
70 | |
71 #endregion | |
72 | |
73 #region Commands | |
74 | |
75 #endregion | |
76 | |
77 #region Helpers | |
78 | |
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 | 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 } |