private void WhenTheUserDoesNotSpecifyACommandThenShowAvailableCommands(List <ConsoleCommand> commands, StringWriter writer,
                                                                                ConsoleCommand firstcommand,
                                                                                ConsoleCommand secondCommand, string[] arguments)
        {
            // when the user does not specify a command
            ConsoleCommandDispatcher.DispatchCommand(commands, arguments, writer);

            // then the output contains a list of available commands
            var output = writer.ToString();

            MyStringAssert.ContainsInOrder(output, firstcommand.Command,
                                           firstcommand.OneLineDescription,
                                           secondCommand.Command,
                                           secondCommand.OneLineDescription);
        }
예제 #2
0
        public void RepeatedlyDispatchingCommand()
        {
            var trace = new StringWriter();

            ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "1", "-y", "2" }, new StringWriter());
            ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "3" }, new StringWriter());
            ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-y", "4" }, new StringWriter());
            ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move" }, new StringWriter());

            // all parameters are evaluated independently
            MyStringAssert.ContainsInOrder(trace.ToString(),
                                           "You walk to 1, 2 and find a maze of twisty little passages, all alike.",
                                           "You walk to 3, 0 and find a maze of twisty little passages, all alike.",
                                           "You walk to 0, 4 and find a maze of twisty little passages, all alike.",
                                           "You walk to 0, 0 and find a maze of twisty little passages, all alike."
                                           );
        }
        private void ShouldShowHelpWhenRequested(List <ConsoleCommand> commands, string[] consoleArguments)
        {
            var writer = new StringWriter();

            // when we call a command, asking for help
            var commandC = new TestCommand()
                           .IsCommand("command-c", "one line description for C")
                           .HasLongDescription(
                @"Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.")
                           .HasAdditionalArguments(0, "<remaining> <args>")
                           .HasOption("o|option=", "option description", v => { });

            commands.Add(commandC);

            var exitCode = ConsoleCommandDispatcher.DispatchCommand(commands, consoleArguments, writer);

            // then the output contains a all help available for that command
            var output = writer.ToString();

            MyStringAssert.ContainsInOrder(output,
                                           commandC.Command,
                                           commandC.OneLineDescription,
                                           commandC.LongDescription,
                                           commandC.RemainingArgumentsHelpText,
                                           "-o",
                                           "--option",
                                           "option description");

            Assert.AreEqual(-1, exitCode);
        }