Пример #1
0
        public void TestRaiseCanExecuteChangedWithoutHandler()
        {
            var cmd = new AsyncRelayCommand(() => Task.CompletedTask);

            // "assert" that this does not throw
            cmd.RaiseCanExecuteChanged();
        }
Пример #2
0
        public void RaiseCanExecuteChangedRaisesCanExecuteChanged()
        {
            var handlers = new AsyncDelegateObjectHandlers();
            var command  = new AsyncRelayCommand <object>(async o => await handlers.Execute(o), o => false);
            var canExecuteChangedRaised = false;

            command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; };

            command.RaiseCanExecuteChanged();
            Assert.True(canExecuteChangedRaised);
        }
        public MainWindowModel()
        {
            UploadCommand = new AsyncRelayCommand(UploadAsync, () =>
                                                  !string.IsNullOrEmpty(ApiServer) &&
                                                  !string.IsNullOrEmpty(CustomerAlias) &&
                                                  !string.IsNullOrEmpty(FilePath));

            PropertyChanged += (sender, args) => UploadCommand.RaiseCanExecuteChanged();

            RegisterContextMenuCommand   = new AsyncRelayCommand(RegisterContextMenuAsync);
            UnregisterContextMenuCommand = new AsyncRelayCommand(UnregisterContextMenuAsync);
        }
Пример #4
0
        public void CanRemoveCanExecuteChangedHandler()
        {
            var command = new AsyncRelayCommand <object>(async o => await Task.Yield());
            var canExecuteChangedRaised = false;

            void Handler(object s, EventArgs e) => canExecuteChangedRaised = true;

            command.CanExecuteChanged += Handler;
            command.CanExecuteChanged -= Handler;
            command.RaiseCanExecuteChanged();

            Assert.False(canExecuteChangedRaised);
        }
Пример #5
0
        public void TestRaiseCanExecuteChanged()
        {
            var cmd = new AsyncRelayCommand(() => Task.CompletedTask);

            int eventFiredCount = 0;

            cmd.CanExecuteChanged += (sender, e) =>
            {
                eventFiredCount++;
            };

            cmd.RaiseCanExecuteChanged();

            Assert.AreEqual(1, eventFiredCount);
        }