public void RegisterSingleHandler() { var target = new MessageMediator(); bool passedTest = false; Action <string> handler = o => passedTest = (o == "Test"); target.RegisterHandler("test", handler); bool hadTarget = target.SendMessage("test", "Test"); Assert.IsTrue(hadTarget, "Mediator did not return success"); Assert.IsTrue(passedTest, "Did not receive message"); target.UnregisterHandler("test", handler); Assert.IsFalse(target.SendMessage("test", "Test")); }
public void TestIntParam2() { var target = new MessageMediator(); var tc = new TestCounter(); target.Register(tc); target.RegisterHandler <int>("test6", tc.MessageHandler6); bool hadTarget = target.SendMessage(5); Assert.IsFalse(hadTarget, "Mediator found unexpected target"); hadTarget = target.SendMessage("test6", 5); Assert.IsTrue(hadTarget, "Mediator did not find target"); Assert.AreEqual(5, tc.Count); target.UnregisterHandler <int>("test6", tc.MessageHandler6); target.Unregister(tc); Assert.IsFalse(target.SendMessage("test6", 5)); }