public void CommandBindRaisesCanExecuteChangedOnBind()
        {
            var vm   = new CommandBindViewModel();
            var view = new CommandBindView()
            {
                ViewModel = vm
            };

            var canExecute1 = new BehaviorSubject <bool>(true);
            var cmd1        = ReactiveCommand.Create(() => { }, canExecute1);

            vm.Command1 = cmd1;

            var disp = 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);
            var cmd2        = ReactiveCommand.Create(() => { }, canExecute2);

            vm.Command1 = cmd2;

            Assert.False(view.Command1.IsEnabled);
        }
        public void CommandBindToExplicitEventWireup()
        {
            var vm   = new CommandBindViewModel();
            var view = new CommandBindView()
            {
                ViewModel = vm
            };
            var fixture = new CommandBinderImplementation();

            int invokeCount = 0;

            vm.Command2.Subscribe(_ => invokeCount += 1);

            var disp = fixture.BindCommand(vm, view, x => x.Command2, x => x.Command2, "MouseUp");

            view.Command2.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left)
            {
                RoutedEvent = Image.MouseUpEvent
            });

            disp.Dispose();

            view.Command2.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left)
            {
                RoutedEvent = Image.MouseUpEvent
            });
            Assert.Equal(1, invokeCount);
        }
        public void CommandBindRaisesCanExecuteChangedOnBind()
        {
            var vm   = new CommandBindViewModel();
            var view = new CommandBindView()
            {
                ViewModel = vm
            };
            var fixture = new CommandBinderImplementation();

            var canExecute1 = new BehaviorSubject <bool>(true);
            var cmd1        = new ReactiveCommand(canExecute1);

            vm.Command1 = cmd1;

            var disp = fixture.BindCommand(vm, view, x => x.Command1, x => x.Command1);

            Assert.True(view.Command1.IsEnabled);

            // Now  change to a disabled cmd

            var canExecute2 = new BehaviorSubject <bool>(false);
            var cmd2        = new ReactiveCommand(canExecute2);

            vm.Command1 = cmd2;

            Assert.False(view.Command1.IsEnabled);
        }
        public void CommandBindNestedCommandWireup()
        {
            var vm = new CommandBindViewModel()
            {
                NestedViewModel = new FakeNestedViewModel()
            };

            var view = new CommandBindView {
                ViewModel = vm
            };

            var disp = view.BindCommand(vm, m => m.NestedViewModel.NestedCommand, x => x.Command1);

            Assert.Equal(vm.NestedViewModel.NestedCommand, view.Command1.Command);
        }
        public void CommandBindNestedCommandWireup()
        {
            var vm = new CommandBindViewModel()
            {
                NestedViewModel = new FakeNestedViewModel()
            };

            var view = new CommandBindView {
                ViewModel = vm
            };
            var fixture = new CommandBinderImplementation();

            var disp = fixture.BindCommand(vm, view, m => m.NestedViewModel.NestedCommand, x => x.Command1);

            Assert.Equal(vm.NestedViewModel.NestedCommand, view.Command1.Command);
        }
        public void CommandBindSetsInitialEnabledState_False()
        {
            var vm   = new CommandBindViewModel();
            var view = new CommandBindView()
            {
                ViewModel = vm
            };

            var canExecute1 = new BehaviorSubject <bool>(false);
            var cmd1        = ReactiveCommand.Create(() => { }, canExecute1);

            vm.Command1 = cmd1;

            var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1);

            Assert.False(view.Command1.IsEnabled);
        }
        public void CommandBindSetsInitialEnabledState_False()
        {
            var vm   = new CommandBindViewModel();
            var view = new CommandBindView()
            {
                ViewModel = vm
            };
            var fixture = new CommandBinderImplementation();

            var canExecute1 = new BehaviorSubject <bool>(false);
            var cmd1        = new ReactiveCommand(canExecute1);

            vm.Command1 = cmd1;

            var disp = fixture.BindCommand(vm, view, x => x.Command1, x => x.Command1);

            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 CommandBindSetsDisablesCommandWhenCanExecuteChanged()
        {
            var vm   = new CommandBindViewModel();
            var view = new CommandBindView()
            {
                ViewModel = vm
            };

            var canExecute1 = new BehaviorSubject <bool>(true);
            var cmd1        = ReactiveCommand.Create(() => { }, canExecute1);

            vm.Command1 = cmd1;

            var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1);

            Assert.True(view.Command1.IsEnabled);

            canExecute1.OnNext(false);

            Assert.False(view.Command1.IsEnabled);
        }
        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;

            var disp = 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 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(() => { });

            vm.Command1 = newCmd;
            Assert.Equal(newCmd, view.Command1.Command);

            disp.Dispose();
            Assert.Null(view.Command1.Command);
        }
        public void CommandBindByNameWireup()
        {
            var vm   = new CommandBindViewModel();
            var view = new CommandBindView()
            {
                ViewModel = vm
            };
            var fixture = new CommandBinderImplementation();

            Assert.Null(view.Command1.Command);

            var disp = fixture.BindCommand(vm, view, x => x.Command1, x => x.Command1);

            Assert.Equal(vm.Command1, view.Command1.Command);

            var newCmd = new ReactiveCommand();

            vm.Command1 = newCmd;
            Assert.Equal(newCmd, view.Command1.Command);

            disp.Dispose();
            Assert.Null(view.Command1.Command);
        }
        public void CommandBindSetsDisablesCommandWhenCanExecuteChanged()
        {
            var vm   = new CommandBindViewModel();
            var view = new CommandBindView()
            {
                ViewModel = vm
            };
            var fixture = new CommandBinderImplementation();

            var canExecute1 = new BehaviorSubject <bool>(true);
            var cmd1        = new ReactiveCommand(canExecute1);

            vm.Command1 = cmd1;


            var disp = fixture.BindCommand(vm, view, x => x.Command1, x => x.Command1);

            Assert.True(view.Command1.IsEnabled);

            canExecute1.OnNext(false);

            Assert.False(view.Command1.IsEnabled);
        }