Exemplo n.º 1
0
        public void Invoke()
        {
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var remoteEndpoint = new EndpointId("other");
            var reg            = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var eventArgs      = new InteractionExtensionsTest.MySerializableEventArgs();
            var notifications  = new Mock <IRaiseProxyNotifications>();
            {
                notifications.Setup(c => c.RaiseNotification(It.IsAny <EndpointId>(), It.IsAny <NotificationId>(), It.IsAny <EventArgs>()))
                .Callback <EndpointId, NotificationId, EventArgs>(
                    (e, n, a) =>
                {
                    Assert.AreSame(remoteEndpoint, e);
                    Assert.AreSame(reg, n);
                    Assert.AreSame(eventArgs, a);
                })
                .Verifiable();
            }

            var action = new NotificationRaisedProcessAction(notifications.Object, systemDiagnostics);

            action.Invoke(
                new NotificationRaisedMessage(
                    remoteEndpoint,
                    new NotificationRaisedData(reg, eventArgs)));

            notifications.Verify(n => n.RaiseNotification(It.IsAny <EndpointId>(), It.IsAny <NotificationId>(), It.IsAny <EventArgs>()), Times.Once());
        }
        public void ProxyConnectingToEventWithTypedEventHandler()
        {
            var local = new EndpointId("local");
            RegisterForNotificationMessage intermediateMsg = null;
            SendMessage messageSender = (e, m, r) =>
            {
                intermediateMsg = m as RegisterForNotificationMessage;
            };

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

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

            object    sender       = null;
            EventArgs receivedArgs = null;

            proxy.OnMyEvent +=
                (s, e) =>
            {
                sender       = s;
                receivedArgs = e;
            };

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

            Assert.AreEqual(id, intermediateMsg.Notification);

            var notificationObj = proxy as NotificationSetProxy;

            Assert.IsNotNull(notificationObj);

            var args = new InteractionExtensionsTest.MySerializableEventArgs();

            notificationObj.RaiseEvent(id, args);

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