public void TestBadRegister()
        {
            var target = new MessageMediator();
            var tc     = new TestCounter();

            target.Register(tc);
            Assert.ThrowsException <ArgumentException>(() => target.RegisterHandler <int>("test", tc.MessageHandler5));
            target.Unregister(tc);
        }
        public void SingleRegisterTest()
        {
            var  target     = new MessageMediator();
            bool passedTest = false;

            target.RegisterHandler("test", (string o) => passedTest = (o == "Test"));
            bool hadTarget = target.SendMessage("test", "Test");

            Assert.AreEqual(true, hadTarget, "Mediator did not return success");
            Assert.AreEqual(true, passedTest, "Did not receive message");
        }
        public void TestBadRegister()
        {
            var target = new MessageMediator();
            var tc     = new TestCounter();

            target.Register(tc);

            try
            {
                target.RegisterHandler <int>("test", tc.MessageHandler5);
                Assert.Fail("Did not throw exception on invalid register");
            }
            catch (ArgumentException)
            {
            }
        }
        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.AreEqual(false, hadTarget, "Mediator found unexpected target");

            hadTarget = target.SendMessage("test6", 5);
            Assert.AreEqual(true, hadTarget, "Mediator did not find target");
            Assert.AreEqual <int>(5, tc.Count);
        }
        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 TestIntParam()
        {
            var target = new MessageMediator();
            var tc     = new TestCounter();

            target.Register(tc);

            bool hadTarget = target.SendMessage(5);

            Assert.IsFalse(hadTarget, "Mediator found unexpected target");

            target.RegisterHandler <int>(tc.MessageHandler5);
            hadTarget = target.SendMessage(5);
            Assert.IsTrue(hadTarget, "Mediator did not find target");
            Assert.AreEqual(5, tc.Count);

            target.Unregister(tc);
            target.UnregisterHandler <int>(tc.MessageHandler5);
            Assert.IsFalse(target.SendMessage(5));
        }