public void SendMessageToWithUncontactableEndpoint() { var endpoints = new Mock <IStoreInformationAboutEndpoints>(); { endpoints.Setup(e => e.CanCommunicateWithEndpoint(It.IsAny <EndpointId>())) .Returns(false); } var channel = new Mock <IProtocolChannel>(); var pipe = new Mock <IDirectIncomingMessages>(); Func <ChannelTemplate, EndpointId, Tuple <IProtocolChannel, IDirectIncomingMessages> > channelBuilder = (template, id) => new Tuple <IProtocolChannel, IDirectIncomingMessages>(channel.Object, pipe.Object); var diagnostics = new SystemDiagnostics((log, s) => { }, null); var layer = new ProtocolLayer( endpoints.Object, channelBuilder, new[] { ChannelTemplate.NamedPipe, }, diagnostics); Assert.Throws <EndpointNotContactableException>( () => layer.SendMessageTo(new EndpointId("A"), new SuccessMessage(new EndpointId("B"), new MessageId()), 1)); }
public void SendMessageToWithOpenChannel() { var remoteEndpoint = new EndpointId("b"); var endpointInfo = new EndpointInformation( remoteEndpoint, new DiscoveryInformation(new Uri("net.pipe://localhost/discovery")), new ProtocolInformation( ProtocolVersions.V1, new Uri("net.pipe://localhost/messages"), new Uri("net.pipe://localhost/data"))); var endpoints = new Mock <IStoreInformationAboutEndpoints>(); { endpoints.Setup(e => e.CanCommunicateWithEndpoint(It.IsAny <EndpointId>())) .Returns(true); endpoints.Setup(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo)) .Returns(true); } var msg = new SuccessMessage(new EndpointId("B"), new MessageId()); var channel = new Mock <IProtocolChannel>(); { channel.Setup(c => c.OpenChannel()) .Verifiable(); channel.Setup(c => c.LocalConnectionPointForVersion(It.IsAny <Version>())) .Returns(endpointInfo.ProtocolInformation); channel.Setup(c => c.Send(It.IsAny <ProtocolInformation>(), It.IsAny <ICommunicationMessage>(), It.IsAny <int>())) .Callback <ProtocolInformation, ICommunicationMessage, int>( (e, m, r) => { Assert.AreSame(endpointInfo.ProtocolInformation, e); Assert.AreSame(msg, m); }) .Verifiable(); } var pipe = new Mock <IDirectIncomingMessages>(); Func <ChannelTemplate, EndpointId, Tuple <IProtocolChannel, IDirectIncomingMessages> > channelBuilder = (template, id) => new Tuple <IProtocolChannel, IDirectIncomingMessages>(channel.Object, pipe.Object); var diagnostics = new SystemDiagnostics((log, s) => { }, null); var layer = new ProtocolLayer( endpoints.Object, channelBuilder, new[] { ChannelTemplate.NamedPipe, }, diagnostics); layer.SignIn(); layer.SendMessageTo(remoteEndpoint, msg, 1); channel.Verify(c => c.OpenChannel(), Times.Once()); channel.Verify(c => c.Send(It.IsAny <ProtocolInformation>(), It.IsAny <ICommunicationMessage>(), It.IsAny <int>()), Times.Once()); }