Beispiel #1
0
        private void WithWorkerThread(Action <WorkerThread, EventMonitor <WorkerThread> > testCase, bool started = true, bool expectStopped = false)
        {
            var wt    = CreateWorkerThread();
            var wtMon = new EventMonitor <WorkerThread>(wt);

            if (started)
            {
                wt.Start();
                AssertState(wt, isDisposed: false, isAlive: true, busy: false);
                wtMon.History.AssertSender(wt);
                wtMon.FilterHistory(ByPropertyChanges <bool>(nameof(WorkerThread.IsAlive)))
                .AssertPropertyValues(true);
            }
            wtMon.ClearHistory();

            testCase(wt, wtMon);

            wtMon.ClearHistory();

            wt.Queue.Dispose();
            wt.Dispose();
            AssertState(wt, isDisposed: true, isAlive: false, busy: false);
            wtMon.History.AssertSender(wt);
            if (expectStopped)
            {
                Assert.IsTrue(
                    wtMon.FilterHistory(ByPropertyChanges <bool>(nameof(WorkerThread.IsAlive)))
                    .IsEmpty);
            }
            else
            {
                wtMon.FilterHistory(ByPropertyChanges <bool>(nameof(WorkerThread.IsAlive)))
                .AssertPropertyValues(false);
            }
        }
Beispiel #2
0
        private void WithWorkingLine(Action <WorkingLine, EventMonitor <WorkingLine> > testCase, int worker = 1, bool started = true)
        {
            var wl    = CreateWorkingLine(worker);
            var wlMon = new EventMonitor <WorkingLine>(wl);

            AssertState(wl, isDisposed: false, busy: false);
            AssertThreadsState(wl, isDisposed: false, isAlive: false, busy: false);

            if (started)
            {
                wl.Start();
                AssertState(wl, isDisposed: false, busy: false);
                AssertThreadsState(wl, isDisposed: false, isAlive: true, busy: false);
                Assert.IsTrue(wlMon.History.IsEmpty);
            }
            wlMon.ClearHistory();

            testCase(wl, wlMon);

            wlMon.ClearHistory();

            wl.Dispose();
            AssertState(wl, isDisposed: true, busy: false);
            AssertThreadsState(wl, isDisposed: true, isAlive: false, busy: false);

            Assert.IsTrue(wlMon.History.IsEmpty);
        }
Beispiel #3
0
        private void WithTaskManager <T>(
            Func <TaskManager, EventMonitor <TaskManager>, T> beforeStart,
            Action <TaskManager, EventMonitor <TaskManager>, T> afterFinish,
            params Tuple <string, int>[] workingLineDescriptions)
        {
            var tm    = CreateTaskManager(workingLineDescriptions);
            var tmMon = new EventMonitor <TaskManager>(tm);

            var finishedEvent = new ManualResetEvent(false);

            tm.Finished += (sender, e) => finishedEvent.Set();

            T cache = (T)beforeStart.Invoke(tm, tmMon);

            tmMon.ClearHistory();

            tm.Start();

            var waitForFinishResult = finishedEvent.WaitOne(10000);

            finishedEvent.Close();
            var waitForEndResult = tm.WaitForEnd(1000);

            afterFinish.Invoke(tm, tmMon, cache);

            tmMon.ClearHistory();

            Assert.IsTrue(waitForEndResult, "WaitForEnd did not finish in time.");
            Assert.IsTrue(waitForFinishResult, "The event TaskManager.Finished did not fire in time.");

            Assert.IsFalse(tm.IsDisposed);
            tm.Dispose();
            AssertState(tm, isDisposed: true, isRunning: false);
            tmMon.History
            .AssertSender(tm)
            .AssertEventNames(nameof(TaskManager.Disposed));
        }