Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
            });
        }