Composite command which allows several commands inside a single command being exposed to a view.
Inheritance: Command, ICompositeCommand
            public void CanExecuteEmptyCommandWithAtLeastOneMustBeExecutable(bool atLeastOneMustBeExecutable, bool expectedValue)
            {
                var compositeCommand = new CompositeCommand();
                compositeCommand.AtLeastOneMustBeExecutable = atLeastOneMustBeExecutable;

                Assert.AreEqual(expectedValue, ((ICatelCommand)compositeCommand).CanExecute(null));
            }
            public void RegistersCommandForExecution()
            {
                var vm = new CompositeCommandViewModel();
                var compositeCommand = new CompositeCommand(); 

                compositeCommand.RegisterCommand(vm.TestCommand1, vm);

                compositeCommand.Execute();

                Assert.IsTrue(vm.IsTestCommand1Executed);
            }
Exemple #3
0
            public void PreventsExecutionOfPartiallyExecutableCommand(bool checkCanExecuteOfAllCommandsToDetermineCanExecuteForCompositeCommand, bool expectedValue)
            {
                var compositeCommand = new CompositeCommand();

                compositeCommand.RegisterCommand(new Command(() => { }, () => false));
                compositeCommand.RegisterCommand(new Command(() => { }, () => true));

                compositeCommand.CheckCanExecuteOfAllCommandsToDetermineCanExecuteForCompositeCommand = checkCanExecuteOfAllCommandsToDetermineCanExecuteForCompositeCommand;

                Assert.AreEqual(expectedValue, ((ICatelCommand)compositeCommand).CanExecute(null));
            }
Exemple #4
0
            public CommandInfo(CompositeCommand compositeCommand, ICommand command, IViewModel viewModel)
            {
                _compositeCommand = compositeCommand;

                Command   = command;
                ViewModel = viewModel;

                if (viewModel != null)
                {
                    viewModel.ClosedAsync += OnViewModelClosedAsync;
                }
            }
            public void RegistersActionForExecution()
            {
                var compositeCommand = new CompositeCommand();

                bool executed = false;
                var action = new Action<object>(obj => executed = true);

                compositeCommand.RegisterAction(action);
                compositeCommand.Execute();

                Assert.IsTrue(executed);
            }
            public void AutomaticallyUnsubscribesCommandOnViewModelClosed()
            {
                var vm = new CompositeCommandViewModel();
                var compositeCommand = new CompositeCommand();

                compositeCommand.RegisterCommand(vm.TestCommand1, vm);

                Assert.IsFalse(vm.IsTestCommand1Executed);

                vm.CloseViewModel(false);

                compositeCommand.Execute();

                Assert.IsFalse(vm.IsTestCommand1Executed);
            }
Exemple #7
0
        /// <summary>
        /// Creates the command inside the command manager.
        /// <para />
        /// If the <paramref name="throwExceptionWhenCommandIsAlreadyCreated"/> is <c>false</c> and the command is already created, only
        /// the input gesture is updated for the existing command.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        /// <param name="inputGesture">The input gesture.</param>
        /// <param name="compositeCommand">The composite command. If <c>null</c>, this will default to a new instance of <see cref="CompositeCommand" />.</param>
        /// <param name="throwExceptionWhenCommandIsAlreadyCreated">if set to <c>true</c>, this method will throw an exception when the command is already created.</param>
        /// <exception cref="ArgumentException">The <paramref name="commandName" /> is <c>null</c> or whitespace.</exception>
        /// <exception cref="InvalidOperationException">The specified command is already created using the <see cref="CreateCommand" /> method.</exception>
        public void CreateCommand(string commandName, InputGesture inputGesture  = null, ICompositeCommand compositeCommand = null,
                                  bool throwExceptionWhenCommandIsAlreadyCreated = true)
        {
            Argument.IsNotNullOrWhitespace("commandName", commandName);

            lock (_lockObject)
            {
                Log.Debug("Creating command '{0}' with input gesture '{1}'", commandName, ObjectToStringHelper.ToString(inputGesture));

                if (_commands.ContainsKey(commandName))
                {
                    string error = string.Format("Command '{0}' is already created using the CreateCommand method", commandName);
                    Log.Error(error);

                    if (throwExceptionWhenCommandIsAlreadyCreated)
                    {
                        throw new InvalidOperationException(error);
                    }

                    _commandGestures[commandName] = inputGesture;
                    return;
                }

                if (compositeCommand == null)
                {
                    compositeCommand = new CompositeCommand();
                }

                _commands.Add(commandName, compositeCommand);
                _originalCommandGestures.Add(commandName, inputGesture);
                _commandGestures.Add(commandName, inputGesture);

                InvalidateCommands();

                CommandCreated.SafeInvoke(this, new CommandCreatedEventArgs(compositeCommand, commandName));
            }
        }
Exemple #8
0
        /// <summary>
        /// Creates the command inside the command manager.
        /// <para />
        /// If the <paramref name="throwExceptionWhenCommandIsAlreadyCreated"/> is <c>false</c> and the command is already created, only
        /// the input gesture is updated for the existing command.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        /// <param name="inputGesture">The input gesture.</param>
        /// <param name="compositeCommand">The composite command. If <c>null</c>, this will default to a new instance of <see cref="CompositeCommand" />.</param>
        /// <param name="throwExceptionWhenCommandIsAlreadyCreated">if set to <c>true</c>, this method will throw an exception when the command is already created.</param>
        /// <exception cref="ArgumentException">The <paramref name="commandName" /> is <c>null</c> or whitespace.</exception>
        /// <exception cref="InvalidOperationException">The specified command is already created using the <see cref="CreateCommand" /> method.</exception>
        public void CreateCommand(string commandName, InputGesture inputGesture = null, ICompositeCommand compositeCommand = null,
            bool throwExceptionWhenCommandIsAlreadyCreated = true)
        {
            Argument.IsNotNullOrWhitespace("commandName", commandName);

            lock (_lockObject)
            {
                Log.Debug("Creating command '{0}' with input gesture '{1}'", commandName, ObjectToStringHelper.ToString(inputGesture));

                if (_commands.ContainsKey(commandName))
                {
                    var error = string.Format("Command '{0}' is already created using the CreateCommand method", commandName);
                    Log.Error(error);

                    if (throwExceptionWhenCommandIsAlreadyCreated)
                    {
                        throw new InvalidOperationException(error);
                    }

                    _commandGestures[commandName] = inputGesture;
                    return;
                }

                if (compositeCommand == null)
                {
                    compositeCommand = new CompositeCommand();
                }

                _commands.Add(commandName, compositeCommand);
                _originalCommandGestures.Add(commandName, inputGesture);
                _commandGestures.Add(commandName, inputGesture);

                InvalidateCommands();

                CommandCreated.SafeInvoke(this, new CommandCreatedEventArgs(compositeCommand, commandName));
            }
        }
            public void ThrowsArgumentNullExceptionForNullAction()
            {
                var compositeCommand = new CompositeCommand();

                ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => compositeCommand.UnregisterAction((Action<object>)null));
            }
            public void ThrowsArgumentNullExceptionForNullCommand()
            {
                var compositeCommand = new CompositeCommand();

                ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => compositeCommand.RegisterCommand(null));
            }
            public void RegisteredActionsCanBeUnregistered_DynamicAction()
            {
                var compositeCommand = new CompositeCommand();

                compositeCommand.RegisterAction(RegisteredActionsCanBeUnregistered_TestMethod);
                compositeCommand.UnregisterAction(RegisteredActionsCanBeUnregistered_TestMethod);

                compositeCommand.Execute(null);

                Assert.IsFalse(_registeredActionsCanBeUnregistered_TestValue);
            }
            public void RegisteredActionsCanBeUnregistered_DefinedAction()
            {
                var invoked = false;
                Action action = () => invoked = true;

                var compositeCommand = new CompositeCommand();

                compositeCommand.RegisterAction(action);
                compositeCommand.UnregisterAction(action);

                compositeCommand.Execute(null);

                Assert.IsFalse(invoked);
            }
Exemple #13
0
            public CommandInfo(CompositeCommand compositeCommand, ICatelCommand command, IViewModel viewModel)
            {
                _compositeCommand = compositeCommand;

                Command = command;
                ViewModel = viewModel;

                if (viewModel != null)
                {
                    viewModel.Closed += OnViewModelClosed;
                }
            }
Exemple #14
0
        /// <summary>
        /// Creates the command inside the command manager.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        /// <param name="compositeCommand">The composite command. If <c>null</c>, this will default to a new instance of <see cref="CompositeCommand"/>.</param>
        /// <param name="throwExceptionWhenCommandIsAlreadyCreated">if set to <c>true</c>, this method will throw an exception when the command is already created.</param>
        /// <exception cref="ArgumentException">The <paramref name="commandName" /> is <c>null</c> or whitespace.</exception>
        /// <exception cref="InvalidOperationException">The specified command is already created using the <see cref="CreateCommand" /> method.</exception>
        public void CreateCommand(string commandName, ICompositeCommand compositeCommand = null,
            bool throwExceptionWhenCommandIsAlreadyCreated = true)
        {
            Argument.IsNotNullOrWhitespace("commandName", commandName);

            lock (_lockObject)
            {
                Log.Debug("Creating command '{0}'", commandName);

                if (_commands.ContainsKey(commandName))
                {
                    string error = string.Format("Command '{0}' is already created using the CreateCommand method", commandName);
                    Log.Error(error);

                    if (throwExceptionWhenCommandIsAlreadyCreated)
                    {
                        throw new InvalidOperationException(error);
                    }

                    return;
                }

                if (compositeCommand == null)
                {
                    compositeCommand = new CompositeCommand();
                }

                _commands.Add(commandName, compositeCommand);

                InvalidateCommands();

                CommandCreated.SafeInvoke(this, new CommandCreatedEventArgs(compositeCommand, commandName));
            }
        }