Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoteNotificationHub"/> class.
 /// </summary>
 /// <param name="endpointInformationStorage">The object that provides notification of the signing in and signing out of endpoints.</param>
 /// <param name="builder">The object that is responsible for building the command proxies.</param>
 /// <param name="systemDiagnostics">The object that provides the diagnostic methods for the system.</param>
 /// <exception cref="ArgumentNullException">
 ///     Thrown if <paramref name="endpointInformationStorage"/> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ArgumentNullException">
 ///     Thrown if <paramref name="builder"/> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ArgumentNullException">
 ///     Thrown if <paramref name="systemDiagnostics"/> is <see langword="null" />.
 /// </exception>
 internal RemoteNotificationHub(
     IStoreInformationAboutEndpoints endpointInformationStorage,
     NotificationProxyBuilder builder,
     SystemDiagnostics systemDiagnostics)
     : base(
         endpointInformationStorage,
         (endpoint, type) => (NotificationSetProxy)builder.ProxyConnectingTo(endpoint, type),
         systemDiagnostics)
 {
     {
         Lokad.Enforce.Argument(() => builder);
     }
 }
        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);
        }