public void CommandBindSetsInitialEnabledState_True() { var vm = new CommandBindViewModel(); var view = new CommandBindView { ViewModel = vm }; var canExecute1 = new BehaviorSubject <bool>(true); vm.Command1 = ReactiveCommand.Create <int>(_ => { }, canExecute1); view.BindCommand(vm, x => x.Command1, x => x.Command1); Assert.True(view.Command1.IsEnabled); }
public void CommandBindNestedCommandWireup() { var vm = new CommandBindViewModel { NestedViewModel = new FakeNestedViewModel() }; var view = new CommandBindView { ViewModel = vm }; view.BindCommand(vm, m => m.NestedViewModel.NestedCommand, x => x.Command1); Assert.Equal(vm.NestedViewModel.NestedCommand, view.Command1.Command); }
public void CommandBindSetsDisablesCommandWhenCanExecuteChanged() { var vm = new CommandBindViewModel(); var view = new CommandBindView { ViewModel = vm }; var canExecute1 = new BehaviorSubject <bool>(true); vm.Command1 = ReactiveCommand.Create <int>(_ => { }, canExecute1); view.BindCommand(vm, x => x.Command1, x => x.Command1); Assert.True(view.Command1.IsEnabled); canExecute1.OnNext(false); Assert.False(view.Command1.IsEnabled); }
public void CommandBindWithParameterObservable() { var vm = new CommandBindViewModel(); var view = new CommandBindView { ViewModel = vm }; var received = 0; var cmd = ReactiveCommand.Create <int>(i => { received = i; }); vm.Command1 = cmd; var value = Observable.Return(42); var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1, value, nameof(CustomClickButton.CustomClick)); vm.Value = 42; view.Command1.RaiseCustomClick(); Assert.Equal(42, received); }
public void CommandBindByNameWireup() { var vm = new CommandBindViewModel(); var view = new CommandBindView { ViewModel = vm }; Assert.Null(view.Command1.Command); var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1); Assert.Equal(vm.Command1, view.Command1.Command); var newCmd = ReactiveCommand.Create <int>(_ => { }); vm.Command1 = newCmd; Assert.Equal(newCmd, view.Command1.Command); disp.Dispose(); Assert.Null(view.Command1.Command); }
public void CommandBindWithDelaySetVMParameterNoINPCExpression() { var vm = new CommandBindViewModel(); var view = new CommandBindView(); var received = 0; var cmd = ReactiveCommand.Create <int>(i => { received = i; }); vm.Command1 = cmd; view.BindCommand(vm, x => x.Command1, x => x.Command1, x => x.Value, nameof(CustomClickButton.CustomClick)); view.ViewModel = vm; vm.Value = 42; view.Command1.RaiseCustomClick(); Assert.Equal(0, received); vm.Value = 13; view.Command1.RaiseCustomClick(); Assert.Equal(0, received); }
public void CommandBindRaisesCanExecuteChangedOnBind() { var vm = new CommandBindViewModel(); var view = new CommandBindView { ViewModel = vm }; var canExecute1 = new BehaviorSubject <bool>(true); vm.Command1 = ReactiveCommand.Create <int>(_ => { }, canExecute1); view.BindCommand(vm, x => x.Command1, x => x.Command1); Assert.True(view.Command1.IsEnabled); // Now change to a disabled cmd var canExecute2 = new BehaviorSubject <bool>(false); vm.Command1 = ReactiveCommand.Create <int>(_ => { }, canExecute2); Assert.False(view.Command1.IsEnabled); }