public void MsgDispatcherPhysical_ExplicitHandlers() { MsgDispatcher dispatcher; dispatcher = new MsgDispatcher(); dispatcher.AddPhysical(new MsgHandlerDelegate(OnExplicit1), typeof(_DispatchMsg1), null); dispatcher.AddPhysical(new MsgHandlerDelegate(OnExplicit2), typeof(_DispatchMsg2), null); dispatcher.AddPhysical(new MsgHandlerDelegate(OnExplicit3), typeof(_DispatchMsg3), null); Clear(); dispatcher.Dispatch(new _DispatchMsg1()); Thread.Sleep(DispatchWait); Assert.IsTrue(onExplicit1); Assert.IsFalse(onExplicit2); Assert.IsFalse(onExplicit3); Clear(); dispatcher.Dispatch(new _DispatchMsg2()); Thread.Sleep(DispatchWait); Assert.IsFalse(onExplicit1); Assert.IsTrue(onExplicit2); Assert.IsFalse(onExplicit3); Clear(); dispatcher.Dispatch(new _DispatchMsg3()); Thread.Sleep(DispatchWait); Assert.IsFalse(onExplicit1); Assert.IsFalse(onExplicit2); Assert.IsTrue(onExplicit3); }
public void MsgDispatcherPhysical_MultipleHandlers() { MsgDispatcher dispatcher; try { new MsgDispatcher().AddTarget(new Target4()); Assert.Fail("Expected the detection of multiple handlers with the same message type."); } catch (MsgException) { } try { dispatcher = new MsgDispatcher(); dispatcher.AddTarget(new Target2()); dispatcher.AddPhysical(new MsgHandlerDelegate(OnExplicit1), typeof(_DispatchMsg1), null); Assert.Fail("Expected the detection of multiple handlers with the same message type."); } catch (MsgException) { } }