public void Init() { // Prepare server Server.Start(); new Thread(new ThreadStart(() => { ServerConnection = Server.AcceptTcpClient(); ClientInstance = new ConnectedClient(ServerConnection); })).Start(); // Prepare client Thread.Sleep(100); ClientConnection.Connect(IPAddress.Loopback, TestPort); Thread.Sleep(100); if (ClientInstance == null) Assert.Fail("Cannot create client for test"); ClientInstance.Start(); }