Example #1
0
        public void CloseChannelTo()
        {
            var endpointId   = new EndpointId("id");
            var endpointInfo = new ProtocolInformation(
                ProtocolVersions.V1,
                new Uri("http://localhost/messages"),
                new Uri("http://localhost/data"));
            var msg               = new EndpointDisconnectMessage(endpointId);
            var messageProxy      = new Mock <IMessageSendingEndpoint>();
            var messageDisposable = messageProxy.As <IDisposable>();

            var dataProxy      = new Mock <IDataTransferingEndpoint>();
            var dataDisposable = dataProxy.As <IDisposable>();

            var localEndpoint = new EndpointId("local");
            Func <ProtocolInformation, IMessageSendingEndpoint>  messageBuilder = id => messageProxy.Object;
            Func <ProtocolInformation, IDataTransferingEndpoint> dataBuilder    = id => dataProxy.Object;
            var sender = new SendingEndpoint(localEndpoint, messageBuilder, dataBuilder);

            sender.Send(endpointInfo, msg, 1);
            Assert.AreEqual(1, sender.KnownEndpoints().Count());

            sender.CloseChannelTo(endpointInfo);
            Assert.AreEqual(0, sender.KnownEndpoints().Count());
        }
Example #2
0
        public void SendMessageToUnknownReceiver()
        {
            var endpointId   = new EndpointId("id");
            var endpointInfo = new ProtocolInformation(
                ProtocolVersions.V1,
                new Uri("http://localhost/messages"),
                new Uri("http://localhost/data"));

            var msg          = new EndpointDisconnectMessage(endpointId);
            var messageProxy = new Mock <IMessageSendingEndpoint>();
            {
                messageProxy.Setup(p => p.Send(It.IsAny <ICommunicationMessage>(), It.IsAny <int>()))
                .Callback <ICommunicationMessage, int>((input, retries) => Assert.AreSame(msg, input));
            }

            var dataProxy = new Mock <IDataTransferingEndpoint>();
            {
                dataProxy.Setup(p => p.Send(It.IsAny <DataTransferMessage>(), It.IsAny <int>()))
                .Verifiable();
            }

            var localEndpoint = new EndpointId("local");
            Func <ProtocolInformation, IMessageSendingEndpoint>  builder     = id => messageProxy.Object;
            Func <ProtocolInformation, IDataTransferingEndpoint> dataBuilder = id => dataProxy.Object;
            var sender = new SendingEndpoint(localEndpoint, builder, dataBuilder);

            sender.Send(endpointInfo, msg, 1);
            Assert.AreEqual(1, sender.KnownEndpoints().Count());
            dataProxy.Verify(p => p.Send(It.IsAny <DataTransferMessage>(), It.IsAny <int>()), Times.Never());
        }
Example #3
0
        public void SendDataToKnownReceiver()
        {
            var text   = "Hello world.";
            var data   = new MemoryStream();
            var writer = new StreamWriter(data);

            writer.Write(text);
            data.Position = 0;

            var localEndpoint = new EndpointId("local");
            var endpointInfo  = new ProtocolInformation(
                ProtocolVersions.V1,
                new Uri("http://localhost/messages"),
                new Uri("http://localhost/data"));
            var messageProxy = new Mock <IMessageSendingEndpoint>();
            {
                messageProxy.Setup(p => p.Send(It.IsAny <ICommunicationMessage>(), It.IsAny <int>()))
                .Verifiable();
            }

            var dataProxy = new Mock <IDataTransferingEndpoint>();
            {
                dataProxy.Setup(p => p.Send(It.IsAny <DataTransferMessage>(), It.IsAny <int>()))
                .Callback <DataTransferMessage, int>(
                    (msg, retries) =>
                {
                    Assert.AreSame(localEndpoint, msg.SendingEndpoint);
                    Assert.AreSame(data, msg.Data);
                })
                .Verifiable();
            }

            Func <ProtocolInformation, IMessageSendingEndpoint>  builder     = id => messageProxy.Object;
            Func <ProtocolInformation, IDataTransferingEndpoint> dataBuilder = id => dataProxy.Object;
            var sender = new SendingEndpoint(localEndpoint, builder, dataBuilder);

            sender.Send(endpointInfo, data, 1);
            Assert.AreEqual(1, sender.KnownEndpoints().Count());
            messageProxy.Verify(p => p.Send(It.IsAny <ICommunicationMessage>(), It.IsAny <int>()), Times.Never());
            dataProxy.Verify(p => p.Send(It.IsAny <DataTransferMessage>(), It.IsAny <int>()), Times.Exactly(1));

            sender.Send(endpointInfo, data, 1);
            Assert.AreEqual(1, sender.KnownEndpoints().Count());
            messageProxy.Verify(p => p.Send(It.IsAny <ICommunicationMessage>(), It.IsAny <int>()), Times.Never());
            dataProxy.Verify(p => p.Send(It.IsAny <DataTransferMessage>(), It.IsAny <int>()), Times.Exactly(2));
        }