Inheritance: ICommandFactory
Example #1
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" }));
        }
Example #2
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]);
        }
Example #3
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));
        }
Example #4
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]);
        }
Example #5
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]);
        }
Example #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" }));
        }
Example #7
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));
        }
Example #8
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));
        }
Example #9
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]);
        }
Example #10
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));
        }
Example #11
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]);
        }
Example #12
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));
        }
Example #13
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));
        }
Example #14
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" }));
 }
Example #15
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));
        }
Example #16
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]);
        }
Example #17
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" }));
 }
Example #18
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));
        }
Example #19
0
 public CommandLoop(IConsole console, CommandFactory commandFactory): this(console,commandFactory, new CommandPropertyWalker())
 {
 }
Example #20
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);
        }
Example #21
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");
        }
Example #22
0
 public CommandLoop(IConsole console, CommandFactory commandFactory, ICommandPropertyWalker commandPropertyWalker)
 {
     Console = console;
     _commandFactory = commandFactory;
     _commandPropertyWalker = commandPropertyWalker;
 }
Example #23
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));
 }
Example #24
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);
        }
Example #25
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);
        }
Example #26
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));
        }
Example #27
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);
        }
Example #28
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);
        }
Example #29
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));
        }