public void Should_work_with_engines() { //Arrange var consoleManager1 = new FakeConsoleManager(); var consoleManager2 = new FakeConsoleManager(); var console1 = new TestConsole(consoleManager1); var console2 = new TestConsole(consoleManager2); var command1 = new RootCommand(console1); var command2 = new RootCommand(console2); var commandEngine1 = new CommandEngine(command1); var commandEngine2 = new CommandEngine(command2); Task.Run(() => { commandEngine1.Start(new string[] { }); }).Wait(100); Task.Run(() => { commandEngine2.Start(new string[] { }); }).Wait(100); console2.Output(new WriteEventArgs(new string('C', console1.BufferWidth * (console1.BufferHeight - 1)))); console1.Output(new WriteEventArgs(new string('A', console1.BufferWidth * (console1.BufferHeight - 1)))); //Act console1.Output(new WriteEventArgs("B")); //Assert Assert.That(consoleManager1.LineOutput[0], Is.EqualTo(new string('A', consoleManager1.BufferWidth))); Assert.That(consoleManager1.LineOutput[consoleManager1.BufferHeight - 3], Is.EqualTo(new string('A', consoleManager1.BufferWidth))); Assert.That(consoleManager1.LineOutput[consoleManager1.BufferHeight - 2], Is.EqualTo("B")); //Assert.That(consoleManager1.LineOutput[consoleManager1.BufferHeight - 1], Is.EqualTo("> ")); //Assert.That(consoleManager1.CursorTop, Is.EqualTo(consoleManager1.BufferHeight - 1)); //Assert.That(consoleManager1.CursorLeft, Is.EqualTo(2)); Assert.That(consoleManager2.LineOutput[0], Is.EqualTo(new string('C', consoleManager1.BufferWidth))); Assert.That(consoleManager2.LineOutput[consoleManager1.BufferHeight - 3], Is.EqualTo(new string('C', consoleManager1.BufferWidth))); //Assert.That(consoleManager2.LineOutput[0], Is.EqualTo("> ")); }
public void Should_recall_first_command_with_a_specific_command_when_pressing_Tab() { //Arrange var input = new[] { ConsoleKey.T, ConsoleKey.W, ConsoleKey.O, ConsoleKey.Tab, ConsoleKey.Enter }; var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input)); var console = new TestConsole(consoleManager); var cancellationToken = new CancellationToken(); var inputInstance = new InputInstance(console, Constants.Prompt, null, cancellationToken); var selection = new CommandTreeNode <string>(new[] { new CommandTreeNode <string>("First", "One"), new CommandTreeNode <string>("Second", "Two", new [] { new CommandTreeNode <string>("FirstSub", "SubOne"), new CommandTreeNode <string>("SecondSub", "SubTwo"), new CommandTreeNode <string>("LastSub", "SubX"), }), new CommandTreeNode <string>("Last", "x") }); //Act var r = inputInstance.ReadLine(selection, true); //Assert var match = selection.Subs.ToArray()[1]; Assert.That(r, Is.EqualTo(match.Key)); Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + match.Value)); }
public void Should_recall_first_sub_command_when_matching_a_sub_part_with_similar_root_name_pressing_Tab() { //Arrange var input = new[] { ConsoleKey.T, ConsoleKey.W, ConsoleKey.O, ConsoleKey.Spacebar, ConsoleKey.F, ConsoleKey.Tab, ConsoleKey.Enter }; var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input)); var console = new TestConsole(consoleManager); var cancellationToken = new CancellationToken(); var inputInstance = new InputInstance(console, Constants.Prompt, null, cancellationToken); var match = new CommandTreeNode <string>("FirstSub", "SubOne"); var selection = new CommandTreeNode <string>(new[] { new CommandTreeNode <string>("First", "One"), new CommandTreeNode <string>("Second", "Two", new [] { match, new CommandTreeNode <string>("SecondSub", "SubTwo"), new CommandTreeNode <string>("LastSub", "SubX"), }), new CommandTreeNode <string>("SecondOther", "TwoOther"), new CommandTreeNode <string>("Last", "x") }); //Act var r = inputInstance.ReadLine(selection, true); //Assert Assert.That(r, Is.EqualTo(match.Key)); Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + "Two " + match.Value)); }
public void Should_recall_command_in_several_layers_when_navigating_with_Tab() { //Arrange var input = new[] { ConsoleKey.T, ConsoleKey.Tab, ConsoleKey.Spacebar, ConsoleKey.O, ConsoleKey.Tab, ConsoleKey.Spacebar, ConsoleKey.S, ConsoleKey.Tab, ConsoleKey.Enter }; var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input)); var console = new TestConsole(consoleManager); var cancellationToken = new CancellationToken(); var inputInstance = new InputInstance(console, Constants.Prompt, null, cancellationToken); var match = new CommandTreeNode <string>("SecondSub", "S"); var selection = new CommandTreeNode <string>(new[] { new CommandTreeNode <string>("First", "One"), new CommandTreeNode <string>("Second", "Two", new [] { new CommandTreeNode <string>("FirstA", "One", new [] { new CommandTreeNode <string>("FirstSub", "ThirdOne"), match, new CommandTreeNode <string>("LastSub", "ThirdX"), }), new CommandTreeNode <string>("SecondSub", "SubTwo"), new CommandTreeNode <string>("LastSub", "SubX"), }), new CommandTreeNode <string>("Last", "x") }); //Act var r = inputInstance.ReadLine(selection, true); //Assert Assert.That(r, Is.EqualTo(match.Key)); Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + "Two One " + match.Value)); }
//TODO: There is an issue with this case, find a good way to set up the test for this. public void Should_output_on_new_line_when_entering_a_long_query_line_with_cursor_at_beginning() { //Arrange var consoleManager = new FakeConsoleManager(); var console = new TestConsole(consoleManager); //TODO: Prepare a query entry that is longer than one line //TODO: Place cursor at start (on first line) and press enter. //Act //TODO: Press enter //Assert //TODO: See where the response output appears }
public void When_typing_the_exit_command_the_command_engine_should_exit() { //Arrange var input = new[] { ConsoleKey.E, ConsoleKey.X, ConsoleKey.I, ConsoleKey.T, ConsoleKey.Enter }; var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input)); var console = new TestConsole(consoleManager); var command = new RootCommand(console); //Act new CommandEngine(command).Start(new string[] { }); //Assert Assert.True(true); }
public void Should_write_line_feeds_as_long_as_the_buffer_height() { //Arrange var consoleManager = new FakeConsoleManager(); var console = new TestConsole(consoleManager); //Act console.Output(new WriteEventArgs(new string('\n', consoleManager.BufferHeight - 2))); //Assert Assert.That(consoleManager.LineOutput, Is.Not.Empty); Assert.That(consoleManager.LineOutput[0], Is.EqualTo(string.Empty)); Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 2], Is.EqualTo(string.Empty)); Assert.That(consoleManager.CursorTop, Is.EqualTo(consoleManager.BufferHeight - 1)); }
public void Should_write_a_string_long_as_the_buffer_width() { //Arrange var consoleManager = new FakeConsoleManager(); var console = new TestConsole(consoleManager); //Act console.Output(new WriteEventArgs(new string('A', consoleManager.BufferWidth))); //Assert Assert.That(consoleManager.LineOutput, Is.Not.Empty); Assert.That(consoleManager.LineOutput[0], Is.EqualTo(new string('A', consoleManager.BufferWidth))); Assert.That(consoleManager.LineOutput[1], Is.Null); Assert.That(consoleManager.CursorTop, Is.EqualTo(1)); }
public void Should_write_short_string() { //Arrange var consoleManager = new FakeConsoleManager(); var console = new TestConsole(consoleManager); //Act console.Output(new WriteEventArgs("A")); //Assert Assert.That(consoleManager.LineOutput, Is.Not.Empty); Assert.That(consoleManager.LineOutput[0], Is.EqualTo("A")); Assert.That(consoleManager.LineOutput[1], Is.Null); Assert.That(consoleManager.CursorTop, Is.EqualTo(1)); }
public void Should_recall_nothing_when_pressing_Tab_and_no_commands_are_provided() { //Arrange var input = new[] { ConsoleKey.Tab, ConsoleKey.Enter }; var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input)); var console = new TestConsole(consoleManager); var cancellationToken = new CancellationToken(); var inputInstance = new InputInstance(console, Constants.Prompt, null, cancellationToken); //Act var r = inputInstance.ReadLine <string>(null, true); //Assert Assert.That(r, Is.EqualTo(string.Empty)); }
public void Should_prompt_cursor() { //Arrange var consoleManager = new FakeConsoleManager(); var console = new TestConsole(consoleManager); var command = new RootCommand(console); var commandEngine = new CommandEngine(command); //Act Task.Run(() => { commandEngine.Start(new string[] { }); }).Wait(100); //Assert //TODO: Fix on build server! Assert.That(consoleManager.LineOutput[0], Is.EqualTo("> ")); //TODO: Fix on build server! Assert.That(consoleManager.CursorTop, Is.EqualTo(0)); //TODO: Fix on build server! Assert.That(consoleManager.CursorLeft, Is.EqualTo(2)); }
public void Should_return_the_string_that_was_entered() { //Arrange var input = new[] { ConsoleKey.A, ConsoleKey.B, ConsoleKey.C, ConsoleKey.Enter }; var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input)); var console = new TestConsole(consoleManager); var cancellationToken = new CancellationToken(); var inputInstance = new InputInstance(console, Constants.Prompt, null, cancellationToken); //Act var r = inputInstance.ReadLine <string>(null, true); //Assert Assert.That(r, Is.EqualTo("ABC")); }
public void Should_a_short_string() { //Arrange var consoleManager = new FakeConsoleManager(); var console = new TestConsole(consoleManager); console.Output(new WriteEventArgs(new string('A', console.BufferWidth * (console.BufferHeight - 1)))); //Act console.Output(new WriteEventArgs("B")); //Assert Assert.That(consoleManager.LineOutput[0], Is.EqualTo(new string('A', consoleManager.BufferWidth))); Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 3], Is.EqualTo(new string('A', consoleManager.BufferWidth))); Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 2], Is.EqualTo("B")); Assert.That(consoleManager.CursorTop, Is.EqualTo(consoleManager.BufferHeight - 1)); }
public void Should_recall_second_command_when_pressing_Tab_Twise() { //Arrange var input = new[] { ConsoleKey.Tab, ConsoleKey.Tab, ConsoleKey.Enter }; var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input)); var console = new TestConsole(consoleManager); var cancellationToken = new CancellationToken(); var inputInstance = new InputInstance(console, Constants.Prompt, null, cancellationToken); var selection = new CommandTreeNode <string>(new[] { new CommandTreeNode <string>("First", "1"), new CommandTreeNode <string>("Second", "2"), new CommandTreeNode <string>("Last", "x") }); //Act var r = inputInstance.ReadLine(selection, true); //Assert Assert.That(r, Is.EqualTo(selection.Subs[1].Key)); Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + selection.Subs[1].Value)); }
public void Should_recall_last_command_when_pressing_Shift_Tab() { //Arrange var input = new[] { new ConsoleKeyInfo('\t', ConsoleKey.Tab, true, false, false), new ConsoleKeyInfo((char)13, ConsoleKey.Enter, false, false, false) }; var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input)); var console = new TestConsole(consoleManager); var cancellationToken = new CancellationToken(); var inputInstance = new InputInstance(console, Constants.Prompt, null, cancellationToken); var selection = new CommandTreeNode <string>(new[] { new CommandTreeNode <string>("First", "1"), new CommandTreeNode <string>("Second", "2"), new CommandTreeNode <string>("Last", "x") }); //Act var r = inputInstance.ReadLine(selection, true); //Assert var match = selection.Subs.Last(); Assert.That(r, Is.EqualTo(match.Key)); Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + match.Value)); }
public void Should_prompt_cursor_after_full_line_output() { //Arrange var consoleManager = new FakeConsoleManager(); var console = new TestConsole(consoleManager); var command = new RootCommand(console); var commandEngine = new CommandEngine(command); Task.Run(() => { commandEngine.Start(new string[] { }); }).Wait(100); //Act console.Output(new WriteEventArgs(new string('A', console.BufferWidth))); //Assert Assert.That(consoleManager.LineOutput[0], Is.EqualTo(new string('A', console.BufferWidth))); //TODO: Fix on build server! Assert.That(consoleManager.LineOutput[1], Is.EqualTo("> ")); //TODO: Fix on build server! Assert.That(consoleManager.CursorTop, Is.EqualTo(1)); //TODO: Fix on build server! Assert.That(consoleManager.CursorLeft, Is.EqualTo(2)); }
public void Should_write_two_rows_v2() { //Arrange var consoleManager = new FakeConsoleManager(); var console = new TestConsole(consoleManager); console.Output(new WriteEventArgs(new string('A', console.BufferWidth * (console.BufferHeight - 1)))); //Act console.Output(new WriteEventArgs(new string('B', 1 * console.BufferWidth + 1))); //Assert Assert.That(consoleManager.LineOutput, Is.Not.Empty); Assert.That(consoleManager.LineOutput[0], Is.EqualTo(new string('A', consoleManager.BufferWidth))); Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 4], Is.EqualTo(new string('A', consoleManager.BufferWidth))); Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 3], Is.EqualTo(new string('B', consoleManager.BufferWidth))); Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 2], Is.EqualTo("B")); Assert.That(consoleManager.CursorTop, Is.EqualTo(consoleManager.BufferHeight - 1)); }
//TODO: There is an issue with this case, find a good way to set up the test for this. public void Should_output_on_new_line_when_entering_a_long_query_line_with_cursor_at_end() { //TODO: Prepare a query entry that is longer than one line //TODO: Place cursor at end of the input buffer and press enter. //Arrange var fakeKeyInput = new FakeKeyInputEngine(); var consoleManager = new FakeConsoleManager(fakeKeyInput); var console = new TestConsole(consoleManager); var command = new RootCommand(console); var commandEngine = new CommandEngine(command); console.Output(new WriteEventArgs("a")); command.Execute(new string('x', console.BufferWidth + 1)); console.Output(new WriteEventArgs("z")); //Assert.That(consoleManager.LineOutput[0], Is.EqualTo("abc")); //Assert.That(consoleManager.LineOutput[1], Is.Null); //Act //Assert }
public void Should_keep_buffer_after_line_output() { //Arrange var inputEngine = new Mock <IKeyInputEngine>(MockBehavior.Strict); inputEngine.Setup(x => x.ReadKey(It.IsAny <CancellationToken>())).Returns(new ConsoleKeyInfo('A', ConsoleKey.A, false, false, false)); var consoleManager = new FakeConsoleManager(inputEngine.Object); var console = new TestConsole(consoleManager); var command = new RootCommand(console); var commandEngine = new CommandEngine(command); Task.Run(() => { commandEngine.Start(new string[] { }); }).Wait(100); //Act console.Output(new WriteEventArgs("A")); //Assert Assert.That(consoleManager.LineOutput[0], Is.EqualTo("A")); Assert.That(consoleManager.LineOutput[1], Is.EqualTo($"{Constants.Prompt}A")); Assert.That(consoleManager.CursorTop, Is.EqualTo(1)); Assert.That(consoleManager.CursorLeft, Is.EqualTo(5)); }
public void Should_a_short_string() { //Arrange var consoleManager = new FakeConsoleManager(); var console = new TestConsole(consoleManager); var command = new RootCommand(console); var commandEngine = new CommandEngine(command); Task.Run(() => { commandEngine.Start(new string[] { }); }).Wait(100); console.Output(new WriteEventArgs(new string('A', console.BufferWidth * (console.BufferHeight - 1)))); //Act console.Output(new WriteEventArgs("B")); //Assert Assert.That(consoleManager.LineOutput[0], Is.EqualTo(new string('A', consoleManager.BufferWidth))); Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 3], Is.EqualTo(new string('A', consoleManager.BufferWidth))); Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 2], Is.EqualTo("B")); //TODO: Fix on build server! Assert.That(consoleManager.LineOutput[consoleManager.BufferHeight - 1], Is.EqualTo("> ")); //TODO: Fix on build server! Assert.That(consoleManager.CursorTop, Is.EqualTo(consoleManager.BufferHeight - 1)); //TODO: Fix on build server! Assert.That(consoleManager.CursorLeft, Is.EqualTo(2)); }