Exemplo n.º 1
0
        public ICommandHandler Create(ICraneCommand command)
        {
            var handler = _commandHandlers.FirstOrDefault(h => h.CanHandle(command));

            if (handler == null)
            {
                throw new MissingCommandHandlerException(string.Format("No handler found for command {0}.", command));
            }
            return(handler);
        }
Exemplo n.º 2
0
        public void can_get_a_commands_name_correctly(ICraneCommand command, string result)
        {
            "Given I have a command"
            ._(() => command = new Help());

            "When I get the command name"
            ._(() => result = command.Name());

            "It should be the type name in lower case"
            ._(() => result.Should().Be("help"));
        }
Exemplo n.º 3
0
        public void Creates_listcommands_command_when_null_arguments_passed(ICommandFactory commandFactory,
                                                                            ICraneCommand craneCommand)
        {
            "Given I have a command factory"
            ._(() => commandFactory = ServiceLocator.Resolve <ICommandFactory>());

            "When I create a command with no arguments"
            ._(() => craneCommand = commandFactory.Create(null));

            "Then the command returned should be the list commands command"
            ._(() => craneCommand.Should().BeOfType <ListCommands>());
        }
Exemplo n.º 4
0
        public void Creates_command_when_arguments_passed_by_switches(ICommandFactory commandFactory,
                                                                      ICraneCommand craneCommand)
        {
            "Given I have a command factory"
            ._(() => commandFactory = ServiceLocator.Resolve <ICommandFactory>());

            "When I create a command with based on the arguments 'init testproject"
            ._(() => craneCommand = commandFactory.Create("init", "-projectName", "testproject"));

            "Then the command returned should be the init command"
            ._(() => craneCommand.Should().BeOfType <Init>());

            "And the ProjectName should be testproject"
            ._(() => ((Init)craneCommand).ProjectName.Should().Be("testproject"));
        }
Exemplo n.º 5
0
 private bool NotHidden(ICraneCommand arg)
 {
     return(arg.GetType().GetCustomAttribute <HiddenCommandAttribute>() == null);
 }
Exemplo n.º 6
0
 public static string Name(this ICraneCommand value)
 {
     return(value.GetType().Name.ToLowerInvariant());
 }
Exemplo n.º 7
0
 private void CreateCommandPage(ICraneCommand command)
 {
     _fileManager.WriteAllText(Path.Combine(_docDirectory, command.Name() + ".md"),
                               _helpFormatter.Format(_helpProvider.HelpCollection.Get(command.Name())));
 }
 public void Handle(ICraneCommand craneCommand)
 {
     throw new NotImplementedException();
 }
 public bool CanHandle(ICraneCommand command)
 {
     return(false);
 }
Exemplo n.º 10
0
 private static bool ShowSuccess(ICraneCommand command)
 {
     return(!(command is ListCommands || command is Help));
 }
Exemplo n.º 11
0
        public void Handle(ICraneCommand craneCommand)
        {
            var command = craneCommand as TCommand;

            DoHandle(command);
        }
Exemplo n.º 12
0
 public bool CanHandle(ICraneCommand command)
 {
     return(command is TCommand);
 }
Exemplo n.º 13
0
        public void can_retrieve_command_help_specifying_a_commands_short_name(CommandHelpCollection help, ICraneCommand command, ICommandHelp result)
        {
            "Given I have a help collection"
            ._(() => help = new CommandHelpCollection(new Dictionary <string, ICommandHelp>
            {
                { "init", new CommandHelp("init", "Crane.Core.Commands.Init", "Initializes things", null) },
                { "help", new CommandHelp("help", "Crane.Core.Commands.Help", "Helps things", null) },
            }));

            "When I retrieve the command help using a short name"
            ._(() => result = help.Get("help"));

            "Then it should retrieve the command help associated with that type"
            ._(() => result.CommandName.Should().Be("help"));
        }