示例#1
0
        public void RecentlyConnectedEndpointWithCommunicationFault()
        {
            var translator  = new Mock <ITranslateVersionedChannelInformation>();
            var translators = new[]
            {
                new Tuple <Version, ITranslateVersionedChannelInformation>(new Version(1, 0), translator.Object),
            };

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

            var template = new NamedPipeDiscoveryChannelTemplate(configuration.Object);
            Func <ChannelTemplate, IDiscoveryChannelTemplate> templateBuilder = t => template;
            var diagnostics = new SystemDiagnostics((l, s) => { }, null);
            var discovery   = new ManualDiscoverySource(
                translators,
                templateBuilder,
                diagnostics);

            discovery.OnEndpointBecomingAvailable += (s, e) => Assert.Fail();
            discovery.StartDiscovery();

            var uri      = new Uri("net.pipe://localhost/pipe/discovery");
            var receiver = new MockEndpoint(
                () =>
            {
                throw new ArgumentException();
            },
                null);

            var host    = new ServiceHost(receiver, uri);
            var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                TransferMode = TransferMode.Buffered,
            };
            var address  = string.Format("{0}_{1}", "ThroughNamedPipe", Process.GetCurrentProcess().Id);
            var endpoint = host.AddServiceEndpoint(typeof(IBootstrapEndpoint), binding, address);

            host.Open();
            try
            {
                discovery.RecentlyConnectedEndpoint(
                    EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                    endpoint.ListenUri);
            }
            finally
            {
                host.Close();
            }
        }
示例#2
0
        public void RecentlyDisconnectedEndpoint()
        {
            var translator  = new Mock <ITranslateVersionedChannelInformation>();
            var translators = new[]
            {
                new Tuple <Version, ITranslateVersionedChannelInformation>(new Version(1, 0), translator.Object),
            };

            var template = new Mock <IDiscoveryChannelTemplate>();
            {
                template.Setup(t => t.GenerateBinding())
                .Verifiable();
            }

            Func <ChannelTemplate, IDiscoveryChannelTemplate> templateBuilder =
                t =>
            {
                return(template.Object);
            };
            var diagnostics = new SystemDiagnostics((l, s) => { }, null);
            var discovery   = new ManualDiscoverySource(
                translators,
                templateBuilder,
                diagnostics);

            discovery.StartDiscovery();

            var eventWasRaised = false;

            discovery.OnEndpointBecomingUnavailable += (s, e) =>
            {
                eventWasRaised = true;
            };
            discovery.RecentlyDisconnectedEndpoint(new EndpointId("a"));

            Assert.IsTrue(eventWasRaised);
        }
示例#3
0
        public void RecentlyConnectedEndpoint()
        {
            var uri          = new Uri("net.pipe://localhost/pipe/discovery/");
            var versionedUri = new Uri(uri, new Uri("/1.0", UriKind.Relative));
            var protocolInfo = new ProtocolInformation(
                new Version(2, 0),
                new Uri("http://localhost/protocol/message/invalid"),
                new Uri("http://localhost/protocol/data/invalid"));
            var translator = new Mock <ITranslateVersionedChannelInformation>();
            {
                translator.Setup(t => t.FromUri(It.IsAny <Uri>()))
                .Callback <Uri>(u => Assert.AreEqual(versionedUri, u))
                .Returns(protocolInfo);
            }

            var translators = new[]
            {
                new Tuple <Version, ITranslateVersionedChannelInformation>(new Version(1, 0), translator.Object),
            };

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

            var template = new NamedPipeDiscoveryChannelTemplate(configuration.Object);
            Func <ChannelTemplate, IDiscoveryChannelTemplate> templateBuilder = t => template;
            var diagnostics = new SystemDiagnostics((l, s) => { }, null);
            var discovery   = new ManualDiscoverySource(
                translators,
                templateBuilder,
                diagnostics);

            var eventWasRaised = false;

            discovery.OnEndpointBecomingAvailable += (s, e) =>
            {
                eventWasRaised = true;
            };
            discovery.StartDiscovery();

            var channels = new[]
            {
                new Tuple <Version, Uri>(new Version(1, 0), versionedUri),
            };
            var receiver = new BootstrapEndpoint(channels);

            var host    = new ServiceHost(receiver, uri);
            var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
            {
                TransferMode = TransferMode.Buffered,
            };
            var address  = string.Format("{0}_{1}", "ThroughNamedPipe", Process.GetCurrentProcess().Id);
            var endpoint = host.AddServiceEndpoint(typeof(IBootstrapEndpoint), binding, address);

            host.Open();
            try
            {
                discovery.RecentlyConnectedEndpoint(
                    EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                    endpoint.ListenUri);
            }
            finally
            {
                host.Close();
            }

            Assert.IsTrue(eventWasRaised);
        }