Пример #1
0
        public static void ShutdownRequest_Cancelled()
        {
            var queue = new ManualEventQueue();

            queue.Subscribers.Add(
                DelegateEventHandler.OnShutdownRequest(
                    e => e.Cancel = true),
                weakRef: false);

            // you can only add one request at a time
            Assert.True(queue.RequestShutdown());
            Assert.False(queue.RequestShutdown());

            // cancel the request
            Assert.True(queue.HandleNext());

            // no shutting down event
            Assert.False(queue.HandleNext());

            // you can add another request, once the previous one is out of the queue
            Assert.True(queue.RequestShutdown());
            Assert.True(queue.HandleNext());
            Assert.False(queue.HandleNext());
        }
Пример #2
0
        public static void ShutdownRequest_NotCancelled()
        {
            var queue = new ManualEventQueue();

            bool shuttingDownDetected = false;

            queue.Subscribers.Add(
                DelegateEventHandler.OnShuttingDown(
                    e => shuttingDownDetected = true),
                weakRef: false);

            // requests are granted by default (Cancel is false)
            Assert.True(queue.RequestShutdown());
            Assert.True(queue.HandleNext()); // request event
            Assert.False(shuttingDownDetected);
            Assert.True(queue.HandleNext()); // shutting down event
            Assert.True(shuttingDownDetected);
            Assert.True(queue.HandleNext()); // shut down event
            Assert.False(queue.HandleNext());
            Assert.True(queue.IsShutDown);
        }
Пример #3
0
        public static void ShutdownRequestHandler()
        {
            var queue = new ManualEventQueue();

            // create subscriber
            ShutdownRequestEvent lastEventHandled = null;
            var subscriber = DelegateEventHandler.OnShutdownRequest(evnt => lastEventHandled = evnt);

            queue.Subscribers.Add(subscriber);

            // enqueue and handle event
            queue.RequestShutdown();
            Assert.Null(lastEventHandled);
            Assert.True(queue.HandleNext());

            // test subscriber
            Assert.NotNull(lastEventHandled);
            Assert.True(queue.HandleNext()); // shutting down event
            Assert.True(queue.HandleNext()); // shut down event
            Assert.True(queue.IsShutDown);
        }