public async void ConnectionStateCycle() { await DefaultSetup(new CalculatorService(), 1); SimpleInMemConnection localConnection = (SimpleInMemConnection)await transport.ConnectToAsync(address, System.Threading.CancellationToken.None); Assert.AreEqual(localConnection.State, CnxState.Connected); await localConnection.StopAsync(); Assert.AreEqual(localConnection.State, CnxState.Disconnected); }
public async Task ConnectedEvent_HasRightRemoteEndpointDetails() { SimpleInMemConnection listenerConnection = null; var connectedEventDone = new ManualResetEventSlim(initialState: false); SimpleInMemListener listener = (SimpleInMemListener)transport.MakeListener(address); listener.Connected += (sender, args) => { Assert.AreSame(listener, sender); listenerConnection = (SimpleInMemConnection)args.Connection; connectedEventDone.Set(); }; await listener.StartAsync(); var connection = (SimpleInMemConnection)await transport.ConnectToAsync(address); bool wasSignaled = connectedEventDone.Wait(TimeSpan.FromSeconds(30)); Assert.IsTrue(wasSignaled, "Timed out waiting for Connected event to complete"); Assert.AreEqual(connection.Id, listenerConnection.Id); }
public async Task DefaultSetup(IService service, int count) { transport = transportBuilder.Construct(); listener = (SimpleInMemListener)transport.MakeListener(address); listener.AddService(service); await listener.StartAsync(); connections = new SimpleInMemConnection[count]; for (int connectionIndex = 0; connectionIndex < count; connectionIndex++) { connections[connectionIndex] = (SimpleInMemConnection)await transport.ConnectToAsync(address, System.Threading.CancellationToken.None); Assert.IsTrue(connections[connectionIndex].IsConnected); Assert.IsTrue(connections[connectionIndex].IsPaired); } }
public void ConnectToAsync_NoListenerRunning() { Assert.Throws <ArgumentException>(async() => await transport.ConnectToAsync(address, new System.Threading.CancellationToken())); }