コード例 #1
0
        public void IsConnectionActiveWithIdAndUnresponsiveConnection()
        {
            var endpoint     = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var address      = new Uri("http://localhost/discovery");
            var endpointInfo = new EndpointInformation(
                endpoint,
                new DiscoveryInformation(address),
                new ProtocolInformation(
                    new Version(),
                    new Uri("http://localhost/messages"),
                    new Uri("http://localhost/data")));
            var endpoints = new Mock <IStoreInformationAboutEndpoints>();
            {
                endpoints.Setup(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo))
                .Returns(true)
                .Verifiable();
            }

            var commands      = new Mock <ISendCommandsToRemoteEndpoints>();
            var notifications = new Mock <INotifyOfRemoteEndpointEvents>();
            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(false);
            }

            var source = new CancellationTokenSource();

            source.Cancel();
            VerifyEndpointConnectionStatus func =
                (id, timeout) =>
            {
                return(Task.Factory.StartNew(
                           () =>
                {
                },
                           source.Token,
                           TaskCreationOptions.None,
                           new CurrentThreadTaskScheduler()));
            };

            var entryPoint = new CommunicationEntryPoint(
                endpoints.Object,
                commands.Object,
                notifications.Object,
                func,
                configuration.Object);

            endpoints.Raise(e => e.OnEndpointConnected     += null, new EndpointEventArgs(endpoint));
            commands.Raise(c => c.OnEndpointConnected      += null, new EndpointEventArgs(endpoint));
            notifications.Raise(n => n.OnEndpointConnected += null, new EndpointEventArgs(endpoint));

            Assert.IsFalse(entryPoint.IsConnectionActive(endpoint));
        }
コード例 #2
0
        public void OnEndpointDisconnectedForAnUnknownEndpoint()
        {
            var endpoint      = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var address       = new Uri("http://localhost/discovery");
            var endpoints     = new Mock <IStoreInformationAboutEndpoints>();
            var commands      = new Mock <ISendCommandsToRemoteEndpoints>();
            var notifications = new Mock <INotifyOfRemoteEndpointEvents>();
            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(false);
            }

            VerifyEndpointConnectionStatus func = (id, timeout) => null;

            var entryPoint = new CommunicationEntryPoint(
                endpoints.Object,
                commands.Object,
                notifications.Object,
                func,
                configuration.Object);

            EndpointId eventEndpoint = null;

            entryPoint.OnEndpointDisconnected +=
                (s, e) =>
            {
                eventEndpoint = e.Endpoint;
            };

            endpoints.Raise(e => e.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            commands.Raise(c => c.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            notifications.Raise(n => n.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));
        }
コード例 #3
0
        public void IsConnectionActiveWithUrlAndUnknownConnection()
        {
            var endpoint     = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var address      = new Uri("http://localhost/discovery");
            var endpointInfo = new EndpointInformation(
                endpoint,
                new DiscoveryInformation(address),
                new ProtocolInformation(
                    new Version(),
                    new Uri("http://localhost/messages"),
                    new Uri("http://localhost/data")));
            var endpoints = new Mock <IStoreInformationAboutEndpoints>();
            {
                endpoints.Setup(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo))
                .Returns(true)
                .Verifiable();
            }

            var commands      = new Mock <ISendCommandsToRemoteEndpoints>();
            var notifications = new Mock <INotifyOfRemoteEndpointEvents>();
            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(false);
            }

            VerifyEndpointConnectionStatus func = (id, timeout) => null;

            var entryPoint = new CommunicationEntryPoint(
                endpoints.Object,
                commands.Object,
                notifications.Object,
                func,
                configuration.Object);

            Assert.IsFalse(entryPoint.IsConnectionActive(new Uri("http://localhost/invalid")));
        }
コード例 #4
0
        public void OnEndpointDisconnected()
        {
            var endpoint     = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var address      = new Uri("http://localhost/discovery");
            var endpointInfo = new EndpointInformation(
                endpoint,
                new DiscoveryInformation(address),
                new ProtocolInformation(
                    new Version(),
                    new Uri("http://localhost/messages"),
                    new Uri("http://localhost/data")));
            var endpoints = new Mock <IStoreInformationAboutEndpoints>();
            {
                endpoints.Setup(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo))
                .Returns(true)
                .Verifiable();
            }

            var commands      = new Mock <ISendCommandsToRemoteEndpoints>();
            var notifications = new Mock <INotifyOfRemoteEndpointEvents>();
            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(false);
            }

            VerifyEndpointConnectionStatus func = (id, timeout) => null;

            var entryPoint = new CommunicationEntryPoint(
                endpoints.Object,
                commands.Object,
                notifications.Object,
                func,
                configuration.Object);

            EndpointId eventEndpoint = null;

            entryPoint.OnEndpointConnected +=
                (s, e) =>
            {
                eventEndpoint = e.Endpoint;
            };

            entryPoint.OnEndpointDisconnected +=
                (s, e) =>
            {
                eventEndpoint = e.Endpoint;
            };

            endpoints.Raise(e => e.OnEndpointConnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Never());
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            commands.Raise(c => c.OnEndpointConnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Never());
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            notifications.Raise(n => n.OnEndpointConnected += null, new EndpointEventArgs(endpoint));
            Assert.AreSame(endpoint, eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Once());
            Assert.IsTrue(entryPoint.KnownEndpoints().Any());
            Assert.AreSame(endpoint, entryPoint.FromUri(address));

            eventEndpoint = null;
            endpoints.Raise(e => e.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.AreSame(endpoint, eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Once());
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            eventEndpoint = null;
            commands.Raise(c => c.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Once());
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            notifications.Raise(n => n.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Once());
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));
        }