public void SimpleScenario() { const string input = @"2 "; var console = new TestConsole(input); var menu = new ConsoleMenu() { console = console } .Add("One", () => { }) .Add("Two", () => { }) .Add("Close", ConsoleMenu.Close) .Add("Exit", () => Environment.Exit(0)) .Configure(m => { m.SelectedItemBackgroundColor = console.ForegroundColor; m.SelectedItemForegroundColor = console.BackgroundColor; m.ItemBackgroundColor = console.BackgroundColor; m.ItemForegroundColor = console.ForegroundColor; m.WriteHeaderAction = () => console.WriteLine("Pick an option:"); m.WriteItemAction = item => console.Write("[{0}] {1}", item.Index, item.Name); }); menu.Show(); Assert.Equal(@"Pick an option: [0] One [1] Two >> [2] Close [3] Exit ", console.ToString()); }
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()); }