Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        public void CanCancelScriptRunWithNullHost()
        {
            var command = new RunScriptCommand(null);

            Assert.IsFalse(command.CanExecute(null));
        }