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

            Assert.AreEqual(true, command.CanExecute("CanExecute"));
            Assert.AreEqual(false, command.CanExecute("Hello"));
        }
示例#2
0
        public void CanExecuteTest()
        {
            var canExecute = true;

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

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

            canExecute = false;

            Assert.AreEqual(false, command.CanExecute(null));
        }
示例#3
0
        public void CanExecuteTestNull()
        {
            var command = new RelayCommand(() =>
            {
            });

            Assert.AreEqual(true, command.CanExecute(null));
        }
        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 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));
        }
示例#7
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IDataService dataService)
        {
            _dataService = dataService;

            Users = new ObservableCollection<User>();
            ReadAllUsersCommand = new RelayCommand(GetUsers);

            //Execute ReadAllUsersCommand to display all users on the main window when the application launches
            if (ReadAllUsersCommand.CanExecute(null))
                ReadAllUsersCommand.Execute(null);

            SearchUsersCommand = new RelayCommand(SearchUsers);

            SendUserCommand = new RelayCommand(SendUser);

            ReceiveRefreshUsersMessage();
        }
        public void CanExecuteTestInvalidParameterType()
        {
            var command = new RelayCommand<string>(
                p =>
                {
                },
                p => p == "CanExecute");

            try
            {
                command.CanExecute(DateTime.Now);
                Assert.Fail("InvalidCastException was not thrown");
            }
            catch (InvalidCastException)
            {
            }
        }
        public void TestCanExecuteWithInvalidParameterType()
        {
            var command = new RelayCommand<string>(
                p =>
                {
                },
                p => p == "CanExecute");

            var result = command.CanExecute(DateTime.Now);
            Assert.IsFalse(result);
        }