예제 #1
0
        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" }));
        }
예제 #2
0
        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" }));
        }
예제 #3
0
        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]);
        }
예제 #4
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]);
        }
예제 #5
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]);
        }
예제 #6
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" }));
        }
예제 #7
0
        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));
        }
예제 #8
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]);
        }
예제 #9
0
        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]);
        }
예제 #10
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]);
        }
예제 #11
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]);
        }
예제 #12
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]);
        }
예제 #13
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));
        }
예제 #14
0
        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));
        }
예제 #15
0
        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));
        }
예제 #16
0
        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));
        }
예제 #17
0
        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));
        }
예제 #18
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" }));
        }
예제 #19
0
        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]);
        }
예제 #20
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]);
        }
예제 #21
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]);
        }
예제 #22
0
        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);
        }
예제 #23
0
        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);
        }
예제 #24
0
        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));
        }
예제 #25
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));
        }
예제 #26
0
        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]);
        }
예제 #27
0
 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" }));
 }
예제 #28
0
        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));
        }
예제 #29
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);
        }
예제 #30
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));
 }
예제 #31
0
        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);
        }
예제 #32
0
        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);
        }
예제 #33
0
        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);
        }
예제 #34
0
 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" }));
 }
예제 #35
0
        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));
        }
예제 #36
0
        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");
        }
예제 #37
0
        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);
        }
예제 #38
0
        static void Main(string[] args)
        {
            var commandLoop = new CommandLoop();

            commandLoop.Start(args);
        }