public void IsConnectionActiveWithIdAndUnresponsiveConnection() { var endpoint = EndpointIdExtensions.CreateEndpointIdForCurrentProcess(); var address = new Uri("http://localhost/discovery"); var endpointInfo = new EndpointInformation( endpoint, new DiscoveryInformation(address), new ProtocolInformation( new Version(), new Uri("http://localhost/messages"), new Uri("http://localhost/data"))); var endpoints = new Mock <IStoreInformationAboutEndpoints>(); { endpoints.Setup(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo)) .Returns(true) .Verifiable(); } var commands = new Mock <ISendCommandsToRemoteEndpoints>(); var notifications = new Mock <INotifyOfRemoteEndpointEvents>(); var configuration = new Mock <IConfiguration>(); { configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>())) .Returns(false); } var source = new CancellationTokenSource(); source.Cancel(); VerifyEndpointConnectionStatus func = (id, timeout) => { return(Task.Factory.StartNew( () => { }, source.Token, TaskCreationOptions.None, new CurrentThreadTaskScheduler())); }; var entryPoint = new CommunicationEntryPoint( endpoints.Object, commands.Object, notifications.Object, func, configuration.Object); endpoints.Raise(e => e.OnEndpointConnected += null, new EndpointEventArgs(endpoint)); commands.Raise(c => c.OnEndpointConnected += null, new EndpointEventArgs(endpoint)); notifications.Raise(n => n.OnEndpointConnected += null, new EndpointEventArgs(endpoint)); Assert.IsFalse(entryPoint.IsConnectionActive(endpoint)); }
public void IsConnectionActiveWithUrlAndUnknownConnection() { var endpoint = EndpointIdExtensions.CreateEndpointIdForCurrentProcess(); var address = new Uri("http://localhost/discovery"); var endpointInfo = new EndpointInformation( endpoint, new DiscoveryInformation(address), new ProtocolInformation( new Version(), new Uri("http://localhost/messages"), new Uri("http://localhost/data"))); var endpoints = new Mock <IStoreInformationAboutEndpoints>(); { endpoints.Setup(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo)) .Returns(true) .Verifiable(); } var commands = new Mock <ISendCommandsToRemoteEndpoints>(); var notifications = new Mock <INotifyOfRemoteEndpointEvents>(); var configuration = new Mock <IConfiguration>(); { configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>())) .Returns(false); } VerifyEndpointConnectionStatus func = (id, timeout) => null; var entryPoint = new CommunicationEntryPoint( endpoints.Object, commands.Object, notifications.Object, func, configuration.Object); Assert.IsFalse(entryPoint.IsConnectionActive(new Uri("http://localhost/invalid"))); }