public void CancelScriptRun()
        {
            using (var source = new CancellationTokenSource())
            {
                using (var task = Task.Factory.StartNew(
                    () => { },
                    source.Token,
                    TaskCreationOptions.None,
                    new CurrentThreadTaskScheduler()))
                {
                    var tuple = new Tuple<Task, CancellationTokenSource>(task, source);
                    var scriptHost = new Mock<IHostScripts>();
                    {
                        scriptHost.Setup(s => s.Execute(It.IsAny<ScriptLanguage>(), It.IsAny<string>(), It.IsAny<TextWriter>()))
                            .Returns(tuple);
                    }

                    var command = new RunScriptCommand(scriptHost.Object);
                    Assert.IsTrue(command.CanExecute(null));

                    var info = new ScriptRunInformation
                    {
                        Language = ScriptLanguage.IronPython,
                        Script = "a",
                        ScriptOutput = new ScriptOutputPipe(),
                    };
                    command.Execute(info);

                    Assert.AreSame(tuple.Item1, info.ScriptRunningTask);
                    Assert.AreSame(tuple.Item2, info.CancellationToken);
                }
            }
        }
Beispiel #2
0
        public void RunScriptCommandTest()
        {
            // The RunScriptCommand class has optional, non-nullable properties. This test makes sure they
            // actually are nullable, and are not serialized if no explicit value is given.
            var runScriptCommand = new RunScriptCommand();
            var value            = JsonConvert.SerializeObject(runScriptCommand);

            // The only required parameter is ScriptId, so that's the only value which should be visible
            // when using default serialization.
            Assert.AreEqual("{\"ScriptId\":null}", value);
        }
        public void CanCancelScriptRunWithNonExecutingHost()
        {
            var scriptHost = new Mock<IHostScripts>();
            {
                scriptHost.Setup(s => s.IsExecutingScript)
                    .Returns(true);
            }

            var command = new RunScriptCommand(scriptHost.Object);
            Assert.IsFalse(command.CanExecute(null));
        }
Beispiel #4
0
        public void OnExecute_ShowsErrorExits_WhenNoPlatformSpecified()
        {
            // Arrange
            var cmd         = new RunScriptCommand();
            var testConsole = new TestConsole();

            // Act
            var exitCode = cmd.OnExecute(new CommandLineApplication(testConsole), testConsole);

            // Assert
            Assert.NotEqual(0, exitCode);
            Assert.Contains($"Platform name is required", testConsole.StdError);
        }
Beispiel #5
0
        public void Configure_UsesCurrentDirectory_WhenSourceDirectoryNotSupplied()
        {
            // Arrange
            var scriptCommand = new RunScriptCommand {
                AppDir = string.Empty
            };

            // Act
            var processedInput = scriptCommand.IsValidInput(null, null);

            // Assert
            Assert.True(processedInput);
            Assert.Equal(Directory.GetCurrentDirectory(), scriptCommand.AppDir);
        }
Beispiel #6
0
        public ScriptPageViewModel(string filePath)
        {
            FilePath   = filePath;
            RunOptions = new RunOptions();

            SaveFileCommand                      = new SaveFileCommand(SaveFile);
            RunScriptCommand                     = new RunScriptCommand(RunScript);
            SetOutputTextFileCommand             = new SetOutputTextFileCommand(SetOutputTextFilePath);
            SetOutputImageDirectoryCommand       = new SetOutputImageDirectoryCommand(SetOutputImageDirectoryPath);
            SetWebDriverPathCommand              = new SetWebDriverPathCommand(SetWebDriverPath);
            ClearOutputTextFilePathCommand       = new ClearInputStringCommand(ClearOutputTextFilePath);
            ClearOutputImageDirectoryPathCommand = new ClearInputStringCommand(ClearOutputImageDirectoryPath);
            ClearWebDriverPathCommand            = new ClearInputStringCommand(ClearWebDriverPath);
            StopScriptCommand                    = new StopScriptCommand(StopScript);

            TryOpenSelf();
        }
Beispiel #7
0
        public void OnExecute_ShowsErrorExits_WhenPlatformDoesNotExist()
        {
            // Arrange
            var nonexistentPlatformName = "bla";
            var cmd = new RunScriptCommand
            {
                PlatformName = nonexistentPlatformName
            };
            var testConsole = new TestConsole();

            // Act
            var exitCode = cmd.OnExecute(new CommandLineApplication(testConsole), testConsole);

            // Assert
            Assert.NotEqual(0, exitCode);
            Assert.Contains($"Platform '{nonexistentPlatformName}' is not supported", testConsole.StdError);
        }
Beispiel #8
0
        public void OnExecute_ShowsHelp_AndExits_WhenSourceDirectoryDoesNotExist()
        {
            // Arrange
            var scriptCommand = new RunScriptCommand
            {
                AppDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())
            };
            var testConsole = new TestConsole();

            // Act
            var exitCode = scriptCommand.OnExecute(new CommandLineApplication(testConsole), testConsole);

            // Assert
            Assert.NotEqual(0, exitCode);
            var error = testConsole.StdError;

            Assert.DoesNotContain("Usage:", error);
            Assert.Contains("Could not find the source directory", error);
        }
 public void CanCancelScriptRunWithNullHost()
 {
     var command = new RunScriptCommand(null);
     Assert.IsFalse(command.CanExecute(null));
 }