Esempio n. 1
0
        public void DisposeDeregistersCommandCanExecuteChanged()
        {
            var command   = new TestCommand();
            var viewModel = new Mock <TestData.ViewModel.WithCommandProperty>();

            viewModel.Setup(x => x.CommandProperty).Returns(command);

            var obj = new Binding.Gtk.BindButtonToCommand(Mock.Of <IButton>());

            obj.Bind(viewModel.Object, nameof(TestData.ViewModel.WithCommandProperty.CommandProperty));

            obj.Dispose();

            Assert.IsTrue(command.CanExecuteChangedWasRemoved);
        }
Esempio n. 2
0
        public void BindSetsGtkButtonSensitiveToICommandCanExecuteMethod(bool canExecute)
        {
            var button  = new Mock <IButton>();
            var command = new Mock <ICommand>();

            command.Setup(x => x.CanExecute(It.IsAny <object>())).Returns(canExecute);

            var viewModel = new Mock <TestData.ViewModel.WithCommandProperty>();

            viewModel.Setup(x => x.CommandProperty).Returns(command.Object);

            var obj = new Binding.Gtk.BindButtonToCommand(button.Object);

            obj.Bind(viewModel.Object, nameof(viewModel.Object.CommandProperty));

            command.Verify(x => x.CanExecute(It.IsAny <object>()), Times.Once);
            button.VerifySet(b => b.Sensitive = canExecute);
        }
Esempio n. 3
0
        public void ForwardGtkButtonFieldClickedEventToICommandExecuteMethod()
        {
            var button  = new Mock <IButton>();
            var command = new Mock <ICommand>();

            command.Setup(x => x.CanExecute(It.IsAny <object>())).Returns(true);

            var viewModel = new Mock <TestData.ViewModel.WithCommandProperty>();

            viewModel.Setup(x => x.CommandProperty).Returns(command.Object);

            var obj = new Binding.Gtk.BindButtonToCommand(button.Object);

            obj.Bind(viewModel.Object, nameof(TestData.ViewModel.WithCommandProperty.CommandProperty));

            command.Verify(x => x.Execute(It.IsAny <object>()), Times.Never);
            button.Raise(x => x.Clicked += null, EventArgs.Empty);
            command.Verify(x => x.Execute(It.IsAny <object>()), Times.Once);
        }