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" })); }
static async Task Main() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { int width = Math.Min(Console.LargestWindowWidth, 150); int height = Math.Min(Console.LargestWindowHeight, 40); Console.SetWindowSize(width, height); } try { // Read configuration data from the IConfiguration config = new ConfigurationBuilder() .AddJsonFile("serviceConfig.json", false, true) .Build(); clientId = config["clientId"]; tenantId = config["tenantId"]; adtInstanceUrl = config["instanceUrl"]; } catch (Exception e) { Log.Error($"Could not read service configuration file serviceConfig.json"); Log.Alert($"Please copy serviceConfig.json.TEMPLATE to serviceConfig.json"); Log.Alert($"and edit to reflect your service connection settings."); Log.Alert($"Make sure that 'Copy always' or 'Copy if newer' is set for serviceConfig.json in VS file properties"); Environment.Exit(0); } Log.Ok("Authenticating..."); try { var credential = new InteractiveBrowserCredential(tenantId, clientId); client = new DigitalTwinsClient(new Uri(adtInstanceUrl), credential); // force authentication to happen here try { client.GetDigitalTwin("---"); } catch (RequestFailedException rex) { } catch (Exception e) { Log.Error($"Authentication or client creation error: {e.Message}"); Log.Alert($"Have you checked that the configuration in serviceConfig.json is correct?"); Environment.Exit(0); } } catch (Exception e) { Log.Error($"Authentication or client creation error: {e.Message}"); Log.Alert($"Have you checked that the configuration in serviceConfig.json is correct?"); Environment.Exit(0); } Log.Ok($"Service client created – ready to go"); CommandLoop CommandLoopInst = new CommandLoop(client); await CommandLoopInst.CliCommandInterpreter(); }
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 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)); }
private static CancellationTokenSource GetCommandLoopCancellationTokenSource( CommandLoop commandLoop) { return((CancellationTokenSource)typeof(CommandLoop) .GetField( "cancellationTokenSource", BindingFlags.Instance | BindingFlags.NonPublic) .GetValue(commandLoop)); }
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 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 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 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 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 BeforeTest() { var commandFactoryMock = new Mock <CommandFactory>(); this.commandGroupMetadataFactoryMock = new Mock <CommandGroupMetadataFactory>(); this.commandResolver = new CommandResolver(commandFactoryMock.Object); this.commandLoop = new CommandLoop( this.commandResolver, this.commandGroupMetadataFactoryMock.Object); }
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 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)); }
/// <summary> /// Initializes a new instance of the <see cref="HelpCommand"/> class. /// </summary> /// <param name="commandLoop">The <see cref="CommandLoop"/> that this /// <see cref="HelpCommand"/> will use to get the current command group from.</param> /// <param name="commandGroupMetadataFactory">The /// <see cref="CommandGroupMetadataFactory"/> to use to create a collection of /// instances of <see cref="CommandMetadata"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="commandLoop"/>, or /// <paramref name="commandGroupMetadataFactory"/> is <see langword="null"/>.</exception> public HelpCommand( CommandLoop commandLoop, CommandGroupMetadataFactory commandGroupMetadataFactory) { ParameterValidation.IsNotNull(commandLoop, nameof(commandLoop)); ParameterValidation.IsNotNull( commandGroupMetadataFactory, nameof(commandGroupMetadataFactory)); this.commandLoop = commandLoop; this.commandGroupMetadataFactory = commandGroupMetadataFactory; }
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); }
static async Task Main() { SetWindowSize(); Uri adtInstanceUrl; try { // Read configuration data from the IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false) .Build(); adtInstanceUrl = new Uri(config["instanceUrl"]); } catch (Exception ex) when(ex is FileNotFoundException || ex is UriFormatException) { Log.Error($"Could not read configuration. Have you configured your ADT instance URL in appsettings.json?\n\nException message: {ex.Message}"); return; } Log.Ok("Authenticating..."); var credential = new DefaultAzureCredential(); client = new DigitalTwinsClient(adtInstanceUrl, credential); Log.Ok($"Service client created – ready to go"); Log.Out($"Initializing Building Scenario..."); var CommandLoopInst = new CommandLoop(client); string[] dummy = new string[1]; await CommandLoopInst.CommandDeleteAllModels(dummy); var b = new BuildingScenario(CommandLoopInst); await b.InitBuilding(); // //await CommandLoopInst.CliCommandInterpreter(); }
internal static Meta <ICommand, CommandMetadata> CreateExitCommandMeta( CommandLoop commandLoop) { var exitCommandMock = new Mock <ICommand>(); exitCommandMock .Setup(c => c.Execute(It.IsAny <CancellationToken>())) .Callback(commandLoop.Exit); var exitCommandMetadata = new CommandMetadata { Group = "CommandGroup", Name = "exit", HelpText = "Exit help text.", ParametersMetadata = new CommandParameterMetadata[0] }; var exitCommandMeta = new Meta <ICommand, CommandMetadata>( exitCommandMock.Object, exitCommandMetadata); return(exitCommandMeta); }
public void BeforeTest() { var commandFactoryMock = new Mock <CommandFactory>(); this.commandGroupMetadataFactoryMock = new Mock <CommandGroupMetadataFactory>(); this.commandResolver = new CommandResolver(commandFactoryMock.Object); this.commandLoop = new CommandLoop( this.commandResolver, this.commandGroupMetadataFactoryMock.Object); #pragma warning disable CC0031 // Check for null before calling a delegate this.commandGroupMetadataFactoryMock .Setup(f => f(this.commandLoop.CurrentGroup)) .Returns(new[] { new CommandMetadata { Group = this.commandLoop.CurrentGroup, Name = "Command0", HelpText = "This is some help text.", ParametersMetadata = new[] { new CommandParameterMetadata { Index = 0, Name = "Arg0", HelpText = "This is some parameter help text." } } }, new CommandMetadata { Group = this.commandLoop.CurrentGroup, Name = "Command1", HelpText = "This is some more help text.", ParametersMetadata = new CommandParameterMetadata[0] } }); #pragma warning restore CC0031 // Check for null before calling a delegate }
/// <summary> /// Конструктор /// </summary> /// <param name="loop">Цикл</param> public SearchCommand(CommandLoop loop) : base(loop, 1)//Команда с одним параметром { }
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 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); }
internal void endLoop() { this.currentLoop = null; this.insideLoop = false; }
public virtual void startLoop(int startTime, int loopCount) { this.currentLoop = new CommandLoop(startTime, loopCount); AddCommand(currentLoop); this.insideLoop = true; }
/// <summary> /// Конструктор /// </summary> /// <param name="loop">Цикл</param> public ExitCommand(CommandLoop loop) : base(loop, 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 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)); }
public PrintAllCommand(CommandLoop loop) : base(loop, 0) { }
public BuildingScenario(CommandLoop cl) { this.cl = cl; }
public SearchCommand(CommandLoop loop) : base(loop, 1) { }
/// <summary> /// Конструктор /// </summary> /// <param name="loop">Цикл</param> public AddCommand(CommandLoop loop) : base(loop, 2) //Требуется два параметра { }
/// <summary> /// Initializes a new instance of the <see cref="ExitCommand"/> class. /// </summary> /// <param name="commandLoop">The <see cref="CommandLoop"/> that this /// <see cref="ExitCommand"/> will cause to exit.</param> /// <exception cref="ArgumentNullException"><paramref name="commandLoop"/> is /// <see langword="null"/>.</exception> public ExitCommand(CommandLoop commandLoop) { ParameterValidation.IsNotNull(commandLoop, nameof(commandLoop)); this.commandLoop = commandLoop; }
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 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 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 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)); }
/// <summary> /// Конструктор /// </summary> /// <param name="loop">Цикл</param> public PrintAllCommand(CommandLoop loop) : base(loop, 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 virtual void startTriggerLoop(string loopTrigger, int startTime, int endTime) { this.currentLoop = new CommandTriggerLoop(loopTrigger, startTime, endTime); AddCommand(currentLoop); this.insideLoop = true; }
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"); }
static void Main(string[] args) { var commandLoop = new CommandLoop(); commandLoop.Start(args); }
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 BuildingScenario(CommandLoop cl_) { cl = cl_; }
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)); }