public void SeperateThreadsForMenuAndTwoWindows() { var console = new MockConsole(); var client = Window.Open(35, 0, 40, 25, "client", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkBlue, console); var server = Window.Open(77, 0, 40, 25, "server", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkYellow, console); // print two lines before the menu console.WriteLine("line 1"); console.WriteLine("line 2"); // create and run a menu inline, at the current cursor position var menu = new Menu(console, "ZeroMQ samples", ConsoleKey.Escape, 30, new MenuItem('1', "cats", () => RunMenuItem(client, "client", "cats")), new MenuItem('2', "dogs", () => RunMenuItem(server, "server", "dogs")), new MenuItem('3', "item 1", () => {}), new MenuItem('4', "item 2", () => {}), new MenuItem('5', "item 3", () => {}), new MenuItem('6', "item 4", () => {}), new MenuItem('7', "item 5", () => {}) ); // line below should print after (below) the menu. console.WriteLine("line 3"); // console should continue working and cursor should be set to below the menu. var kb = new MockKeyboard(0, GetKeyInfos());; menu.Keyboard = kb; menu.Run(); Task.WaitAll(_tasks.ToArray()); Approvals.Verify(console.BufferWrittenString); }
public void KeyboardCreateTest() { IGorgonInputServiceFactory serviceFactory = new MockInputServiceFactory(); IGorgonInputService service = serviceFactory.CreateService("My.Input.Service"); IReadOnlyList <IGorgonKeyboardInfo2> keyboards = service.EnumerateKeyboards(); IGorgonKeyboard keyboard; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (MockControl control = new MockControl()) { keyboard = new MockKeyboard(service, keyboards[0]); keyboard.BindWindow(control); control.Show(); control.FormClosing += (sender, args) => { keyboard.UnbindWindow(); }; keyboard.IsAcquired = true; Application.Run(control); } }
public void menu_plus_two_windows_full_of_progress_bars_each_window_on_seperate_thread_no_scrolling_of_pbars() { var console = new MockConsole(); var client = Window.Open(35, 0, 40, 25, "client", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkBlue, console); var server = Window.Open(77, 0, 40, 25, "server", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkYellow, console); console.WriteLine("one"); console.WriteLine("two"); var menu = new Menu(console, "Progress Bars", ConsoleKey.Escape, 30, new MenuItem('1', "AutoResetEvent client", () => RunProgressBars(client, "client", "cats")), new MenuItem('2', "AutoResetEvent server", () => RunProgressBars(server, "server", "dogs")) ); // need a unit test for the menu before fixing it. var kb = new MockKeyboard(0, GetKeyInfos()); menu.Keyboard = kb; menu.Run(); console.WriteLine("three"); console.WriteLine("stopping"); Task.WaitAll(_tasks.ToArray()); console.WriteLine("finished, press enter to close."); Approvals.Verify(console.BufferWrittenString); }
public void menu_plus_two_windows_full_of_progress_bars_each_window_on_seperate_thread_no_scrolling_of_pbars() { var console = new MockConsole(); var client = Window.Open(35, 0, 40, 25, "client", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkBlue, console); var server = Window.Open(77, 0, 40, 25, "server", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkYellow, console); console.WriteLine("one"); console.WriteLine("two"); var menu = new Menu(console, "Progress Bars", ConsoleKey.Escape, 30, new MenuItem('1', "AutoResetEvent client", () => RunProgressBars(client, "client", "cats")), new MenuItem('2', "AutoResetEvent server", () => RunProgressBars(server, "server", "dogs")) ); // need a unit test for the menu before fixing it. var kb = new MockKeyboard(0, GetKeyInfos()); menu.Keyboard = kb; menu.Run(); console.WriteLine("three"); console.WriteLine("stopping"); Task.WaitAll(_tasks.ToArray()); console.WriteLine("finished, press enter to close."); var actual = console.BufferWritten; var expected = new string[] { "one ┌─────────────── client ───────────────┐ ┌─────────────── server ───────────────┐ ", "two │Item 24 of 24 . (100%) ######## │ │Item 24 of 24 . (100%) ######## │ ", " │cats99 │ │dogs99 │ ", " Progress Bars │Item 11 of 11 . (100%) ######## │ │Item 11 of 11 . (100%) ######## │ ", " -------------------------- │cats99 │ │dogs99 │ ", " AutoResetEvent client │Item 46 of 46 . (100%) ######## │ │Item 46 of 46 . (100%) ######## │ ", " AutoResetEvent server │cats99 │ │dogs99 │ ", " │Item 77 of 77 . (100%) ######## │ │Item 77 of 77 . (100%) ######## │ ", "three │cats99 │ │dogs99 │ ", "stopping │Item 65 of 65 . (100%) ######## │ │Item 65 of 65 . (100%) ######## │ ", "finished, press enter to close. │cats99 │ │dogs99 │ ", " │Item 43 of 43 . (100%) ######## │ │Item 43 of 43 . (100%) ######## │ ", " │cats99 │ │dogs99 │ ", " │Item 35 of 35 . (100%) ######## │ │Item 35 of 35 . (100%) ######## │ ", " │cats99 │ │dogs99 │ ", " │Item 94 of 94 . (100%) ######## │ │Item 94 of 94 . (100%) ######## │ ", " │cats99 │ │dogs99 │ ", " │Item 10 of 10 . (100%) ######## │ │Item 10 of 10 . (100%) ######## │ ", " │cats99 │ │dogs99 │ ", " │Item 64 of 64 . (100%) ######## │ │Item 64 of 64 . (100%) ######## │ ", " │cats99 │ │dogs99 │ ", " │ │ │ │ ", " │ │ │ │ ", " │ │ │ │ ", " └──────────────────────────────────────┘ └──────────────────────────────────────┘ " }; actual.Should().BeEquivalentTo(expected); }
public void WaitForKeyPress_should_be_case_insensitive() { var k = new MockKeyboard('a', 'B'); var sut = new Keyboard(k); sut.WaitForKeyPress('a'); sut.WaitForKeyPress('B'); }
public void only_char_registered_to_receive_events_should_recieve_events() { var k = new MockKeyboard('c', 'B', 'c', 'a', 'd', 'o', 'g', 't', 'q'); var seq = new List <char>(); var sut = new Keyboard(k); sut.OnCharPressed('c', c => seq.Add(c)); sut.WaitForKeyPress('q'); Assert.AreEqual("cc", new string(seq.ToArray())); }
public void mutliple_registered_clients_should_all_recieve_events() { var k = new MockKeyboard('c', 'B', 'c', 'a', 'd', 'o', 'g', 't', 'q'); var seq1 = new List <char>(); var seq2 = new List <char>(); var keyboard = new Keyboard(k); keyboard.OnCharPressed(new[] { 'c', 'a', 't' }, c => seq1.Add(c)); keyboard.OnCharPressed(new[] { 'd', 'o', 'g' }, c => seq2.Add(c)); keyboard.WaitForKeyPress('q'); Assert.AreEqual("ccat", new string(seq1.ToArray())); Assert.AreEqual("dog", new string(seq2.ToArray())); }
public void SeperateThreadsForMenuAndTwoWindows() { var console = new MockConsole(); var client = Window.Open(35, 0, 40, 25, "client", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkBlue, console); var server = Window.Open(77, 0, 40, 25, "server", LineThickNess.Single, ConsoleColor.White, ConsoleColor.DarkYellow, console); // print two lines before the menu console.WriteLine("line 1"); console.WriteLine("line 2"); // create and run a menu inline, at the current cursor position var menu = new Menu(console, "Test samples", ConsoleKey.Escape, 30, new MenuItem('1', "cats", () => RunMenuItem(client, "client", "cats")), new MenuItem('2', "dogs", () => RunMenuItem(server, "server", "dogs")), new MenuItem('3', "item 1", () => {}), new MenuItem('4', "item 2", () => {}), new MenuItem('5', "item 3", () => {}), new MenuItem('6', "item 4", () => {}), new MenuItem('7', "item 5", () => {}) ); // line below should print after (below) the menu. console.WriteLine("line 3"); // console should continue working and cursor should be set to below the menu. var kb = new MockKeyboard(0, GetKeyInfos());; menu.Keyboard = kb; menu.Run(); Task.WaitAll(_tasks.ToArray()); var expected = new string[] { "line 1 ┌─────────────── client ───────────────┐ ┌─────────────── server ───────────────┐ ", "line 2 │cats 7978 │ │dogs 7978 │ ", " │cats 7979 │ │dogs 7979 │ ", " Test samples │cats 7980 │ │dogs 7980 │ ", " -------------------------- │cats 7981 │ │dogs 7981 │ ", " cats │cats 7982 │ │dogs 7982 │ ", " dogs │cats 7983 │ │dogs 7983 │ ", " item 1 │cats 7984 │ │dogs 7984 │ ", " item 2 │cats 7985 │ │dogs 7985 │ ", " item 3 │cats 7986 │ │dogs 7986 │ ", " item 4 │cats 7987 │ │dogs 7987 │ ", " item 5 │cats 7988 │ │dogs 7988 │ ", " │cats 7989 │ │dogs 7989 │ ", "line 3 │cats 7990 │ │dogs 7990 │ ", " │cats 7991 │ │dogs 7991 │ ", " │cats 7992 │ │dogs 7992 │ ", " │cats 7993 │ │dogs 7993 │ ", " │cats 7994 │ │dogs 7994 │ ", " │cats 7995 │ │dogs 7995 │ ", " │cats 7996 │ │dogs 7996 │ ", " │cats 7997 │ │dogs 7997 │ ", " │cats 7998 │ │dogs 7998 │ ", " │cats 7999 │ │dogs 7999 │ ", " │ │ │ │ ", " └──────────────────────────────────────┘ └──────────────────────────────────────┘ " }; var actual = console.BufferWritten; actual.Should().BeEquivalentTo(expected); }