Mercurial > silverbladetech
annotate SilverlightValidation/SilverlightValidation.Tests/TestSupport/CommandCanExecuteAssertHelper.cs @ 97:1adc1ae981ea
Tests added to SilverlightValidation.Tests
author | stevenhollidge <stevenhollidge@hotmail.com> |
---|---|
date | Sat, 05 May 2012 16:39:00 +0100 |
parents | |
children |
rev | line source |
---|---|
97
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
1 using System; |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
2 using System.Windows.Input; |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
3 using NUnit.Framework; |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
4 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
5 namespace SilverlightValidation.Tests.TestSupport |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
6 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
7 public static class CommandCanExecuteAssertHelper |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
8 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
9 #region Assert methods (using helper) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
10 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
11 #region Can/cannot execute |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
12 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
13 /// <summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
14 /// Raises an assertion if the supplied command's CanExecute method returns false. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
15 /// </summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
16 /// <remarks> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
17 /// CanExecute is passed null. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
18 /// </remarks> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
19 /// <param name="command">The command.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
20 public static void AssertCanExecute(this ICommand command) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
21 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
22 if (command == null) throw new ArgumentNullException("command"); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
23 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
24 Assert.IsTrue(command.CanExecute(null)); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
25 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
26 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
27 /// <summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
28 /// Raises an assertion if the supplied command's CanExecute method returns false. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
29 /// </summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
30 /// <typeparam name="T"></typeparam> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
31 /// <param name="command">The command.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
32 /// <param name="value">A value to pass to CanExecute.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
33 public static void AssertCanExecute<T>(this ICommand command, T value) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
34 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
35 if (command == null) throw new ArgumentNullException("command"); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
36 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
37 Assert.IsTrue(command.CanExecute(value)); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
38 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
39 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
40 /// <summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
41 /// Raises an assertion if the supplied command's CanExecute method returns true. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
42 /// </summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
43 /// <remarks> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
44 /// CanExecute is passed null. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
45 /// </remarks> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
46 /// <param name="command">The command.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
47 public static void AssertCannotExecute(this ICommand command) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
48 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
49 if (command == null) throw new ArgumentNullException("command"); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
50 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
51 Assert.IsTrue(!command.CanExecute(null)); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
52 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
53 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
54 /// <summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
55 /// Raises an assertion if the supplied command's CanExecute method returns true. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
56 /// </summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
57 /// <typeparam name="T"></typeparam> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
58 /// <param name="command">The command.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
59 /// <param name="value">A value to pass to CanExecute.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
60 public static void AssertCannotExecute<T>(this ICommand command, T value) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
61 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
62 if (command == null) throw new ArgumentNullException("command"); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
63 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
64 Assert.IsTrue(!command.CanExecute(value)); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
65 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
66 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
67 #endregion |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
68 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
69 #region Assert is raised/Assert is not raised (CommandCanExecute) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
70 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
71 /// <summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
72 /// Raises an assertion if the action is invoked and the supplied command |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
73 /// raises a CommandCanExecuteChanged event. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
74 /// </summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
75 /// <param name = "command">The command.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
76 /// <param name = "action">The action to invoke.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
77 public static void AssertIsNotRaised(this ICommand command, Action action) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
78 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
79 Assert.IsTrue(IsNotRaised(command, action)); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
80 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
81 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
82 /// <summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
83 /// Raises an assertion if the action is invoked and the supplied command |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
84 /// does not raise at least one CommandCanExecuteChanged event. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
85 /// </summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
86 /// <param name = "command">The command.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
87 /// <param name = "action">The action to invoke.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
88 public static void AssertIsRaised(this ICommand command, Action action) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
89 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
90 Assert.IsTrue(IsRaised(command, action)); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
91 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
92 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
93 /// <summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
94 /// Raises an assertion if the action is invoked and the supplied command |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
95 /// does raise the number of CommandCanExecuteChanged events as defined by the |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
96 /// supplied predicate. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
97 /// </summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
98 /// <param name = "command">The command.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
99 /// <param name = "predicate">The predicate.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
100 /// <param name = "action">The action to invoke.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
101 public static void AssertIsRaised(this ICommand command, Predicate<int> predicate, Action action) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
102 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
103 Assert.IsTrue(IsRaised(command, predicate, action)); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
104 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
105 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
106 #endregion |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
107 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
108 #endregion |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
109 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
110 #region Is raised/Is not raised methods (CommandCanExecute) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
111 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
112 /// <summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
113 /// Determines if the specified CommandCanExecuteChanged event is |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
114 /// not raised when the supplied action is invoked. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
115 /// </summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
116 /// <param name = "command">The command.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
117 /// <param name = "action">The action to invoke.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
118 public static bool IsNotRaised(this ICommand command, Action action) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
119 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
120 return !IsRaised(command, action); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
121 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
122 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
123 /// <summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
124 /// Determines if the specified CommandCanExecuteChanged event is |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
125 /// raised one or more times when the supplied action is invoked. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
126 /// </summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
127 /// <param name = "command">The command.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
128 /// <param name = "action">The action to invoke.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
129 /// <returns> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
130 /// <c>true</c> if the specified command is raised; otherwise, <c>false</c>. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
131 /// </returns> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
132 public static bool IsRaised(this ICommand command, Action action) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
133 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
134 return IsRaised(command, count => count > 0, action); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
135 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
136 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
137 /// <summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
138 /// Determines if the specified CommandCanExecuteChanged event is |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
139 /// raised the number of times as defined by the predicate when the supplied action is invoked. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
140 /// </summary> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
141 /// <param name = "command">The command.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
142 /// <param name = "predicate">A predicate.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
143 /// <param name = "action">The action to invoke.</param> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
144 /// <returns> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
145 /// <c>true</c> if the specified command's CanExecuteChanged event is raised; otherwise, <c>false</c>. |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
146 /// </returns> |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
147 public static bool IsRaised(this ICommand command, Predicate<int> predicate, Action action) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
148 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
149 if (predicate == null) throw new ArgumentNullException("predicate"); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
150 if (action == null) throw new ArgumentNullException("action"); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
151 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
152 using (var watcher = new CommandCanExecuteChangedEventWatcher(command)) |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
153 { |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
154 action(); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
155 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
156 return predicate(watcher.RaisedCount); |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
157 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
158 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
159 |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
160 #endregion |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
161 } |
1adc1ae981ea
Tests added to SilverlightValidation.Tests
stevenhollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
162 } |