Пример #1
0
        public void TestRelayCommandWithNullValueTypeParam()
        {
            RelayCommand<int> command = new RelayCommand<int>(
                e => Assert.That(e, Is.EqualTo(0)),
                i =>
                    {
                        Assert.That(i, Is.EqualTo(0));
                        return true;
                    });

            Assert.That(command.HasCanExecuteFunction, Is.True);
            Assert.That(command.CanExecute(null), Is.True);
            command.Execute(null);
            Assert.That(command.CanExecute(null), Is.True);
        }
Пример #2
0
        public void TestRelayCommandWithParamNoCanExecute()
        {
            const string parameterString = "567";
            int parameterAsInt = int.Parse(parameterString);

            bool actionPerformed = false;

            string executeActionParam = string.Empty;

            RelayCommand<string> command = new RelayCommand<string>(
                e =>
                    {
                        executeActionParam = e;
                        actionPerformed = true;
                    });

            Assert.That(command.HasCanExecuteFunction, Is.False);
            Assert.That(command.CanExecute(parameterString), Is.True);
            command.Execute(parameterAsInt);
            Assert.That(command.CanExecute(parameterString), Is.True);

            // Check convertible parameter.
            Assert.That(command.CanExecute(parameterAsInt), Is.True);
            Assert.That(actionPerformed, Is.True);

            Assert.That(executeActionParam, Is.EqualTo(parameterString));
        }
Пример #3
0
        public void TestRelayCommandNoParamNoCanExecute()
        {
            bool actionPerformed = false;

            BaseCommand command = new RelayCommand(
                () => { actionPerformed = true; });

            Assert.That(command.HasCanExecuteFunction, Is.False);
            Assert.That(command.CanExecute(null), Is.True);
            command.Execute(null);

            Assert.That(command.CanExecute(null), Is.True);
            Assert.That(actionPerformed, Is.True);
        }