Exemple #1
0
        public void Create()
        {
            var id           = new EndpointId("sendingEndpoint");
            var notification = NotificationId.Create(
                typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var msg = new UnregisterFromNotificationMessage(id, notification);

            Assert.AreSame(id, msg.Sender);
            Assert.AreSame(notification, msg.Notification);
        }
        public void Create()
        {
            var id           = new EndpointId("sendingEndpoint");
            var notification = NotificationId.Create(
                typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var args = new MockEventArgs(1);
            var notificationRaised = new NotificationRaisedData(notification, args);
            var msg = new NotificationRaisedMessage(id, notificationRaised);

            Assert.AreSame(id, msg.Sender);
            Assert.AreSame(notification, msg.Notification.Notification);
            Assert.AreSame(args, msg.Notification.EventArgs);
        }
        public void ProxyDisconnectFromEventWithNormalEventHandler()
        {
            var local = new EndpointId("local");
            UnregisterFromNotificationMessage intermediateMsg = null;
            SendMessage messageSender = (e, m, r) =>
            {
                intermediateMsg = m as UnregisterFromNotificationMessage;
            };

            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder           = new NotificationProxyBuilder(local, messageSender, systemDiagnostics);

            var remoteEndpoint = new EndpointId("other");
            var proxy          = builder.ProxyConnectingTo <InteractionExtensionsTest.IMockNotificationSetWithEventHandler>(remoteEndpoint);

            object    sender       = null;
            EventArgs receivedArgs = null;

            EventHandler handler =
                (s, e) =>
            {
                sender       = s;
                receivedArgs = e;
            };

            proxy.OnMyEvent += handler;

            Assert.IsNull(intermediateMsg);

            var notificationObj = proxy as NotificationSetProxy;

            Assert.IsNotNull(notificationObj);

            var id   = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithEventHandler).GetEvent("OnMyEvent"));
            var args = new EventArgs();

            notificationObj.RaiseEvent(id, args);

            Assert.AreSame(proxy, sender);
            Assert.AreSame(args, receivedArgs);

            sender           = null;
            receivedArgs     = null;
            proxy.OnMyEvent -= handler;

            Assert.AreEqual(id, intermediateMsg.Notification);

            notificationObj.RaiseEvent(id, new EventArgs());
            Assert.IsNull(sender);
            Assert.IsNull(receivedArgs);
        }
        public INotification SendTo(INotificationListener listener)
        {
            Require.NotNull(listener, "listener");

            if (IsAddressed && IsAddressedTo(listener))
            {
                return(this);
            }

            return(CopyAndUpdate(properties =>
            {
                properties[NotificationPropertyKeys.Common.NOTIFICATION_ID] = NotificationId.Create().ToString();
                properties[NotificationPropertyKeys.Common.RECIPIENT] = listener.GetType().FullName;
            }));
        }
Exemple #5
0
        public void FromMessage()
        {
            var translator = new NotificationUnregistrationConverter();

            var id  = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var msg = new UnregisterFromNotificationMessage(new EndpointId("a"), id);

            var data = translator.FromMessage(msg);

            Assert.IsInstanceOf(typeof(NotificationUnregistrationData), data);
            Assert.AreSame(msg.Id, data.Id);
            Assert.AreSame(msg.Sender, data.Sender);
            Assert.AreSame(msg.InResponseTo, data.InResponseTo);
            Assert.AreEqual(NotificationIdExtensions.Serialize(id), ((NotificationUnregistrationData)data).NotificationId);
        }
Exemple #6
0
        public void RaiseNotification()
        {
            var localEndpoint     = new EndpointId("local");
            var notifier          = new Mock <IStoreInformationAboutEndpoints>();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var hub = new RemoteNotificationHub(
                notifier.Object,
                new NotificationProxyBuilder(
                    localEndpoint,
                    (e, msg, r) => { },
                    systemDiagnostics),
                systemDiagnostics);

            var endpoint = new EndpointId("other");
            var types    = new List <OfflineTypeInformation>
            {
                new OfflineTypeInformation(
                    typeof(InteractionExtensionsTest.IMockNotificationSetWithEventHandler).FullName,
                    typeof(InteractionExtensionsTest.IMockNotificationSetWithEventHandler).Assembly.GetName())
            };

            hub.OnReceiptOfEndpointNotifications(endpoint, types);

            var proxy = hub.NotificationsFor <InteractionExtensionsTest.IMockNotificationSetWithEventHandler>(endpoint);

            Assert.IsNotNull(proxy);

            var id   = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithEventHandler).GetEvent("OnMyEvent"));
            var args = new EventArgs();

            var wasEventRaised = false;

            proxy.OnMyEvent +=
                (s, e) =>
            {
                wasEventRaised = true;
                Assert.AreSame(args, e);
            };
            hub.RaiseNotification(endpoint, id, args);

            Assert.IsTrue(wasEventRaised);
        }
Exemple #7
0
        public void ToMessage()
        {
            var translator = new NotificationUnregistrationConverter();

            var id   = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var data = new NotificationUnregistrationData
            {
                Id             = new MessageId(),
                InResponseTo   = new MessageId(),
                Sender         = new EndpointId("a"),
                NotificationId = NotificationIdExtensions.Serialize(id),
            };
            var msg = translator.ToMessage(data);

            Assert.IsInstanceOf(typeof(UnregisterFromNotificationMessage), msg);
            Assert.AreSame(data.Id, msg.Id);
            Assert.AreSame(data.Sender, msg.Sender);
            Assert.AreEqual(id, ((UnregisterFromNotificationMessage)msg).Notification);
        }
 protected AbstractNotification()
 {
     m_notificationId   = NotificationId.Create();
     m_notificationType = GetType().FullName;
     m_recipient        = null;
 }