public void RunningUnknownCommandsDoesNotThrowException() { var inputSequence = "fooooo".ToInputSequence().AddEnterHit().AddInputSequence("exit").AddEnterHit(); var console = new LowLevelTestConsole(inputSequence); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); Assert.DoesNotThrow(() => commandLoop.Start(new[] { "fooo" })); }
public void InterpretsBooleanArgumentWithFalseAssignmentExpression() { var console = new LowLevelTestConsole(); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest = false", "--nonInteractive" }); Assert.AreEqual("Run. Test: False, Text: ", console.ReadInLineFromTo(7, 0, 23)); }
public void MaliciousCommandWontTakeShellMeDown() { var inputSequence = "exit".ToInputSequence().AddEnterHit(); var console = new LowLevelTestConsole(inputSequence); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] {"malicious", " --value=4", "--non-interactive"}); Assert.AreEqual("Unexpected error happended while proceeding the command: Malicious", console.ReadInLineFromTo(7, 0, 65)); }
public void SwitchesToInteractiveModeIfStartedWithoutAnyCommand() { var inputSequence = "test --nonInteractive".ToInputSequence().AddEnterHit(); var console = new LowLevelTestConsole(inputSequence); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new string[]{}); Assert.AreEqual("Run. Test: False, Text: ", console.ReadInLineFromTo(8, 0, 23)); }
public void WritesHelloWorld() { var inputSequence = "Hello World".ToInputSequence(); var lowLevelConsole = new LowLevelTestConsole(inputSequence); var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "$ " }; adapter.ReadUntilSequenceIsOver(inputSequence); Assert.AreEqual("$ Hello World", lowLevelConsole.ReadInLineFromTo(0,0,12)); }
public void InterpretsEnumerableLogLevelArgumentAssignment2() { var console = new LowLevelTestConsole(); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "LogLevel", "--LogLevel=[Information, Error]", "--nonInteractive" }); Assert.AreEqual("Information", console.ReadInLineFromTo(7, 0, 10)); Assert.AreEqual("Error", console.ReadInLineFromTo(8, 0, 4)); }
public void WritesPrompt() { var inputSequence = " ".ToInputSequence(); var lowLevelConsole = new LowLevelTestConsole(inputSequence); var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) {Prompt = "$ "}; adapter.ReadUntilSequenceIsOver(inputSequence); var written = lowLevelConsole.ReadCharacterAt(0, 0); Assert.AreEqual('$',written); }
public void BreaksLineOnTheRightCharacter() { var inputSequence = "Hello this is shell.me. We are testing the new LowLevelConsole, which gives us great power!".ToInputSequence(); var lowLevelConsole = new LowLevelTestConsole(inputSequence); var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " }; adapter.ReadUntilSequenceIsOver(inputSequence); Assert.AreEqual("(S) Hello this is shell.me. We are testing the new LowLevelConsole, which gives ", lowLevelConsole.ReadInLineFromTo(0, 0, 79)); Assert.AreEqual("us great power!", lowLevelConsole.ReadInLineFromTo(1, 0, 14)); }
public void CanInitializeCommand() { var console = new LowLevelTestConsole(); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--non-interactive" }); Assert.AreEqual("Run. Test: False, Text: ", console.ReadInLineFromTo(7, 0,23)); }
public void InterpretsEnumerableLogLevelArgumentInInteractiveMode() { var inputSequence = "LogLevel --logLevel=[Information, Error] --non-interactive".ToInputSequence().AddEnterHit(); var console = new LowLevelTestConsole(inputSequence); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new string[]{}); Assert.AreEqual("(S) LogLevel --logLevel=[Information, Error] --non-interactive", console.ReadInLineFromTo(7, 0, 61)); Assert.AreEqual("Information", console.ReadInLineFromTo(8, 0, 10)); Assert.AreEqual("Error", console.ReadInLineFromTo(9, 0, 4)); }
public void CursorMovesLeftUntilItHitsThePrompt() { var inputSequence = "Hello" .ToInputSequence() .AddLeftArrowHit(5); var lowLevelConsole = new LowLevelTestConsole(inputSequence); var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " }; adapter.ReadUntilSequenceIsOver(inputSequence); Assert.AreEqual("(S) Hello", lowLevelConsole.ReadInLineFromTo(0, 0, 8)); Assert.AreEqual(4, lowLevelConsole.CursorLeft); Assert.AreEqual(0, lowLevelConsole.CursorTop); }
public void BackspaceJumpsLineUpAndLetsUsWriteAgain() { var inputSequence = "Hello this is shell.me. We are testing the new LowLevelConsole, which gives us great power!" .ToInputSequence() .AddBackspaceHit(21) .AddInputSequence("rocks!"); var lowLevelConsole = new LowLevelTestConsole(inputSequence); var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " }; adapter.ReadUntilSequenceIsOver(inputSequence); Assert.AreEqual("(S) Hello this is shell.me. We are testing the new LowLevelConsole, which rocks!", lowLevelConsole.ReadInLineFromTo(0, 0, 79)); //We are just making sure that there is nothing left on the second line Assert.AreEqual(" ", lowLevelConsole.ReadInLineFromTo(1, 0, 79)); }
public void WritesMovesCursorBeforeWritingAndInsertsAnotherWord() { var inputSequence = "World" .ToInputSequence() .AddLeftArrowHit(5) .AddInputSequence("Hello "); var lowLevelConsole = new LowLevelTestConsole(inputSequence); var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " }; adapter.ReadUntilSequenceIsOver(inputSequence); Assert.AreEqual("(S) Hello World", lowLevelConsole.ReadInLineFromTo(0, 0, 14)); Assert.AreEqual(10, lowLevelConsole.CursorLeft); }
public void WriteLineWorks() { var lowLevelConsole = new LowLevelTestConsole(); var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " }; adapter.WriteLine("Hello World"); adapter.WriteLine("Hello World"); Assert.AreEqual("Hello World", lowLevelConsole.ReadInLineFromTo(0, 0, 10)); Assert.AreEqual("Hello World", lowLevelConsole.ReadInLineFromTo(1, 0, 10)); Assert.AreEqual(0, lowLevelConsole.CursorLeft); }
public void InterpretsIntArgumentAssignment() { var console = new LowLevelTestConsole(); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "IntProperty", "--Size = 5 ", "--nonInteractive" }); Assert.AreEqual("5", console.ReadInLineFromTo(7, 0, 0)); }
public void InterpretsStringArgumentAssignment() { var console = new LowLevelTestConsole(); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest = false ", "--Text=Foo", "--non-interactive" }); Assert.AreEqual("Run. Test: False, Text: Foo", console.ReadInLineFromTo(7, 0, 26)); }
public void CursorCanNotMoveAheadTheWriting() { var inputSequence = "Hello" .ToInputSequence() .AddRightArrowHit(5); var lowLevelConsole = new LowLevelTestConsole(inputSequence); var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " }; adapter.ReadUntilSequenceIsOver(inputSequence); Assert.AreEqual("(S) Hello", lowLevelConsole.ReadInLineFromTo(0, 0, 8)); Assert.AreEqual(9, lowLevelConsole.CursorLeft); Assert.AreEqual(0, lowLevelConsole.CursorTop); }
public void RunsCommandsInParallelBecauseAllowParallelIsDefaultedToTrue() { var console = new LowLevelTestConsole(); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); var console2 = new LowLevelTestConsole(); var commandFactory2 = new CommandFactory(Configurations.PluginDirectory); var commandLoop2 = new CommandLoop(console2, commandFactory2); Task.WaitAll(new[] { Task.Factory.StartNew(() => commandLoop.Start(new[] { "LongRunningCommand", "--nonInteractive" })), Task.Factory.StartNew(() => commandLoop2.Start(new[] { "LongRunningCommand", "--nonInteractive" })) }); Assert.IsTrue(console.ReadInLineFromTo(7, 0, 8) == "Completed"); Assert.IsTrue(console2.ReadInLineFromTo(7, 0, 8) == "Completed"); }
public void InterpretsEnumerableIntArgumentAssignment() { var console = new LowLevelTestConsole(); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "EnumerableInt", "--Values = [1,2, 3,4] ", "--nonInteractive" }); Assert.AreEqual("1", console.ReadInLineFromTo(7, 0, 0)); Assert.AreEqual("2", console.ReadInLineFromTo(8, 0, 0)); Assert.AreEqual("3", console.ReadInLineFromTo(9, 0, 0)); Assert.AreEqual("4", console.ReadInLineFromTo(10, 0, 0)); }
public void PrintsExceptionsToTheConsole() { var console = new LowLevelTestConsole(); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "RaiseException", "--nonInteractive" }); Assert.AreEqual("Unexpected error happended while proceeding the command: RaiseException", console.ReadInLineFromTo(7, 0, 70)); }
public void IgnoresSecondCommandBecauseItsConfiguredToNotRunInParallel() { var console = new LowLevelTestConsole(); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); var console2 = new LowLevelTestConsole(); var commandFactory2 = new CommandFactory(Configurations.PluginDirectory); var commandLoop2 = new CommandLoop(console2, commandFactory2); Task.WaitAll(new[] { Task.Factory.StartNew(() => commandLoop.Start(new[] { "LongRunningCommand", "--nonInteractive", "--allow-parallel=false" })), Task.Factory.StartNew(() => commandLoop2.Start(new[] { "LongRunningCommand", "--nonInteractive", "--allow-parallel=false" })) }); var successfulRuns = 0; var firstCommandRun = console.BufferLines == 8 && console.ReadInLineFromTo(7,0,8) == "Completed"; var secondCommandRun = console2.BufferLines == 8 && console2.ReadInLineFromTo(7, 0, 8) == "Completed"; if (firstCommandRun) successfulRuns++; if (secondCommandRun) successfulRuns++; Assert.AreEqual(1, successfulRuns); }
public void RunsTwoTimesAndThenIgnoresLastCommandBecauseOfPreviousExit() { var inputSequence = "test".ToInputSequence().AddEnterHit().AddInputSequence("exit").AddEnterHit().AddInputSequence("test").AddEnterHit(); var console = new LowLevelTestConsole(inputSequence); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest" }); Assert.AreEqual("Run. Test: True, Text: ", console.ReadInLineFromTo(7, 0, 22)); Assert.AreEqual("(S) test", console.ReadInLineFromTo(8, 0, 7)); Assert.AreEqual("Run. Test: False, Text: ", console.ReadInLineFromTo(9, 0, 23)); Assert.AreEqual("(S) exit", console.ReadInLineFromTo(10, 0, 7)); Assert.AreEqual(11, console.BufferLines); }
public void ErasesCurrentLineAndResetsCursor() { var inputSequence = "Hello".ToInputSequence(); var lowLevelConsole = new LowLevelTestConsole(inputSequence); var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " }; adapter.ReadUntilSequenceIsOver(inputSequence); Assert.AreEqual("(S) Hello", lowLevelConsole.ReadInLineFromTo(0, 0, 8)); Assert.AreEqual(9, lowLevelConsole.CursorLeft); adapter.EraseCurrentLine(); Assert.AreEqual("(S) ", lowLevelConsole.ReadInLineFromTo(0, 0, 8)); Assert.AreEqual(4, lowLevelConsole.CursorLeft); }
public void RunsTwoTimesInteractiveAndThenClosesAfterLastNonInteractive() { var inputSequence = "test".ToInputSequence().AddEnterHit().AddInputSequence("test --nonInteractive").AddEnterHit(); var console = new LowLevelTestConsole(inputSequence); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest" }); Assert.AreEqual("Run. Test: True, Text: ", console.ReadInLineFromTo(7, 0, 22)); Assert.AreEqual("(S) test", console.ReadInLineFromTo(8, 0, 7)); Assert.AreEqual("Run. Test: False, Text: ", console.ReadInLineFromTo(9, 0, 23)); Assert.AreEqual("(S) test --nonInteractive", console.ReadInLineFromTo(10, 0, 24)); Assert.AreEqual("Run. Test: False, Text: ", console.ReadInLineFromTo(11, 0, 23)); Assert.AreEqual(12, console.BufferLines); }
public void IgnoresUnsupportedPropertyTypes() { var console = new LowLevelTestConsole(); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); Assert.DoesNotThrow(() => commandLoop.Start(new[] { "UnknownProperty", "--Size = {X: 5, Y: 10 } ", "--nonInteractive" })); }
public void InterpretsEnumerableStringArgumentAssignment() { var console = new LowLevelTestConsole(); var commandFactory = new CommandFactory(Configurations.PluginDirectory); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "EnumerableString", "--Values = [Foo,bar,Foo Bar] ", "--nonInteractive" }); Assert.AreEqual("Foo", console.ReadInLineFromTo(7, 0, 2)); Assert.AreEqual("bar", console.ReadInLineFromTo(8, 0, 2)); Assert.AreEqual("Foo Bar", console.ReadInLineFromTo(9, 0, 6)); }