Beispiel #1
0
        public static void NoEventsOrSubscribersAfterStopping()
        {
            var queue      = new TaskEventQueue();
            var subscriber = new TestEventHandler();

            queue.Subscribers.AddAll(subscriber);

            queue.BeginShutdown();
            Thread.Sleep(SleepTime);
            Assert.False(IsRunning(queue));

            queue.Enqueue(new TestEvent());
            Thread.Sleep(SleepTime);
            Assert.Null(subscriber.LastEventHandled);
            Assert.False(queue.Subscribers.AddAll(new TestEventHandler(), weakRef: false));
        }
Beispiel #2
0
        public static void EmptyingQueueDoesNotShutItDown()
        {
            var queue      = new TaskEventQueue();
            var subscriber = new TestEventHandler();

            queue.Subscribers.AddAll(subscriber);

            Thread.Sleep(SleepTime);
            Assert.True(IsRunning(queue));

            queue.Enqueue(new TestEvent());
            Thread.Sleep(SleepTime);
            Assert.NotNull(subscriber.LastEventHandled);
            Assert.True(IsRunning(queue));

            queue.BeginShutdown();
            Thread.Sleep(SleepTime);
            Assert.False(IsRunning(queue));
        }
Beispiel #3
0
        public static void EventHandlingSuspension()
        {
            var queue = new TaskEventQueue();

            Assert.False(queue.EventHandling.IsSuspended);

            var subscriber = new TestEventHandler();

            queue.Subscribers.AddAll(subscriber);
            var evnt = new TestEvent();

            queue.EventHandling.Suspend();
            queue.Enqueue(evnt);
            Thread.Sleep(SleepTime);
            Assert.Null(subscriber.LastEventHandled);

            queue.EventHandling.Resume();
            Thread.Sleep(SleepTime);
            Assert.AreSame(evnt, subscriber.LastEventHandled);

            queue.BeginShutdown();
        }