Example #1
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);
        }
Example #2
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);
        }