@@ -30,16 +30,15 @@ public class CommandBindingImplementationTests
3030 [ Fact ]
3131 public void CommandBindByNameWireup ( )
3232 {
33- var vm = new CommandBindViewModel ( ) ;
34- var view = new CommandBindView { ViewModel = vm } ;
33+ var view = new CommandBindView { ViewModel = new ( ) } ;
3534
3635 Assert . Null ( view . Command1 . Command ) ;
3736
38- var disp = view . BindCommand ( vm , x => x . Command1 , x => x . Command1 ) ;
39- Assert . Equal ( vm . Command1 , view . Command1 . Command ) ;
37+ var disp = view . BindCommand ( view . ViewModel , x => x . Command1 , x => x . Command1 ) ;
38+ Assert . Equal ( view . ViewModel . Command1 , view . Command1 . Command ) ;
4039
4140 var newCmd = ReactiveCommand . Create < int > ( _ => { } ) ;
42- vm . Command1 = newCmd ;
41+ view . ViewModel . Command1 = newCmd ;
4342 Assert . Equal ( newCmd , view . Command1 . Command ) ;
4443
4544 disp . Dispose ( ) ;
@@ -54,14 +53,14 @@ public void CommandBindNestedCommandWireup()
5453 {
5554 var vm = new CommandBindViewModel
5655 {
57- NestedViewModel = new FakeNestedViewModel ( )
56+ NestedViewModel = new ( )
5857 } ;
5958
6059 var view = new CommandBindView { ViewModel = vm } ;
6160
62- view . BindCommand ( vm , m => m . NestedViewModel . NestedCommand , x => x . Command1 ) ;
61+ view . BindCommand ( view . ViewModel , m => m . NestedViewModel . NestedCommand , x => x . Command1 ) ;
6362
64- Assert . Equal ( vm . NestedViewModel . NestedCommand , view . Command1 . Command ) ;
63+ Assert . Equal ( view . ViewModel . NestedViewModel . NestedCommand , view . Command1 . Command ) ;
6564 }
6665
6766 /// <summary>
@@ -70,13 +69,12 @@ public void CommandBindNestedCommandWireup()
7069 [ Fact ]
7170 public void CommandBindSetsInitialEnabledState_True ( )
7271 {
73- var vm = new CommandBindViewModel ( ) ;
74- var view = new CommandBindView { ViewModel = vm } ;
72+ var view = new CommandBindView { ViewModel = new ( ) } ;
7573
7674 var canExecute1 = new BehaviorSubject < bool > ( true ) ;
77- vm . Command1 = ReactiveCommand . Create < int > ( _ => { } , canExecute1 ) ;
75+ view . ViewModel . Command1 = ReactiveCommand . Create < int > ( _ => { } , canExecute1 ) ;
7876
79- view . BindCommand ( vm , x => x . Command1 , x => x . Command1 ) ;
77+ view . BindCommand ( view . ViewModel , x => x . Command1 , x => x . Command1 ) ;
8078
8179 Assert . True ( view . Command1 . IsEnabled ) ;
8280 }
@@ -87,13 +85,12 @@ public void CommandBindSetsInitialEnabledState_True()
8785 [ Fact ]
8886 public void CommandBindSetsDisablesCommandWhenCanExecuteChanged ( )
8987 {
90- var vm = new CommandBindViewModel ( ) ;
91- var view = new CommandBindView { ViewModel = vm } ;
88+ var view = new CommandBindView { ViewModel = new ( ) } ;
9289
9390 var canExecute1 = new BehaviorSubject < bool > ( true ) ;
94- vm . Command1 = ReactiveCommand . Create < int > ( _ => { } , canExecute1 ) ;
91+ view . ViewModel . Command1 = ReactiveCommand . Create < int > ( _ => { } , canExecute1 ) ;
9592
96- view . BindCommand ( vm , x => x . Command1 , x => x . Command1 ) ;
93+ view . BindCommand ( view . ViewModel , x => x . Command1 , x => x . Command1 ) ;
9794
9895 Assert . True ( view . Command1 . IsEnabled ) ;
9996
@@ -108,13 +105,12 @@ public void CommandBindSetsDisablesCommandWhenCanExecuteChanged()
108105 [ Fact ]
109106 public void CommandBindSetsInitialEnabledState_False ( )
110107 {
111- var vm = new CommandBindViewModel ( ) ;
112- var view = new CommandBindView { ViewModel = vm } ;
108+ var view = new CommandBindView { ViewModel = new ( ) } ;
113109
114110 var canExecute1 = new BehaviorSubject < bool > ( false ) ;
115- vm . Command1 = ReactiveCommand . Create < int > ( _ => { } , canExecute1 ) ;
111+ view . ViewModel . Command1 = ReactiveCommand . Create < int > ( _ => { } , canExecute1 ) ;
116112
117- view . BindCommand ( vm , x => x . Command1 , x => x . Command1 ) ;
113+ view . BindCommand ( view . ViewModel , x => x . Command1 , x => x . Command1 ) ;
118114
119115 Assert . False ( view . Command1 . IsEnabled ) ;
120116 }
@@ -125,19 +121,18 @@ public void CommandBindSetsInitialEnabledState_False()
125121 [ Fact ]
126122 public void CommandBindRaisesCanExecuteChangedOnBind ( )
127123 {
128- var vm = new CommandBindViewModel ( ) ;
129- var view = new CommandBindView { ViewModel = vm } ;
124+ var view = new CommandBindView { ViewModel = new ( ) } ;
130125
131126 var canExecute1 = new BehaviorSubject < bool > ( true ) ;
132- vm . Command1 = ReactiveCommand . Create < int > ( _ => { } , canExecute1 ) ;
127+ view . ViewModel . Command1 = ReactiveCommand . Create < int > ( _ => { } , canExecute1 ) ;
133128
134- view . BindCommand ( vm , x => x . Command1 , x => x . Command1 ) ;
129+ view . BindCommand ( view . ViewModel , x => x . Command1 , x => x . Command1 ) ;
135130
136131 Assert . True ( view . Command1 . IsEnabled ) ;
137132
138133 // Now change to a disabled cmd
139134 var canExecute2 = new BehaviorSubject < bool > ( false ) ;
140- vm . Command1 = ReactiveCommand . Create < int > ( _ => { } , canExecute2 ) ;
135+ view . ViewModel . Command1 = ReactiveCommand . Create < int > ( _ => { } , canExecute2 ) ;
141136
142137 Assert . False ( view . Command1 . IsEnabled ) ;
143138 }
@@ -148,20 +143,18 @@ public void CommandBindRaisesCanExecuteChangedOnBind()
148143 [ Fact ]
149144 public void CommandBindWithParameterExpression ( )
150145 {
151- var vm = new CommandBindViewModel ( ) ;
152- var view = new CommandBindView { ViewModel = vm } ;
146+ var view = new CommandBindView { ViewModel = new ( ) } ;
153147
154148 var received = 0 ;
155- var cmd = ReactiveCommand . Create < int > ( i => { received = i ; } ) ;
156- vm . Command1 = cmd ;
149+ view . ViewModel . Command1 = ReactiveCommand . Create < int > ( i => received = i ) ;
157150
158- var disp = view . BindCommand ( vm , x => x . Command1 , x => x . Command1 , x => x . Value , nameof ( CustomClickButton . CustomClick ) ) ;
151+ var disp = view . BindCommand ( view . ViewModel , x => x . Command1 , x => x . Command1 , x => x . Value , nameof ( CustomClickButton . CustomClick ) ) ;
159152
160- vm . Value = 42 ;
153+ view . ViewModel . Value = 42 ;
161154 view . Command1 . RaiseCustomClick ( ) ;
162155 Assert . Equal ( 42 , received ) ;
163156
164- vm . Value = 13 ;
157+ view . ViewModel . Value = 13 ;
165158 view . Command1 . RaiseCustomClick ( ) ;
166159 Assert . Equal ( 13 , received ) ;
167160 }
@@ -172,22 +165,21 @@ public void CommandBindWithParameterExpression()
172165 [ Fact ]
173166 public void CommandBindWithDelaySetVMParameterExpression ( )
174167 {
175- var vm = new CommandBindViewModel ( ) ;
176- var view = new ReactiveObjectCommandBindView ( ) ;
168+ var view = new ReactiveObjectCommandBindView
169+ {
170+ ViewModel = new ( )
171+ } ;
177172
178173 var received = 0 ;
179- var cmd = ReactiveCommand . Create < int > ( i => { received = i ; } ) ;
180- vm . Command1 = cmd ;
181-
182- var disp = view . BindCommand ( vm , x => x . Command1 , x => x . Command1 , x => x . Value , nameof ( CustomClickButton . CustomClick ) ) ;
174+ view . ViewModel . Command1 = ReactiveCommand . Create < int > ( i => received = i ) ;
183175
184- view . ViewModel = vm ;
176+ var disp = view . BindCommand ( view . ViewModel , x => x . Command1 , x => x . Command1 , x => x . Value , nameof ( CustomClickButton . CustomClick ) ) ;
185177
186- vm . Value = 42 ;
178+ view . ViewModel . Value = 42 ;
187179 view . Command1 . RaiseCustomClick ( ) ;
188180 Assert . Equal ( 42 , received ) ;
189181
190- vm . Value = 13 ;
182+ view . ViewModel . Value = 13 ;
191183 view . Command1 . RaiseCustomClick ( ) ;
192184 Assert . Equal ( 13 , received ) ;
193185 }
@@ -198,24 +190,25 @@ public void CommandBindWithDelaySetVMParameterExpression()
198190 [ Fact ]
199191 public void CommandBindWithDelaySetVMParameterNoINPCExpression ( )
200192 {
201- var vm = new CommandBindViewModel ( ) ;
202- var view = new CommandBindView ( ) ;
193+ var view = new CommandBindView { ViewModel = new ( ) } ;
203194
204195 var received = 0 ;
205- var cmd = ReactiveCommand . Create < int > ( i => { received = i ; } ) ;
206- vm . Command1 = cmd ;
196+ var cmd = ReactiveCommand . Create < int > ( i => received = i ) ;
197+ view . ViewModel . Command1 = cmd ;
198+ view . ViewModel . Value = 10 ;
207199
208- view . BindCommand ( vm , x => x . Command1 , x => x . Command1 , x => x . Value , nameof ( CustomClickButton . CustomClick ) ) ;
200+ view . BindCommand ( view . ViewModel , x => x . Command1 , x => x . Command1 , x => x . Value , nameof ( CustomClickButton . CustomClick ) ) ;
209201
210- view . ViewModel = vm ;
202+ view . Command1 . RaiseCustomClick ( ) ;
203+ Assert . Equal ( 10 , received ) ;
211204
212- vm . Value = 42 ;
205+ view . ViewModel . Value = 42 ;
213206 view . Command1 . RaiseCustomClick ( ) ;
214- Assert . Equal ( 0 , received ) ;
207+ Assert . Equal ( 42 , received ) ;
215208
216- vm . Value = 13 ;
209+ view . ViewModel . Value = 13 ;
217210 view . Command1 . RaiseCustomClick ( ) ;
218- Assert . Equal ( 0 , received ) ;
211+ Assert . Equal ( 13 , received ) ;
219212 }
220213
221214 /// <summary>
@@ -224,17 +217,19 @@ public void CommandBindWithDelaySetVMParameterNoINPCExpression()
224217 [ Fact ]
225218 public void CommandBindWithParameterObservable ( )
226219 {
227- var vm = new CommandBindViewModel ( ) ;
228- var view = new CommandBindView { ViewModel = vm } ;
220+ var view = new CommandBindView { ViewModel = new ( ) } ;
229221
230222 var received = 0 ;
231223 var cmd = ReactiveCommand . Create < int > ( i => { received = i ; } ) ;
232- vm . Command1 = cmd ;
224+ view . ViewModel . Command1 = cmd ;
225+ view . ViewModel . Value = 10 ;
226+ var value = view . ViewModel . WhenAnyValue ( v => v . Value ) ;
227+ var disp = view . BindCommand ( view . ViewModel , x => x . Command1 , x => x . Command1 , value , nameof ( CustomClickButton . CustomClick ) ) ;
233228
234- var value = Observable . Return ( 42 ) ;
235- var disp = view . BindCommand ( vm , x => x . Command1 , x => x . Command1 , value , nameof ( CustomClickButton . CustomClick ) ) ;
229+ view . Command1 . RaiseCustomClick ( ) ;
230+ Assert . Equal ( 10 , received ) ;
236231
237- vm . Value = 42 ;
232+ view . ViewModel . Value = 42 ;
238233 view . Command1 . RaiseCustomClick ( ) ;
239234
240235 Assert . Equal ( 42 , received ) ;
0 commit comments