コード例 #1
0
        /// <summary>
        /// Creates the notification map for the given notification interface.
        /// </summary>
        /// <returns>The notification map.</returns>
        /// <exception cref="NotificationEventNotMappedException">
        ///     Thrown when one or more of the events on the notification interface are not mapped to instance events.
        /// </exception>
        public NotificationMap ToMap()
        {
            var type   = typeof(TNotification);
            var events = type.GetEvents();

            foreach (var eventInfo in events)
            {
                var id = NotificationId.Create(eventInfo);
                if (!m_Definitions.ContainsKey(id))
                {
                    throw new NotificationEventNotMappedException();
                }
            }

            return(new NotificationMap(type, m_Definitions.Values.ToArray()));
        }
コード例 #2
0
        public void FromWithEventUnregistration()
        {
            var mapper = NotificationMapper <IMockNotificationSet> .Create();

            mapper.From(s => s.OnMyEvent -= null)
            .GenerateHandler();

            var map = mapper.ToMap();

            Assert.AreEqual(1, map.Definitions.Length);

            var def = map.Definitions[0];

            var id = NotificationId.Create(typeof(IMockNotificationSet).GetEvent("OnMyEvent"));

            Assert.AreEqual(id, def.Id);
        }
コード例 #3
0
        public void RegisterWithoutBeingSignedIn()
        {
            var         wasInvoked = false;
            SendMessage sender     =
                (endpoint, message, retries) =>
            {
                wasInvoked = true;
            };

            var collection = new LocalNotificationCollection(new EndpointId("a"), sender);

            var id  = NotificationId.Create(typeof(IMockNotificationSet).GetEvent("OnMyEvent"));
            var def = new NotificationDefinition(id);

            collection.Register(new[] { def });

            Assert.AreEqual(1, collection.Count(pair => pair.Equals(id)));
            Assert.IsFalse(wasInvoked);
        }
コード例 #4
0
        public void RaiseNormalEvent()
        {
            var                   knownEndpoint = new EndpointId("other");
            EndpointId            other         = null;
            ICommunicationMessage msg           = null;
            var                   wasInvoked    = false;
            SendMessage           sender        =
                (endpoint, message, retries) =>
            {
                wasInvoked = true;
                other      = endpoint;
                msg        = message;
            };

            var collection = new LocalNotificationCollection(new EndpointId("a"), sender);

            var id  = NotificationId.Create(typeof(IMockNotificationSet).GetEvent("OnMyEvent"));
            var def = new NotificationDefinition(id);
            var obj = new MockNotificationSet();

            obj.OnMyEvent += def.ForwardToListeners;
            collection.Register(new[] { def });

            Assert.AreEqual(1, collection.Count(pair => pair.Equals(id)));
            Assert.IsFalse(wasInvoked);

            collection.RegisterForNotification(knownEndpoint, id);

            var args = new EventArgs();

            obj.RaiseOnMyEvent(args);

            Assert.IsTrue(wasInvoked);
            Assert.AreEqual(knownEndpoint, other);
            Assert.IsInstanceOf <NotificationRaisedMessage>(msg);

            var notificationMsg = msg as NotificationRaisedMessage;

            Assert.AreEqual(id, notificationMsg.Notification.Notification);
            Assert.AreSame(args, notificationMsg.Notification.EventArgs);
        }