Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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);
        }