async Task DoSend(bool slowOutgoing, bool slowIncoming) { Incoming.SlowConnection = slowIncoming; Outgoing.SlowConnection = slowOutgoing; var task = NetworkIO.SendAsync(Outgoing, data, 0, data.Length, null, null, null); int received = 0; byte[] buffer = new byte [data.Length]; while (received != buffer.Length) { int r = await Incoming.ReceiveAsync(buffer, received, buffer.Length - received); Assert.AreNotEqual(0, r, "#Received data"); received += r; } Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(1)), "Data should be all sent"); Assert.IsTrue(Toolbox.ByteMatch(buffer, data), "Data matches"); }