public void capture_standard_output() { //Arrange var asFound = Console.Out; try { var current_level = new nutility.InputInstanceReplLevel("UC-2", new cli1.RootInput()); var tree = new nutility.Tree <string, nutility.InputReplLevel> { Value = current_level }; var input_lines = new[] { "-f1 -n=-132" }; var reader = new StringReader(Common.asTextContent(input_lines)); var writer = new StringWriter(); Console.SetOut(writer); var repl = new nutility.REPL { Reader = reader, Writer = writer }; //Act repl.Loop(tree); //Assert Assert.IsTrue($"{writer}".Contains("N: -132")); } finally { Console.SetOut(asFound); } }
public void capture_TextWriter() { //Arrange var input_lines = new[] { "x1 -f1 -n=43" }; var reader = new StringReader(Common.asTextContent(input_lines)); var repl = new nutility.REPL { Reader = reader }; var level_writer = new StringWriter(); var current_level = new nutility.InputInstanceReplLevel("x1", new InputY(level_writer)); var tree = new nutility.Tree <string, nutility.InputReplLevel> { Value = current_level }; //Act repl.Loop(tree); //Assert Assert.AreEqual("N: 43\r\n", $"{level_writer}"); }
public void basic() { //Arrange var current_level = new nutility.InputClassReplLevel("UC-1", typeof(InputX)); var tree = new nutility.Tree <string, nutility.InputReplLevel> { Value = current_level }; var input_lines = new[] { "new x1", "?" }; var reader = new StringReader(Common.asTextContent(input_lines)); var writer = new StringWriter(); var repl = new nutility.REPL { Reader = reader, Writer = writer }; //Act repl.Loop(tree); //Assert Assert.IsTrue($"{writer}".Contains($"x1 ({typeof(InputX).FullName})")); }
public static void MainEntryPoint(string[] args, TextReader reader = null, TextWriter writer = null, int consoleWindowWidth = 20) { try { if (reader == null) { reader = Console.In; } if (writer == null) { writer = Console.Out; } if (Environment.UserInteractive) { WriteLine($"Hello, {Environment.UserDomainName}\\{Environment.UserName} !!!"); Write($"PID: {System.Diagnostics.Process.GetCurrentProcess().Id} Thread: {System.Threading.Thread.CurrentThread.ManagedThreadId} Culture: {System.Threading.Thread.CurrentThread?.CurrentUICulture?.Name}, {System.Threading.Thread.CurrentThread?.CurrentCulture?.Name}\n"); } /*if (!(args?.Any() == true) || args?.First().Contains("?") == true) * { * WriteLine($"Working with {GetHostProcessName()}:"); * nutility.Switch.ShowUsage(typeof(RootInput)); * } * else*/ { var mvp = new nutility.InputClassReplLevel("MVP", typeof(RootInput)); var use_case_hierarchy_root = new nutility.Tree <string, nutility.InputReplLevel> { Value = mvp }; var uc2 = new nutility.InputClassReplLevel("UC2", typeof(InputUC2)); use_case_hierarchy_root[uc2.ID] = new nutility.Tree <string, nutility.InputReplLevel> { Value = uc2, Parent = use_case_hierarchy_root }; var uc3 = new nutility.InputClassReplLevel("UC3", typeof(InputUC3)); use_case_hierarchy_root[uc3.ID] = new nutility.Tree <string, nutility.InputReplLevel> { Value = uc3, Parent = use_case_hierarchy_root }; var repl = new nutility.REPL { Reader = reader, Writer = writer, ConsoleWindowWidth = consoleWindowWidth }; repl.Loop(use_case_hierarchy_root); } } catch (Exception ex) { for (int level = 0; ex != null; ex = ex.InnerException, ++level) { writer.WriteLine($"\r\n[Level {level}] {ex.GetType().FullName}: {ex.Message} {ex.StackTrace}"); } } string GetHostProcessName() { var result = Environment.GetCommandLineArgs()?.FirstOrDefault(); if (!string.IsNullOrWhiteSpace(result)) { result = System.IO.Path.GetFileNameWithoutExtension(result); } return(result); } }