/// <summary>
        /// Opens the channel and provides information on how to connect to the given channel.
        /// </summary>
        public void OpenChannel()
        {
            lock (m_Lock)
            {
                foreach (var version in ProtocolVersions.SupportedVersions())
                {
                    if (m_MessagePipesByVersion.ContainsKey(version) || m_DataPipesByVersion.ContainsKey(version))
                    {
                        CloseChannel(version);
                    }

                    var dataUri    = CreateAndStoreDataChannelForProtocolVersion(version);
                    var messageUri = CreateAndStoreMessageChannelForProtocolVersion(version);

                    var localConnection = new ProtocolInformation(version, messageUri, dataUri);
                    m_LocalConnectionPoints.Add(localConnection);
                }
            }
        }
Ejemplo n.º 2
0
        public void OpenChannel()
        {
            var id       = new EndpointId("a");
            var template = new Mock <IProtocolChannelTemplate>();

            var messageUri = new Uri("http://localhost/messages/invalid");
            var dataUri    = new Uri("http://localhost/data/invalid");
            var host       = new Mock <IHoldServiceConnections>();
            {
                host.Setup(
                    h =>
                    h.OpenChannel(
                        It.IsAny <IReceiveInformationFromRemoteEndpoints>(),
                        It.IsAny <Func <ServiceHost, ServiceEndpoint> >()))
                .Returns <IReceiveInformationFromRemoteEndpoints, Func <ServiceHost, ServiceEndpoint> >(
                    (r, f) => r is IMessagePipe ? messageUri : dataUri)
                .Verifiable();
            }

            Func <IHoldServiceConnections> hostBuilder = () => host.Object;

            var messagePipe = new Mock <IMessagePipe>();
            Func <Version, Tuple <Type, IMessagePipe> > messageReceiverBuilder =
                version => new Tuple <Type, IMessagePipe>(typeof(IMessagePipe), messagePipe.Object);

            var dataPipe = new Mock <IDataPipe>();
            Func <Version, Tuple <Type, IDataPipe> > dataReceiverBuilder =
                version => new Tuple <Type, IDataPipe>(typeof(IDataPipe), dataPipe.Object);

            var sendingEndpoint = new Mock <ISendingEndpoint>();
            BuildSendingEndpoint senderBuilder = (endpoint, builder, endpointBuilder) => sendingEndpoint.Object;

            var messageEndpoint = new Mock <IMessageSendingEndpoint>();
            Func <Version, Uri, IMessageSendingEndpoint> versionedMessageSenderBuilder = (version, uri) => messageEndpoint.Object;

            var dataEndpoint = new Mock <IDataTransferingEndpoint>();
            Func <Version, Uri, IDataTransferingEndpoint> versionedDataSenderBuilder = (version, uri) => dataEndpoint.Object;

            var channel = new ProtocolChannel(
                id,
                template.Object,
                hostBuilder,
                messageReceiverBuilder,
                dataReceiverBuilder,
                senderBuilder,
                versionedMessageSenderBuilder,
                versionedDataSenderBuilder);

            channel.OpenChannel();
            var protocols = channel.LocalConnectionPoints().ToList();

            Assert.AreEqual(1, protocols.Count());
            Assert.That(protocols.Select(p => p.Version), Is.EquivalentTo(ProtocolVersions.SupportedVersions()));

            var connection = channel.LocalConnectionPointForVersion(ProtocolVersions.V1);

            Assert.AreEqual(ProtocolVersions.V1, connection.Version);
            Assert.AreEqual(messageUri, connection.MessageAddress);
            Assert.AreEqual(dataUri, connection.DataAddress);

            host.Verify(
                h => h.OpenChannel(It.IsAny <IReceiveInformationFromRemoteEndpoints>(), It.IsAny <Func <ServiceHost, ServiceEndpoint> >()),
                Times.Exactly(2));
        }