public void Init() { _pipeStream = new PipeStream {MaxBufferLength = 3}; Action writeAction = () => { _pipeStream.WriteByte(10); _pipeStream.WriteByte(13); _pipeStream.WriteByte(25); // attempting to write more bytes than the max. buffer length should block // until bytes are read or the stream is closed try { _pipeStream.WriteByte(35); } catch (Exception ex) { _writeException = ex; throw; } }; _asyncWriteResult = writeAction.BeginInvoke(null, null); // ensure we've started writing _asyncWriteResult.AsyncWaitHandle.WaitOne(50); Act(); }
public void Read() { const int sleepTime = 100; var target = new PipeStream(); target.WriteByte(0x0a); target.WriteByte(0x0d); target.WriteByte(0x09); var readBuffer = new byte[2]; var bytesRead = target.Read(readBuffer, 0, readBuffer.Length); Assert.AreEqual(2, bytesRead); Assert.AreEqual(0x0a, readBuffer[0]); Assert.AreEqual(0x0d, readBuffer[1]); var writeToStreamThread = new Thread( () => { Thread.Sleep(sleepTime); var writeBuffer = new byte[] {0x05, 0x03}; target.Write(writeBuffer, 0, writeBuffer.Length); }); writeToStreamThread.Start(); readBuffer = new byte[2]; bytesRead = target.Read(readBuffer, 0, readBuffer.Length); Assert.AreEqual(2, bytesRead); Assert.AreEqual(0x09, readBuffer[0]); Assert.AreEqual(0x05, readBuffer[1]); }
public void Init() { _pipeStream = new PipeStream(); _pipeStream.WriteByte(10); _pipeStream.WriteByte(13); _bytesRead = 0; _readBuffer = new byte[4]; Action readAction = () => _bytesRead = _pipeStream.Read(_readBuffer, 0, _readBuffer.Length); _asyncReadResult = readAction.BeginInvoke(null, null); _asyncReadResult.AsyncWaitHandle.WaitOne(50); Act(); }
public void Init() { _pipeStream = new PipeStream(); _pipeStream.WriteByte(10); _pipeStream.WriteByte(13); _pipeStream.WriteByte(25); _bytesRead = 123; Action readAction = () => _bytesRead = _pipeStream.Read(new byte[4], 0, 4); _asyncReadResult = readAction.BeginInvoke(null, null); // ensure we've started reading _asyncReadResult.AsyncWaitHandle.WaitOne(50); Act(); }
public void Position_GetterAlwaysReturnsZero() { var target = new PipeStream(); Assert.AreEqual(0, target.Position); target.WriteByte(0x0a); Assert.AreEqual(0, target.Position); target.ReadByte(); Assert.AreEqual(0, target.Position); }
public void LengthTest() { var target = new PipeStream(); Assert.AreEqual(0L, target.Length); target.Write(new byte[] { 0x0a, 0x05, 0x0d }, 0, 2); Assert.AreEqual(2L, target.Length); target.WriteByte(0x0a); Assert.AreEqual(3L, target.Length); target.Read(new byte[2], 0, 2); Assert.AreEqual(1L, target.Length); target.ReadByte(); Assert.AreEqual(0L, target.Length); }