Inheritance: ICmdRConsole
Beispiel #1
0
        public void Run_Help()
        {
            //todo: use moq to fake the console & state
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.AutoRegisterCommands();
            cmdR.RegisterRoute("cd", (p, con, state) =>
            {
                state.CmdPrompt = "new prompt> ";
            });

            cmdR.Run(new[] { "?" });

            Assert.AreEqual("basic-module1       ", console.ConsoleWindow[0]);
            Assert.AreEqual("basic-module2       ", console.ConsoleWindow[1]);
            Assert.AreEqual("attribute-module1   ", console.ConsoleWindow[2]);
            Assert.AreEqual("attribute-module2   ", console.ConsoleWindow[3]);
            Assert.AreEqual("?                   ", console.ConsoleWindow[4]);
            Assert.AreEqual("cd                  ", console.ConsoleWindow[5]);
            Assert.AreEqual("", console.ConsoleWindow[6]);
            Assert.AreEqual("> ", console.ConsoleWindow[7]);
            Assert.AreEqual("> ", console.ConsoleWindow[8]);
        }
Beispiel #2
0
        public void AutoRegisterCommands_CanInvokeAttributeModuleRouteTwo()
        {
            var fakeConsole = new FakeCmdRConsole("");

            var cmdR = new CmdR(console: fakeConsole);
            cmdR.AutoRegisterCommands();
            cmdR.Run(new string[] { "attribute-module2" });


            Assert.AreEqual("attribute-test2", fakeConsole.ConsoleWindow[0]);
        }
Beispiel #3
0
        public void AutoRegisterCommands_CanInvokeBasicModuleRouteOne()
        {
            var fakeConsole = new FakeCmdRConsole("");

            var cmdR = new CmdR(console: fakeConsole);
            cmdR.AutoRegisterCommands();
            cmdR.Run(new string[] { "basic-module1" });


            Assert.AreEqual("module-test1", fakeConsole.ConsoleWindow[0]);
        }
Beispiel #4
0
        public void AutoRegisterCommands_CanInvokeAttributeModuleRouteTwo()
        {
            var fakeConsole = new FakeCmdRConsole("");

            var cmdR = new CmdR(console: fakeConsole);

            cmdR.AutoRegisterCommands();
            cmdR.Run(new string[] { "attribute-module2" });


            Assert.AreEqual("attribute-test2", fakeConsole.ConsoleWindow[0]);
        }
Beispiel #5
0
        public void AutoRegisterCommands_CanInvokeBasicModuleRouteOne()
        {
            var fakeConsole = new FakeCmdRConsole("");

            var cmdR = new CmdR(console: fakeConsole);

            cmdR.AutoRegisterCommands();
            cmdR.Run(new string[] { "basic-module1" });


            Assert.AreEqual("module-test1", fakeConsole.ConsoleWindow[0]);
        }
Beispiel #6
0
        public void Run_PrintsOutTheCommandPromptAfterRunningACommand()
        {
            //todo: use moq to fake the console & state
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.RegisterRoute("cd", (p, con, s) => con.Write("hello!"));

            cmdR.Run(new string[] { "cd" });

            Assert.AreEqual("> ", console.ConsoleWindow[1]);
        }
Beispiel #7
0
        public void Run_ExecutesACommandPassedInOnTheCommandLine()
        {
            //todo: use moq to fake the console & state
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.RegisterRoute("cd", (p, con, s) => con.Write("hello!"));

            cmdR.Run(new string[] { "cd" });

            Assert.AreEqual("hello!", console.ConsoleWindow[0]);
        }
Beispiel #8
0
        public void Run_SplitsInitialCommandsOnTheCommandSeparator()
        {
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.RegisterRoute("first", (p, con, s) => con.Write("First Command"));
            cmdR.RegisterRoute("second", (p, con, s) => con.Write("Second Command"));

            cmdR.Run(new string[] { "first", CmdRExtensions.COMMAND_SEPARATOR, "second" });

            Assert.AreEqual("First Command", console.ConsoleWindow[0]);
            Assert.AreEqual("Second Command", console.ConsoleWindow[1]);
        }
Beispiel #9
0
        public void Run_WeCanModifyTheCommandPromptAndItsWrittenToTheConsole()
        {
            //todo: use moq to fake the console & state
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.RegisterRoute("cd", (p, con, state) =>
            {
                state.CmdPrompt = "new prompt> ";
            });

            cmdR.Run(new string[] { "cd" });

            Assert.AreEqual("new prompt> ", console.ConsoleWindow[0]);
        }
Beispiel #10
0
        public void Run_DoubleEscapedCommandSeparatorNotUsedInCommand()
        {
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.RegisterRoute("first &", (p, con, s) => con.Write("First Command"));
            cmdR.RegisterRoute("second", (p, con, s) => con.Write("Second Command"));

            var doubleEscapedCommandSeparator = CmdRExtensions.ESCAPE_CHAR + CmdRExtensions.ESCAPE_CHAR + CmdRExtensions.COMMAND_SEPARATOR;

            cmdR.Run(new[] { "first", doubleEscapedCommandSeparator, CmdRExtensions.COMMAND_SEPARATOR, "second" });

            Assert.AreEqual("First Command", console.ConsoleWindow[0]);
            Assert.AreEqual("Second Command", console.ConsoleWindow[1]);
        }
Beispiel #11
0
        public void Run_HelpWithDetails()
        {
            //todo: use moq to fake the console & state
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.AutoRegisterCommands();
            cmdR.RegisterRoute("cd", (p, con, state) =>
            {
                state.CmdPrompt = "new prompt> ";
            }, "changes directory");

            cmdR.Run(new[] { "? cd" });

            Assert.AreEqual("  cd", console.ConsoleWindow[0]);
            Assert.AreEqual("  changes directory", console.ConsoleWindow[1]);
        }
Beispiel #12
0
        public void Run_PrintsOutTheCommandPromptAfterRunningACommand()
        {
            //todo: use moq to fake the console & state
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.RegisterRoute("cd", (p, con, s) => con.Write("hello!"));

            cmdR.Run(new string[] { "cd" });

            Assert.AreEqual("> ", console.ConsoleWindow[1]);
        }
Beispiel #13
0
        public void Run_ExecutesACommandPassedInOnTheCommandLine()
        {
            //todo: use moq to fake the console & state
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.RegisterRoute("cd", (p, con, s) => con.Write("hello!"));

            cmdR.Run(new string[] { "cd" });

            Assert.AreEqual("hello!", console.ConsoleWindow[0]);
        }
Beispiel #14
0
        public void Run_HelpWithDetails()
        {
            //todo: use moq to fake the console & state
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());
            cmdR.AutoRegisterCommands();
            cmdR.RegisterRoute("cd", (p, con, state) =>
            {
                state.CmdPrompt = "new prompt> ";
            }, "changes directory");

            cmdR.Run(new[] { "? cd" });

            Assert.AreEqual("  cd", console.ConsoleWindow[0]);
            Assert.AreEqual("  changes directory", console.ConsoleWindow[1]);
        }
Beispiel #15
0
        public void Run_Help()
        {
            //todo: use moq to fake the console & state
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());
            cmdR.AutoRegisterCommands();
            cmdR.RegisterRoute("cd", (p, con, state) =>
                {
                    state.CmdPrompt = "new prompt> ";
                });

            cmdR.Run(new[] { "?" });

            Assert.AreEqual("basic-module1       ", console.ConsoleWindow[0]);
            Assert.AreEqual("basic-module2       ", console.ConsoleWindow[1]);
            Assert.AreEqual("attribute-module1   ", console.ConsoleWindow[2]);
            Assert.AreEqual("attribute-module2   ", console.ConsoleWindow[3]);
            Assert.AreEqual("?                   ", console.ConsoleWindow[4]);
            Assert.AreEqual("cd                  ", console.ConsoleWindow[5]);
            Assert.AreEqual("", console.ConsoleWindow[6]);
            Assert.AreEqual("> ", console.ConsoleWindow[7]);
            Assert.AreEqual("> ", console.ConsoleWindow[8]);
        }
Beispiel #16
0
        public void Run_WeCanModifyTheCommandPromptAndItsWrittenToTheConsole()
        {
            //todo: use moq to fake the console & state
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.RegisterRoute("cd", (p, con, state) =>
                {
                    state.CmdPrompt = "new prompt> ";
                });

            cmdR.Run(new string[] { "cd" });

            Assert.AreEqual("new prompt> ", console.ConsoleWindow[0]);
        }
Beispiel #17
0
        public void Run_DoubleEscapedCommandSeparatorNotUsedInCommand()
        {
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.RegisterRoute("first &", (p, con, s) => con.Write("First Command"));
            cmdR.RegisterRoute("second", (p, con, s) => con.Write("Second Command"));

            var doubleEscapedCommandSeparator = CmdRExtensions.ESCAPE_CHAR + CmdRExtensions.ESCAPE_CHAR + CmdRExtensions.COMMAND_SEPARATOR;
            cmdR.Run(new[] { "first", doubleEscapedCommandSeparator, CmdRExtensions.COMMAND_SEPARATOR, "second" });

            Assert.AreEqual("First Command", console.ConsoleWindow[0]);
            Assert.AreEqual("Second Command", console.ConsoleWindow[1]);
        }
Beispiel #18
0
        public void Run_SplitsInitialCommandsOnTheCommandSeparator()
        {
            var console = new FakeCmdRConsole("");

            var cmdR = new CmdR(new OrderedCommandParser(), new Routing(), new RouteParser(), console, new CmdRState());

            cmdR.RegisterRoute("first", (p, con, s) => con.Write("First Command"));
            cmdR.RegisterRoute("second", (p, con, s) => con.Write("Second Command"));

            cmdR.Run(new string[] { "first", CmdRExtensions.COMMAND_SEPARATOR, "second" });

            Assert.AreEqual("First Command", console.ConsoleWindow[0]);
            Assert.AreEqual("Second Command", console.ConsoleWindow[1]);
        }