Example #1
0
        public void GenerateTypedHandler()
        {
            NotificationDefinition          storedDefinition = null;
            Action <NotificationDefinition> storeDefinition  = d => storedDefinition = d;
            var id     = new NotificationId("a");
            var mapper = new EventMapper(storeDefinition, id);

            var handler = mapper.GenerateHandler <EventArgs>();

            Assert.IsNotNull(storedDefinition);
            Assert.AreEqual(id, storedDefinition.Id);

            var args             = new EventArgs();
            var wasActionInvoked = false;
            Action <NotificationId, EventArgs> action =
                (n, a) =>
            {
                wasActionInvoked = true;
                Assert.AreEqual(id, n);
                Assert.AreSame(args, a);
            };

            storedDefinition.OnNotification(action);

            var obj = new object();

            handler(obj, args);

            Assert.IsTrue(wasActionInvoked);
        }
        public void ForwardToListeners()
        {
            var id         = new NotificationId("a");
            var definition = new NotificationDefinition(id);

            var args = new EventArgs();
            var wasHandlerInvoked = false;
            Action <NotificationId, EventArgs> handler =
                (n, e) =>
            {
                wasHandlerInvoked = true;
                Assert.AreEqual(id, n);
                Assert.AreSame(args, e);
            };

            definition.OnNotification(handler);

            var obj = new object();

            definition.ForwardToListeners(obj, args);

            Assert.IsTrue(wasHandlerInvoked);
        }