public void CanExecuteTestNull()
        {
            var command = new RelayCommand<string>(p =>
            {
            });

            Assert.AreEqual(true, command.CanExecute("Hello"));
        }
        public void CanExecuteTestInvalidParameterType()
        {
            var command = new RelayCommand<string>(p =>
            {
            },
                                                   p => p == "CanExecute");

            command.CanExecute(DateTime.Now);
        }
        public void CanExecuteTest()
        {
            var command = new RelayCommand<string>(p =>
            {
            },
                                                   p => p == "CanExecute");

            Assert.AreEqual(true, command.CanExecute("CanExecute"));
            Assert.AreEqual(false, command.CanExecute("Hello"));
        }
Example #4
0
        public void TestCanExecute()
        {
            var canExecute = true;

            var command = new RelayCommand((e) =>
            {
            },
                                           (e) => canExecute);

            Assert.AreEqual(true, command.CanExecute(null));

            canExecute = false;

            Assert.AreEqual(false, command.CanExecute(null));
        }
Example #5
0
        public void TestCallingExecuteWhenCanExecuteIsFalse()
        {
            var counter = 0;

            var command = new RelayCommand(
                (e) => counter++,
                (e) => _canExecute);

            command.Execute(null);
            Assert.AreEqual(1, counter);
            _canExecute = false;
            command.Execute(null);
            Assert.AreEqual(1, counter);
            _canExecute = true;
            command.Execute(null);
            Assert.AreEqual(2, counter);
        }
Example #6
0
        public void TestCanExecuteChanged()
        {
            var command = new RelayCommand((e) =>
            {
            },
                                           (e) => true);

            var canExecuteChangedCalled = 0;

            var canExecuteChangedEventHandler = new EventHandler((s, e) => canExecuteChangedCalled++);

            command.CanExecuteChanged += canExecuteChangedEventHandler;

            command.RaiseCanExecuteChanged();

            Assert.AreEqual(1, canExecuteChangedCalled);

            command.CanExecuteChanged -= canExecuteChangedEventHandler;
            command.RaiseCanExecuteChanged();

            Assert.AreEqual(1, canExecuteChangedCalled);
        }
Example #7
0
        public CustomMsgBox()
        {
            // Required to initialize variables
            InitializeComponent();
            HideBoxAnimation.Completed += HideBoxAnimationCompleted;

            OkCommand = new RelayCommand((e) =>
            {
                _result = true;
                Hide();
            });

            CancelCommand = new RelayCommand((e) =>
            {
                _result = false;
                Hide();
            });

            DataContext = this;
        }
Example #8
0
            public TestViewModel()
            {
                SimpleCommand = new RelayCommand((e) => CommandExecuted = true);

                ParameterCommand = new RelayCommand<string>(p =>
                {
                    CommandExecuted = true;
                    ParameterReceived = p;
                });

                ToggledCommand = new RelayCommand(
                    (e) => CommandExecuted = true,
                    (e) => EnableToggledCommand);

                ToggledCommandWithParameter = new RelayCommand<string>(
                    p =>
                    {
                        CommandExecuted = true;
                        ParameterReceived = p;
                    },
                    p => (p != null && p.StartsWith("Hello")));

                CommandWithEventArgs = new RelayCommand<EventArgs>(e =>
                    {
                        CommandExecuted = true;
                        ParameterReceived = ((StringEventArgs)e).Parameter;
                    });
            }
        public void CanExecuteTestNullParameter()
        {
            var command = new RelayCommand<string>(p =>
            {
            },
                                                   p => false);

            Assert.AreEqual(false, command.CanExecute(null));

            var command2 = new RelayCommand<string>(p =>
            {
            },
                                                   p => true);

            Assert.AreEqual(true, command2.CanExecute(null));
        }
        public void TestCallingExecuteWhenCanExecuteIsFalse()
        {
            var result = string.Empty;
            const string value1 = "Hello";
            const string value2 = "World";

            var command = new RelayCommand<string>(
                s => result = s,
                s => _canExecute);

            command.Execute(value1);
            Assert.AreEqual(value1, result);
            _canExecute = false;
            command.Execute(value2);
            Assert.AreEqual(value1, result);
            _canExecute = true;
            command.Execute(value2);
            Assert.AreEqual(value2, result);
        }
        public void ExecuteTest()
        {
            var dummy = "Not executed";
            const string executed = "Executed";
            const string parameter = "Parameter";

            var command = new RelayCommand<string>(p =>
            {
                dummy = executed + p;
            });

            command.Execute(parameter);

            Assert.AreEqual(executed + parameter, dummy);
        }
 public void ConstructorTestInvalidExecuteNull2()
 {
     var command = new RelayCommand<string>(null, null);
 }
Example #13
0
 public void TestConstructorInvalidExecuteNull1()
 {
     var command = new RelayCommand(null);
 }
Example #14
0
        public void TestCanExecuteNull()
        {
            var command = new RelayCommand((e) =>
            {
            });

            Assert.AreEqual(true, command.CanExecute(null));
        }
Example #15
0
        public void TestExecute()
        {
            var dummy = "Not executed";
            const string executed = "Executed";

            var command = new RelayCommand((e) =>
            {
                dummy = executed;
            });

            command.Execute(null);

            Assert.AreEqual(executed, dummy);
        }