private static void StubReceive(ISocketConnectionProxy socket, int offset, int size, byte[] bytes) { A.CallTo(() => socket.Receive(A <byte[]> .Ignored, offset, size)) .Invokes((byte[] buffer, int offsetArg, int sizeArg) => { bytes.CopyTo(buffer, offset); }) .Returns(bytes.Length) .Once(); }
private int TryReadChunk(byte[] buffer) { // We can't be sure that we're receiving the full 9+ bytes at the same // time, so loop to read data until we fill the buffer. Under normal // circumstances, we should, in which case there's just a single // Receive call here. int bytesRead; int bufferOffset = 0; while (bufferOffset < buffer.Length) { bytesRead = _socketConnection.Receive(buffer, bufferOffset, buffer.Length - bufferOffset); if (bytesRead == 0) { break; } bufferOffset += bytesRead; } return(bufferOffset); }