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]); }
public void AutoRegisterCommands_CanInvokeBasicModuleRouteTwo() { var fakeConsole = new FakeCmdRConsole(""); var cmdR = new CmdR(console: fakeConsole); cmdR.AutoRegisterCommands(); cmdR.Run(new string[] { "basic-module2" }); Assert.AreEqual("module-test2", fakeConsole.ConsoleWindow[0]); }
public void AutoRegisterCommands_CanInvokeAttributeModuleRouteOne() { var fakeConsole = new FakeCmdRConsole(""); var cmdR = new CmdR(console: fakeConsole); cmdR.AutoRegisterCommands(); cmdR.Run(new string[] { "attribute-module1" }); Assert.AreEqual("attribute-test1", fakeConsole.ConsoleWindow[0]); }
static void Main(string[] args) { var cmdR = new CmdR("> ", new [] { "exit" }); cmdR.Console.WriteLine("Welcome to Midlands Bank Plc"); cmdR.Console.WriteLine("----------------------------"); cmdR.Console.WriteLine("type ? for help on available commands\n"); cmdR.AutoRegisterCommands(); cmdR.Run(args); }
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]); }
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]); }
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]); }
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]); }
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]); }
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]); }
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]); }
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]); }
static void Main(string[] args) { // the class which contains all our logic var example = new DOSPromptReplication(); // creating the CmdR class passing, specifying the command prompt (> ) to use and a list of exit codes (exit) the user can type to exit the cmdR loop // these are the system defaults, so they dont actually need to be passed in var cmdR = new CmdR("> ", new string[] { "exit" }); // setting up the command routes cmdR.RegisterRoute("cd path", example.ChangeDirectory, "change current directory"); cmdR.RegisterRoute("ls filter?", example.ListDirectory, "list the contents of the current directory, optionaly specify a filter to search for contents within the directory"); cmdR.RegisterRoute("del file", example.DeleteFile, "delete the sepcified file"); cmdR.RegisterRoute("cls", example.Clear, "Clears the screen."); // registering a route with a lambda cmdR.RegisterRoute("echo text", (parameters, console, state) => console.WriteLine(parameters["text"]), "print the specified text to the console"); // start the cmdR loop passing in the args as the first command to execute cmdR.Run(args); }