public void Given_valid_command_returns_correct_command_type(string command, CommandType expectedCommandType) { var commandMatcher = new CommandMatcher(); var commandType = commandMatcher.GetCommandType(command); Assert.AreEqual(expectedCommandType, commandType); }
public void Throw_Invalid_Command_Exception_Given_Invalid_Command(string invalidCommand) { var commandMatcher = new CommandMatcher(); Assert.Throws <InvalidCommandException>( () => commandMatcher.GetCommandType(invalidCommand)); }
public void Given_invalid_command_throws_CommandException(string invalidCommand) { var commandMatcher = new CommandMatcher(); Assert.Throws <CommandException>( () => commandMatcher.GetCommandType(invalidCommand)); }
public void StartLineEditor() { LineEditor le = new LineEditor("LineEditor", 50); le.AutoCompleteEvent = (string text, int pos) => { //text = text.ToLower(); string token = null; for (int i = pos - 1; i >= 0; i--) { if (Char.IsWhiteSpace(text[i])) { token = text.Substring(i + 1, pos - i - 1); break; } else if (i == 0) { token = text.Substring(0, pos); } } List <string> results = new List <string>(); if (token == null) { token = string.Empty; results.AddRange(CommandMatcher.AutoComplete.Select(x => x.Path).ToArray()); } else { string[] completePaths = CommandMatcher.AutoComplete .Where(x => x.Path.Length > pos) .Select(x => x.Path.Substring(pos - token.Length)) .ToArray(); for (int i = 0; i < completePaths.Length; i++) { if (completePaths[i].StartsWith(token)) { string result = completePaths[i]; results.Add(result.Substring(token.Length, result.Length - token.Length)); } } } return(new LineEditor.Completion(token, results.ToArray())); }; string s; while ((s = le.Edit("> ", "")) != null) { if (new[] { "exit", "quit", "bye", "q", "e" }.Contains(s)) { break; } CommandMatcher.CallAction(s); } }
public void Should_CommandMatcher_Return_Expected_CommandType() { var commandMatcher = new CommandMatcher(); var areaCommandType = commandMatcher.GetCommandType("5 5"); areaCommandType.Should().BeEquivalentTo(CommandType.AreaCommand); var moveCommandType = commandMatcher.GetCommandType("LMLMLMLMMM"); moveCommandType.Should().BeEquivalentTo(CommandType.MoveCommand); }
public void Should_CommandMatcher_Throw_InvalidCommandStringException() { //Arrange var commandMatcher = new CommandMatcher(); //Act Action action = () => { var response = commandMatcher.GetCommandType("5 5xxxxxxx"); }; //Assert action.Should().Throw <InvalidCommandStringException>(); }
public void Start(string[] args) { var commandMatcher = new CommandMatcher(args); var command = _commandFactory.GetCommand(commandMatcher.CommandName); if (command != null) { _commandPropertyWalker.FillCommandProperties(args, command); } var nonInteractive = command != null && command.NonInteractive; var exit = false; TryToProceedCommand(command, args); while (!nonInteractive && !exit) { Console.WriteLine("Enter commands or type exit to close"); if (!nonInteractive) { var input = Console.ReadLine(); if (!string.IsNullOrEmpty(input)) { if (input.ToLower() == "exit") { exit = true; } else { var tempArgs = input.Split(' '); command = _commandFactory.GetCommand(new CommandMatcher(tempArgs).CommandName); if (TryToProceedCommand(command, tempArgs)) { nonInteractive = command.NonInteractive; } } } } } }
internal Commander() { _matcher = new CommandMatcher <TContext>(); _execution = new CommandExecution <TContext>(); }
public void Given_invalid_command_throws_CommandException(string invalidCommand) { var commandMatcher = new CommandMatcher(); Assert.Throws<CommandException>( () => commandMatcher.GetCommandType(invalidCommand)); }