Exemple #1
0
        public void LocalConnectionPointForVersionWithUnknownVersion()
        {
            var id       = new EndpointId("a");
            var template = new Mock <IProtocolChannelTemplate>();

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

            Func <Version, Tuple <Type, IMessagePipe> > messageReceiverBuilder = version => new Tuple <Type, IMessagePipe>(null, null);
            Func <Version, Tuple <Type, IDataPipe> >    dataReceiverBuilder    = version => new Tuple <Type, IDataPipe>(null, null);

            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);

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

            Assert.IsNull(connection);
        }
Exemple #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));
        }