public void Reentry_Submenu() { var console = new TestConsole(); console.AddUserInput(ConsoleKey.D1); console.AddUserInputWithActionBefore(ConsoleKey.D1, () => { AssertHelper.Equal(@"Pick an option: [0] One >> [1] Close ", console.ToString()); }); // open submenu once again console.AddUserInputWithActionBefore(ConsoleKey.D1, () => { AssertHelper.Equal(@"Pick an option: [0] Sub_One >> [1] Sub_Close ", console.ToString()); }); console.AddUserInputWithActionBefore(ConsoleKey.D1, () => { AssertHelper.Equal(@"Pick an option: [0] One >> [1] Close ", console.ToString()); }); var submenu = new ConsoleMenu() { Console = console } .Add("Sub_One", () => { }) .Add("Sub_Close", ConsoleMenu.Close) .Configure(m => { ConfigHelper.BaseTestConfiguration(m, console); }); var menu = new ConsoleMenu() { Console = console } .Add("One", submenu.Show) .Add("Close", ConsoleMenu.Close) .Configure(m => { ConfigHelper.BaseTestConfiguration(m, console); }); menu.Show(); AssertHelper.Equal(@"Pick an option: [0] One >> [1] Close ", console.ToString()); }
public void PreSelected_OpenSubmenu() { var console = new TestConsole(); var submenu = new ConsoleMenu(args: new[] { "--menu-select=0" }, level: 1) { Console = console } .Add("One1", () => console.Write("Should not be chosen")) .Add("Close1", ConsoleMenu.Close) .Configure(m => { ConfigHelper.BaseTestConfiguration(m, console); }); var menu = new ConsoleMenu(args: new[] { "--menu-select=0" }, level: 0) { Console = console } .Add("One0", submenu.Show) .Add("Close0", ConsoleMenu.Close) .Configure(m => { ConfigHelper.BaseTestConfiguration(m, console); }); console.AddUserInputWithActionBefore("2", () => { Assert.Equal(@"Pick an option: >> [0] One1 [1] Close1 ", console.ToString(), ignoreLineEndingDifferences: true); }); console.AddUserInputWithActionBefore(ConsoleKey.Enter, () => { submenu.CloseMenu(); menu.CloseMenu(); }); menu.Show(); }
public void Breadcrumbs() { var console = new TestConsole(); console.AddUserInputWithActionBefore("1", () => AssertHelper.Equal(@"First menu Pick an option: >> [0] One [1] Two [2] Close [3] Exit ", console.ToString())); console.AddUserInputWithActionBefore("0", () => AssertHelper.Equal(@"First menu > Second menu Pick an option: >> [0] Close ", console.ToString())); console.AddUserInputWithActionBefore("2", () => AssertHelper.Equal(@"First menu Pick an option: [0] One >> [1] Two [2] Close [3] Exit ", console.ToString())); var submenu = new ConsoleMenu { Console = console } .Add("Close", ConsoleMenu.Close) .Configure(m => { ConfigHelper.BaseTestConfiguration(m, console); m.EnableBreadcrumb = true; m.WriteBreadcrumbAction = titles => console.WriteLine(string.Join(" > ", titles)); m.Title = "Second menu"; }); var menu = new ConsoleMenu() { Console = console } .Add("One", () => { }) .Add("Two", submenu.Show) .Add("Close", ConsoleMenu.Close) .Add("Exit", () => Environment.Exit(0)) .Configure(m => { ConfigHelper.BaseTestConfiguration(m, console); m.EnableBreadcrumb = true; m.WriteBreadcrumbAction = titles => console.WriteLine(string.Join(" > ", titles)); m.Title = "First menu"; }); menu.Show(); AssertHelper.Equal(@"First menu Pick an option: [0] One [1] Two >> [2] Close [3] Exit ", console.ToString()); }
public void Filtering_Navigation() { var console = new TestConsole(); console.AddUserInputWithActionBefore("e", () => AssertHelper.Equal(@"Pick an option: >> [0] One [1] Two [2] Close [3] Exit Filter: ", console.ToString())); console.AddUserInputWithActionBefore(ConsoleKey.DownArrow, () => AssertHelper.Equal(@"Pick an option: >> [0] One [2] Close [3] Exit Filter: e", console.ToString())); console.AddUserInputWithActionBefore(ConsoleKey.UpArrow, () => AssertHelper.Equal(@"Pick an option: [0] One >> [2] Close [3] Exit Filter: e", console.ToString())); console.AddUserInputWithActionBefore(ConsoleKey.UpArrow, () => AssertHelper.Equal(@"Pick an option: >> [0] One [2] Close [3] Exit Filter: e", console.ToString())); console.AddUserInputWithActionBefore(ConsoleKey.UpArrow, () => AssertHelper.Equal(@"Pick an option: [0] One [2] Close >> [3] Exit Filter: e", console.ToString())); console.AddUserInputWithActionBefore(ConsoleKey.Enter, () => AssertHelper.Equal(@"Pick an option: [0] One >> [2] Close [3] Exit Filter: e", console.ToString())); var submenu = new ConsoleMenu { Console = console } .Add("Close", ConsoleMenu.Close) .Configure(m => { ConfigHelper.BaseTestConfiguration(m, console); m.EnableFilter = true; }); var menu = new ConsoleMenu() { Console = console } .Add("One", () => { }) .Add("Two", submenu.Show) .Add("Close", ConsoleMenu.Close) .Add("Exit", () => Environment.Exit(0)) .Configure(m => { ConfigHelper.BaseTestConfiguration(m, console); m.EnableFilter = true; }); menu.Show(); AssertHelper.Equal(@"Pick an option: [0] One >> [2] Close [3] Exit Filter: e ", console.ToString()); }