public void AbortTest()
        {
            var process = new MockThreadedBeginStopWithSleepingThreadProcess();
            var target = new ThreadedProcess_Accessor(new PrivateObject(process));

            target.Start();

            Assert.AreEqual(ProcessExecutionState.Running, process.ExecutionState);

            target.Abort();

            Assert.AreEqual(ProcessExecutionState.Terminated, process.ExecutionState);
            Assert.AreEqual(ThreadState.Stopped, target.WorkingThread.ThreadState);
        }
        public void BeginStopTest()
        {
            var process = new MockThreadedBeginStopWithSleepingThreadProcess();
            var target = new ThreadedProcess_Accessor(new PrivateObject(process));

            var state = new MockAsyncState {TestField = "TestFieldValue"};

            target.Start();

            IAsyncResult ar = target.BeginStop(state, StopCallback);

            if (!ar.AsyncWaitHandle.WaitOne(20000))
            {
                Assert.IsTrue(false, "The time given to the process to stop has been exceeded!");
            }

            Assert.IsTrue(ar.IsCompleted);
            Assert.IsTrue(process.ThreadWasInterrupted, "Thread should have been interrupted from its WaitSleepJoin state!");
            beginStopCallbackHandle.WaitOne();
            Assert.IsTrue(beginStopCallbackCalled, "The BeginStopCallback should have been called!");
        }
        public void SelfSuspendTest()
        {
            // time to suspend, ms.
            const int suspendTimeout = 5000;
            MockThreadedSuspendProcess process = new MockThreadedSuspendProcess(suspendTimeout);
            ThreadedProcess_Accessor target = new ThreadedProcess_Accessor(new PrivateObject(process ));

            target.Start();
            // give it some time before calling stop, or if it completes it will set its event (not now :))
            target.CompletedEvent.WaitOne((int)(suspendTimeout*2));

            target.Stop();

            Assert.IsTrue(process.StopWatch.ElapsedMilliseconds >= suspendTimeout);
            Assert.IsTrue(!process.ResumedBeforeTimeout);
        }