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); }
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")); }
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>()); }
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")); }
private bool NotHidden(ICraneCommand arg) { return(arg.GetType().GetCustomAttribute <HiddenCommandAttribute>() == null); }
public static string Name(this ICraneCommand value) { return(value.GetType().Name.ToLowerInvariant()); }
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); }
private static bool ShowSuccess(ICraneCommand command) { return(!(command is ListCommands || command is Help)); }
public void Handle(ICraneCommand craneCommand) { var command = craneCommand as TCommand; DoHandle(command); }
public bool CanHandle(ICraneCommand command) { return(command is TCommand); }
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")); }