public void test_eventdispatch_subscribe() { EventDispatch dispatch = new EventDispatch(); dispatch.subscribe(new MockEventHandler_Test00()); 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)); }
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)); }