public void CommandBindToExplicitEventWireupWithParameter() { var vm = new WinformCommandBindViewModel(); var view = new WinformCommandBindView { ViewModel = vm }; var fixture = new CommandBinderImplementation(); var invokeCount = 0; vm.Command3.Subscribe(_ => ++ invokeCount); var disp = CommandBinderImplementationMixins.BindCommand(fixture, vm, view, x => x.Command3, x => x.Command2, vm => vm.Parameter, "MouseUp"); view.Command2.RaiseMouseUpEvent(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0)); Assert.Equal(10, vm.ParameterResult); Assert.Equal(1, invokeCount); vm.Parameter = 2; view.Command2.RaiseMouseUpEvent(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0)); Assert.Equal(20, vm.ParameterResult); Assert.Equal(2, invokeCount); disp.Dispose(); view.Command2.RaiseMouseUpEvent(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0)); Assert.Equal(2, invokeCount); }
public void CommandBindByNameWireupWithParameter() { var vm = new WinformCommandBindViewModel(); var view = new WinformCommandBindView { ViewModel = vm }; ICommandBinderImplementation fixture = new CommandBinderImplementation(); var invokeCount = 0; vm.Command3.Subscribe(_ => ++ invokeCount); var disp = CommandBinderImplementationMixins.BindCommand(fixture, vm, view, vm => vm.Command3, v => v.Command1, vm => vm.Parameter); view.Command1.PerformClick(); Assert.Equal(1, invokeCount); Assert.Equal(10, vm.ParameterResult); // update the parameter to ensure its updated when the command is executed vm.Parameter = 2; view.Command1.PerformClick(); Assert.Equal(2, invokeCount); Assert.Equal(20, vm.ParameterResult); // break the Command3 subscription var newCmd = ReactiveCommand.Create <int>(i => vm.ParameterResult = i * 2); vm.Command3 = newCmd; // ensure that the invoke count does not update and that the Command3 is now using the new math view.Command1.PerformClick(); Assert.Equal(2, invokeCount); Assert.Equal(4, vm.ParameterResult); disp.Dispose(); }