public void CanCancelScriptRunWithNullHost()
        {
            Func <string, IDisposable> func = s => new MockDisposable();

            var command = new CancelScriptRunCommand(null, func);

            Assert.IsFalse(command.CanExecute(null));
        }
        public void CanCancelScriptRunWithNonExecutingHost()
        {
            var scriptHost = new Mock <IHostScripts>();
            {
                scriptHost.Setup(s => s.IsExecutingScript)
                .Returns(false);
            }

            Func <string, IDisposable> func = s => new MockDisposable();

            var command = new CancelScriptRunCommand(scriptHost.Object, func);

            Assert.IsFalse(command.CanExecute(null));
        }
        public void CancelScriptRun()
        {
            var scriptHost = new Mock <IHostScripts>();
            {
                scriptHost.Setup(s => s.IsExecutingScript)
                .Returns(true);
            }

            Func <string, IDisposable> func = s => new MockDisposable();

            var command = new CancelScriptRunCommand(scriptHost.Object, func);

            Assert.IsTrue(command.CanExecute(null));

            var info = new ScriptRunInformation
            {
                ScriptRunningTask = Task.Factory.StartNew(() => { }),
                CancellationToken = new CancellationTokenSource(),
            };

            command.Execute(info);

            Assert.IsTrue(info.CancellationToken.IsCancellationRequested);
        }