public void ConnectAsync() { using (var client = new TcpClient()) { var connectCheck = false; client.Connected += () => connectCheck = true; client.IsConnected.Should().BeFalse(); client.ConnectAsync(IPAddress.Loopback, testPort); Waiting.Until(() => connectCheck); client.IsConnected.Should().BeTrue(); new Action(() => client.Connect(IPAddress.Loopback, testPort)).Should().Throw <InvalidOperationException>(); } }
public void DisconnectAync() { using (var client = new TcpClient()) { var disconnectCheck = false; client.Disconnected += () => disconnectCheck = true; client.Connect(IPAddress.Loopback, testPort); client.DisconnectAsync(); Waiting.Until(() => disconnectCheck); client.IsConnected.Should().BeFalse(); client.IsDisposed.Should().BeFalse(); new Action(() => client.DisconnectAsync()).Should().NotThrow(); } }
public void Send() { using (var client = new TcpClient()) { var bytes = new ArraySegment <byte>(); var sendData = new byte[] { 123 }; client.Connect(IPAddress.Loopback, testPort); Waiting.Until(() => connectedSession != null); connectedSession.PacketReceived += reader => bytes = reader.ReadBytes(); client.Send(sendData); Waiting.Until(() => bytes.Array != null); bytes.Array.Skip(bytes.Offset).Take(bytes.Count).Should().BeEquivalentTo(sendData); } }