public void OeExecution_Test_Killed()
        {
            if (!GetEnvExecution(out UoeExecutionEnv env))
            {
                return;
            }
            env.UseProgressCharacterMode = true;
            using (var exec = new UoeExecutionCustomTest(env)) {
                exec.ProgramContent           = "PAUSE 100.";
                _iOeExecutionTestKilledEvents = 0;
                exec.OnExecutionEnd          += execution => _iOeExecutionTestKilledEvents++;
                exec.ExecuteNoWait();
                Task.Factory.StartNew(() => {
                    Thread.Sleep(1000);
                    exec.KillProcess();
                });
                exec.WaitForExit();
                Assert.IsTrue(exec.ExecutionHandledExceptions, "has exceptions");
                Assert.IsTrue(exec.HasBeenKilled, "has been killed");
                Assert.IsTrue(exec.ExecutionFailed, "has failed");
                Assert.IsInstanceOfType(exec.HandledExceptions[0], typeof(UoeExecutionKilledException));

                // the end event executed correctly even if the process has been killed
                Assert.IsNotNull(exec.ExecutionTimeSpan);
                Assert.AreEqual(1, _iOeExecutionTestKilledEvents);
            }
            env.Dispose();
        }
        public void OeExecution_Test_WaitFor_with_cancel_source()
        {
            if (!GetEnvExecution(out UoeExecutionEnv env))
            {
                return;
            }
            env.UseProgressCharacterMode = true;
            using (var exec = new UoeExecutionCustomTest(env)) {
                exec.ProgramContent = "PAUSE 100.";
                exec.ExecuteNoWait();
                using (var cancel = new CancellationTokenSource()) {
                    exec.CancelToken = cancel.Token;
                    exec.WaitForExit(200);
                    Assert.IsNull(exec.ExecutionTimeSpan, "the execution isn't over");
                    exec.WaitForExit(200);
                    Assert.IsNull(exec.ExecutionTimeSpan, "the execution still isn't over");
                    Task.Factory.StartNew(() => {
                        Thread.Sleep(200);
                        cancel.Cancel();
                    });
                    var d = DateTime.Now;
                    exec.WaitForExit(1400);
                    Assert.IsNotNull(exec.ExecutionTimeSpan, "the execution is now over because it has been cancelled");
                    Assert.IsTrue(DateTime.Now.Subtract(d).TotalMilliseconds < 800, "it should have waited for the cancel and not for 2000ms (note that it has a rough precision...)");
                }
                exec.KillProcess();
                exec.WaitForExit();
                Assert.IsTrue(exec.HasBeenKilled, "has been killed");
                Assert.IsInstanceOfType(exec.HandledExceptions[0], typeof(UoeExecutionKilledException));

                // the end event executed correctly even if the process has been killed
                Assert.IsNotNull(exec.ExecutionTimeSpan);
            }
            env.Dispose();
        }