Beispiel #1
0
        /// <summary>
        /// Translates the <see cref="VersionedChannelInformation"/> to the current version of <see cref="EndpointInformation"/>.
        /// </summary>
        /// <param name="info">The object describing the versioned channel information.</param>
        /// <returns>A pair containing the ID of the endpoint and the protocol information for the endpoint.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="info"/> is <see langword="null" />.
        /// </exception>
        public static ProtocolInformation FromVersioned(VersionedChannelInformation info)
        {
            {
                Lokad.Enforce.Argument(() => info);
            }

            return(new ProtocolInformation(info.ProtocolVersion, info.Address));
        }
Beispiel #2
0
        public void FromUri()
        {
            var protocolVersions = new[]
            {
                new Version(1, 0),
            };

            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 translator  = new DiscoveryChannelTranslator(
                protocolVersions,
                templateBuilder,
                diagnostics);

            var info = new VersionedChannelInformation
            {
                ProtocolVersion = new Version(1, 0),
                Address         = new Uri("http://localhost/protocol/invalid")
            };
            var receiver = new MockEndpoint(
                () => DiscoveryVersions.V1,
                () => new[] { new Version(1, 0), },
                v => info);

            var uri     = new Uri("net.pipe://localhost/pipe/discovery");
            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(IInformationEndpoint), binding, address);

            host.Open();
            try
            {
                var receivedInfo = translator.FromUri(endpoint.ListenUri);
                Assert.IsNotNull(receivedInfo);
                Assert.AreEqual(info.ProtocolVersion, receivedInfo.Version);
                Assert.AreEqual(info.Address, receivedInfo.MessageAddress);
                Assert.IsNull(receivedInfo.DataAddress);
            }
            finally
            {
                host.Close();
            }
        }
Beispiel #3
0
        public void FromVersioned()
        {
            var input = new VersionedChannelInformation
            {
                ProtocolVersion = new Version(1, 2, 3, 4),
                Address         = new Uri("http://localhost/invalid")
            };

            var output = ChannelInformationToTransportConverter.FromVersioned(input);

            Assert.AreSame(input.ProtocolVersion, output.Version);
            Assert.AreSame(input.Address, output.MessageAddress);
        }