public void IgnoresUnsupportedPropertyTypes() { var console = new TestConsole(new List <string>()); var commandFactory = new CommandFactory(new[] { new UnknownPropertyCommand(), }); var commandLoop = new CommandLoop(console, commandFactory); Assert.DoesNotThrow(() => commandLoop.Start(new[] { "test", "--Size = {X: 5, Y: 10 } ", "--nonInteractive" })); }
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 InterpretsIntArgumentAssignment() { var console = new TestConsole(new List<string>()); var commandFactory = new CommandFactory(new[] { new IntPropertyCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--Size = 5 ", "--nonInteractive" }); Assert.AreEqual("5", console.OutputQueue[0]); }
public void InterpretsStringArgumentAssignment() { var console = new TestConsole(new List<string>()); var commandFactory = new CommandFactory(new[] { new TestCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest = false ", "--Text=Foo", "--non-interactive" }); Assert.AreEqual("Run. Test: False, Text: Foo", console.OutputQueue[0]); }
public void InterpretsBooleanArgumentWithoutAssignmentAsTrue() { var console = new TestConsole(new List<string>()); var commandFactory = new CommandFactory(new[] { new TestCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest", "--nonInteractive" }); Assert.AreEqual("Run. Test: True, Text: ", console.OutputQueue[0]); }
public void RunningUnknownCommandsDoesNotThrowException() { var console = new TestConsole(new List<string>() {"--test", "exit" }); //var commandFactory = new CommandFactory(new[] {new TestCommand()}); var commandFactory = new CommandFactory(new ICommand[] { }); var commandLoop = new CommandLoop(console, commandFactory); Assert.DoesNotThrow(() => commandLoop.Start(new[] { "--test" })); }
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 SwitchesToInteractiveModeIfStartedWithoutAnyCommand() { var console = new TestConsole(new List<string>() { "test --nonInteractive" }); var commandFactory = new CommandFactory(new[] { new TestCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new string[]{}); Assert.AreEqual("Enter commands or type exit to close", console.OutputQueue[0]); Assert.AreEqual("Run. Test: False, Text: ", console.OutputQueue[1]); }
public void InterpretsIntArgumentAssignment() { var console = new TestConsole(new List <string>()); var commandFactory = new CommandFactory(new[] { new IntPropertyCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--Size = 5 ", "--nonInteractive" }); Assert.AreEqual("5", console.OutputQueue[0]); }
public void CanInitializeCommand() { var console = new TestConsole(new List<string>() {}); var commandFactory = new CommandFactory(new[] {new TestCommand()}); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--non-interactive" }); Assert.AreEqual("Run. Test: False, Text: ", console.OutputQueue[0]); }
public void InterpretsBooleanArgumentWithoutAssignmentAsTrue() { var console = new TestConsole(new List <string>()); var commandFactory = new CommandFactory(new[] { new TestCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest", "--nonInteractive" }); Assert.AreEqual("Run. Test: True, Text: ", console.OutputQueue[0]); }
public void InterpretsStringArgumentAssignment() { var console = new TestConsole(new List <string>()); var commandFactory = new CommandFactory(new[] { new TestCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest = false ", "--Text=Foo", "--non-interactive" }); Assert.AreEqual("Run. Test: False, Text: Foo", console.OutputQueue[0]); }
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 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 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 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 RunningUnknownCommandsDoesNotThrowException() { var console = new TestConsole(new List <string>() { "--test", "exit" }); //var commandFactory = new CommandFactory(new[] {new TestCommand()}); var commandFactory = new CommandFactory(new ICommand[] { }); var commandLoop = new CommandLoop(console, commandFactory); Assert.DoesNotThrow(() => commandLoop.Start(new[] { "--test" })); }
public void PrintsExceptionsToTheConsole() { var console = new TestConsole(new List <string>()); var commandFactory = new CommandFactory(new[] { new ExceptionCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "RaiseException", "--nonInteractive" }); Assert.AreEqual("Unexpected error happended while proceeding the command: RaiseException", console.OutputQueue[0]); Assert.AreEqual("Exception: Foo", console.OutputQueue[1]); Assert.IsTrue(console.OutputQueue[2].StartsWith("Stacktrace:")); Assert.AreEqual("Exception: Bar", console.OutputQueue[3]); }
public void CanInitializeCommand() { var console = new TestConsole(new List <string>() { }); var commandFactory = new CommandFactory(new[] { new TestCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--non-interactive" }); Assert.AreEqual("Run. Test: False, Text: ", console.OutputQueue[0]); }
public void SwitchesToInteractiveModeIfStartedWithoutAnyCommand() { var console = new TestConsole(new List <string>() { "test --nonInteractive" }); var commandFactory = new CommandFactory(new[] { new TestCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new string[] {}); Assert.AreEqual("Enter commands or type exit to close", console.OutputQueue[0]); Assert.AreEqual("Run. Test: False, Text: ", console.OutputQueue[1]); }
public void RunsTwoTimesInteractiveAndThenIgnoresLastCommandBecauseOfPreviousExit() { var console = new TestConsole(new List <string>() { "test", "exit", "--test" }); var commandFactory = new CommandFactory(new[] { new TestCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest" }); Assert.AreEqual("Run. Test: True, Text: ", console.OutputQueue[0]); Assert.AreEqual("Enter commands or type exit to close", console.OutputQueue[1]); Assert.AreEqual("Run. Test: False, Text: ", console.OutputQueue[2]); Assert.AreEqual("Enter commands or type exit to close", console.OutputQueue[3]); Assert.AreEqual(4, console.OutputQueue.Count); }
public void RunsTwoTimesInteractiveAndThenClosesAfterLastNonInteractive() { var console = new TestConsole(new List <string>() { "test", "test --nonInteractive" }); var commandFactory = new CommandFactory(new[] { new TestCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest" }); Assert.AreEqual("Run. Test: True, Text: ", console.OutputQueue[0]); Assert.AreEqual("Enter commands or type exit to close", console.OutputQueue[1]); Assert.AreEqual("Run. Test: False, Text: ", console.OutputQueue[2]); Assert.AreEqual("Enter commands or type exit to close", console.OutputQueue[3]); Assert.AreEqual("Run. Test: False, Text: ", console.OutputQueue[4]); Assert.AreEqual(5, console.OutputQueue.Count); }
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 PrintsExceptionsToTheConsole() { var console = new TestConsole(new List<string>()); var commandFactory = new CommandFactory(new[] { new ExceptionCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "RaiseException", "--nonInteractive" }); Assert.AreEqual("Unexpected error happended while proceeding the command: RaiseException", console.OutputQueue[0]); Assert.AreEqual("Exception: Foo", console.OutputQueue[1]); Assert.IsTrue(console.OutputQueue[2].StartsWith("Stacktrace:")); Assert.AreEqual("Exception: Bar", console.OutputQueue[3]); }
public void IgnoresUnsupportedPropertyTypes() { var console = new TestConsole(new List<string>()); var commandFactory = new CommandFactory(new[] { new UnknownPropertyCommand(), }); var commandLoop = new CommandLoop(console, commandFactory); Assert.DoesNotThrow(() => commandLoop.Start(new[] { "test", "--Size = {X: 5, Y: 10 } ", "--nonInteractive" })); }
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 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 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 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 RunsTwoTimesInteractiveAndThenIgnoresLastCommandBecauseOfPreviousExit() { var console = new TestConsole(new List<string>() { "test", "exit", "--test" }); var commandFactory = new CommandFactory(new[] { new TestCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest" }); Assert.AreEqual("Run. Test: True, Text: ", console.OutputQueue[0]); Assert.AreEqual("Enter commands or type exit to close", console.OutputQueue[1]); Assert.AreEqual("Run. Test: False, Text: ", console.OutputQueue[2]); Assert.AreEqual("Enter commands or type exit to close", console.OutputQueue[3]); Assert.AreEqual(4, console.OutputQueue.Count); }
public void RunsTwoTimesInteractiveAndThenClosesAfterLastNonInteractive() { var console = new TestConsole(new List<string>() { "test", "test --nonInteractive" }); var commandFactory = new CommandFactory(new[] { new TestCommand() }); var commandLoop = new CommandLoop(console, commandFactory); commandLoop.Start(new[] { "test", "--IsTest" }); Assert.AreEqual("Run. Test: True, Text: ", console.OutputQueue[0]); Assert.AreEqual("Enter commands or type exit to close", console.OutputQueue[1]); Assert.AreEqual("Run. Test: False, Text: ", console.OutputQueue[2]); Assert.AreEqual("Enter commands or type exit to close", console.OutputQueue[3]); Assert.AreEqual("Run. Test: False, Text: ", console.OutputQueue[4]); Assert.AreEqual(5, console.OutputQueue.Count); }
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)); }
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 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); }
static void Main(string[] args) { var commandLoop = new CommandLoop(); commandLoop.Start(args); }