Beispiel #1
0
        public void test_eventdispatch_dispatch()
        {
            EventDispatch dispatch = new EventDispatch();

            MockEventHandler_Test00 handler = new MockEventHandler_Test00();

            dispatch.subscribe(handler);
            dispatch.subscribe(new MockEventHandler_Test01());
            dispatch.subscribe(new MockEventHandler_Test02());

            MockSender s = new MockSender();

            Assert.IsTrue(dispatch.dispatch(new MockEvent_Test00(s)));

            dispatch.unsubscribe(handler);

            Assert.IsFalse(dispatch.dispatch(new MockEvent_Test00(s)));
        }
Beispiel #2
0
        public void test_eventdispatch_unsubscribe()
        {
            EventDispatch dispatch = new EventDispatch();

            MockEventHandler_Test00 handler = new MockEventHandler_Test00();

            dispatch.subscribe(handler);
            dispatch.subscribe(new MockEventHandler_Test01());
            dispatch.subscribe(new MockEventHandler_Test02());

            Assert.That(dispatch.CategoryCount, Is.EqualTo(3));

            Assert.That(dispatch.getHandlers().Length, Is.EqualTo(3));
            Assert.That(dispatch.getHandlers(new BitField((int)EventCategory.TEST_00)).Length, Is.EqualTo(1));

            dispatch.unsubscribe(handler);

            Assert.That(dispatch.CategoryCount, Is.EqualTo(3));         // The category remains inside the dispatchers list, only the handler is removed

            Assert.That(dispatch.getHandlers().Length, Is.EqualTo(2));
            Assert.That(dispatch.getHandlers(handler.EventCategory).Length, Is.EqualTo(0));
        }