Exemple #1
0
        public void WhenExecuteCommandWhichNotExtis_CommandManager_ShouldThrowException()
        {
            string aliasName         = "myalias";
            string commandName       = "mycommand";
            var    storedDataService = new StoredDataServiceMock(true);

            var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            var commandDefinition = new AddAliasCommand(storedDataService, instance.Commands);

            instance.RegisterCommand(commandDefinition);


            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandNameParameter.GetInvokeName(),
                commandName,
                commandDefinition.CommandAliasParameter.GetInvokeName(),
                aliasName);

            Assert.Throws <CommandNotFoundException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
Exemple #2
0
        public void WhenExecuteCommand_CommandManager_ShouldAddAlias()
        {
            string aliasName          = "myalias";
            string commandName        = "mycommand";
            string commandNamespace   = "name.space";
            string commandDescription = "description";

            var storedDataService = new StoredDataServiceMock(false);

            var mockCommand = new CommandMock(commandNamespace, commandName, commandDescription);
            var instance    = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(mockCommand);

            var commandDefinition = new AddAliasCommand(storedDataService, instance.Commands);

            instance.RegisterCommand(commandDefinition);


            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandNameParameter.GetInvokeName(),
                mockCommand.GetInvocationCommandName(),
                commandDefinition.CommandAliasParameter.GetInvokeName(),
                aliasName);

            instance.ExecuteInputRequest(inputRequest);

            var storedAlias = storedDataService.AddedCommand == mockCommand.GetInvocationCommandName();

            var actual = storedAlias;

            Assert.True(actual);
        }
Exemple #3
0
        public void WhenExecuteCommandWithRepeatedAliasParameter_CommandManager_ShouldThrowException()
        {
            string aliasName          = "myalias";
            string commandName        = "mycommand";
            string commandNamespace   = "name.space";
            string commandDescription = "description";
            var    storedDataService  = new StoredDataServiceMock(true);

            var mockCommand = new CommandMock(commandNamespace, commandName, commandDescription);
            var instance    = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(mockCommand);


            var commandDefinition = new AddAliasCommand(storedDataService, instance.Commands);

            instance.RegisterCommand(commandDefinition);


            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandNameParameter.GetInvokeName(),
                mockCommand.GetInvocationCommandName(),
                commandDefinition.CommandAliasParameter.GetInvokeName(),
                aliasName);

            Assert.Throws <AliasRepeatedException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
Exemple #4
0
        public void WhenExecuteCommandWithoutCommandParameter_CommandManager_ShouldThrowException()
        {
            string aliasName = "myalias";

            var storedDataService  = new StoredDataServiceMock(false);
            var registeredCommands = new List <CommandBase>();
            var commandDefinition  = new AddAliasCommand(storedDataService, registeredCommands);

            var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandAliasParameter.GetInvokeName(),
                aliasName);

            Assert.Throws <InvalidParamsException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }