CreateCommand() public method

Creates the command inside the command manager. If the throwExceptionWhenCommandIsAlreadyCreated is false and the command is already created, only the input gesture is updated for the existing command.
The is null or whitespace. The specified command is already created using the method.
public CreateCommand ( string commandName, Catel.Windows.Input.InputGesture inputGesture = null, ICompositeCommand compositeCommand = null, bool throwExceptionWhenCommandIsAlreadyCreated = true ) : void
commandName string Name of the command.
inputGesture Catel.Windows.Input.InputGesture The input gesture.
compositeCommand ICompositeCommand The composite command. If null, this will default to a new instance of .
throwExceptionWhenCommandIsAlreadyCreated bool if set to true, this method will throw an exception when the command is already created.
return void
Example #1
0
            public void ThrowsInvalidOperationExceptionForAlreadyCreatedCommand()
            {
                var commandManager = new CommandManager();

                commandManager.CreateCommand("MyCommand");

                ExceptionTester.CallMethodAndExpectException<InvalidOperationException>(() => commandManager.CreateCommand("MyCommand"));
            }
Example #2
0
            public void ReturnsTrueForCreatedCommand()
            {
                var commandManager = new CommandManager();

                commandManager.CreateCommand("MyCommand");

                Assert.IsTrue(commandManager.IsCommandCreated("MyCommand"));
            }
Example #3
0
            public void CorrectlyCreatesTheCommand()
            {
                var commandManager = new CommandManager();

                commandManager.CreateCommand("MyCommand");

                Assert.IsTrue(commandManager.IsCommandCreated("MyCommand"));
            }
Example #4
0
            public void ThrowsArgumentNullExceptionForWhitespaceCommandName()
            {
                var commandManager = new CommandManager();

                ExceptionTester.CallMethodAndExpectException<ArgumentException>(() => commandManager.CreateCommand(" "));
            }
Example #5
0
            public void DoesNotExecuteUnregisteredCommands()
            {
                var vm = new CompositeCommandViewModel();
                var commandManager = new CommandManager();

                commandManager.CreateCommand("MyCommand");
                commandManager.RegisterCommand("MyCommand", vm.TestCommand1);

                Assert.IsTrue(commandManager.IsCommandCreated("MyCommand"));

                commandManager.UnregisterCommand("MyCommand", vm.TestCommand1);

                commandManager.ExecuteCommand("MyCommand");

                Assert.IsFalse(vm.IsTestCommand1Executed);
            }
Example #6
0
            public void ExecutesRegisteredCommands()
            {
                var vm = new CompositeCommandViewModel();
                var commandManager = new CommandManager();

                commandManager.CreateCommand("MyCommand");
                commandManager.RegisterCommand("MyCommand", vm.TestCommand1);

                commandManager.ExecuteCommand("MyCommand");

                Assert.IsTrue(vm.IsTestCommand1Executed);
            }
Example #7
0
            public void ReturnsCommandForCreatedCommand()
            {
                var commandManager = new CommandManager();

                commandManager.CreateCommand("MyCommand");

                Assert.IsNotNull(commandManager.GetCommand("MyCommand"));
            }
            public void RegisteredActionsCanBeUnregistered_DynamicAction()
            {
                var commandManager = new CommandManager();

                commandManager.CreateCommand("TestAction");

                commandManager.RegisterAction("TestAction", RegisteredActionsCanBeUnregistered_TestMethod);
                commandManager.UnregisterAction("TestAction", RegisteredActionsCanBeUnregistered_TestMethod);

                commandManager.ExecuteCommand("TestAction");

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

                var commandManager = new CommandManager();

                commandManager.CreateCommand("TestAction");

                commandManager.RegisterAction("TestAction", action);
                commandManager.UnregisterAction("TestAction", action);

                commandManager.ExecuteCommand("TestAction");

                Assert.IsFalse(invoked);
            }