public void PositionShouldReturnSameValueAsBeforeFlush() { SftpSessionMock.InSequence(MockSequence) .Setup(p => p.IsOpen) .Returns(true); Assert.AreEqual(_readBytes.Length, _target.Position); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3)); }
public void PositionShouldReturnZero() { SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); var actual = _target.Position; Assert.AreEqual(0L, actual); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1)); }
public void PositionShouldReturnSizeOfFile() { SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); var actual = _target.Position; Assert.AreEqual(_fileAttributes.Size, actual); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1)); }
protected override void SetupMocks() { _seq = new MockSequence(); SftpSessionMock.InSequence(_seq) .Setup(p => p.CreateWaitHandleArray(It.IsNotNull <WaitHandle>(), It.IsNotNull <WaitHandle>())) .Returns <WaitHandle, WaitHandle>((disposingWaitHandle, semaphoreAvailableWaitHandle) => { _waitHandleArray[0] = disposingWaitHandle; _waitHandleArray[1] = semaphoreAvailableWaitHandle; return(_waitHandleArray); }); SftpSessionMock.InSequence(_seq).Setup(p => p.OperationTimeout).Returns(_operationTimeout); SftpSessionMock.InSequence(_seq) .Setup(p => p.WaitAny(_waitHandleArray, _operationTimeout)) .Returns(() => WaitAny(_waitHandleArray, _operationTimeout)); SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, 0, ChunkLength, It.IsNotNull <AsyncCallback>(), It.IsAny <BufferedRead>())) .Callback <byte[], ulong, uint, AsyncCallback, object>((handle, offset, length, callback, state) => { _chunk1BeginRead.Set(); var asyncResult = new SftpReadAsyncResult(callback, state); asyncResult.SetAsCompleted(_chunk1, false); }) .Returns((SftpReadAsyncResult)null); SftpSessionMock.InSequence(_seq).Setup(p => p.OperationTimeout).Returns(_operationTimeout); SftpSessionMock.InSequence(_seq) .Setup(p => p.WaitAny(_waitHandleArray, _operationTimeout)) .Returns(() => WaitAny(_waitHandleArray, _operationTimeout)); SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, ChunkLength, ChunkLength, It.IsNotNull <AsyncCallback>(), It.IsAny <BufferedRead>())) .Callback <byte[], ulong, uint, AsyncCallback, object>((handle, offset, length, callback, state) => { _chunk2BeginRead.Set(); var asyncResult = new SftpReadAsyncResult(callback, state); asyncResult.SetAsCompleted(_chunk2, false); }) .Returns((SftpReadAsyncResult)null); SftpSessionMock.InSequence(_seq).Setup(p => p.OperationTimeout).Returns(_operationTimeout); SftpSessionMock.InSequence(_seq) .Setup(p => p.WaitAny(_waitHandleArray, _operationTimeout)) .Returns(() => WaitAny(_waitHandleArray, _operationTimeout)); SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, 2 * ChunkLength, ChunkLength, It.IsNotNull <AsyncCallback>(), It.IsAny <BufferedRead>())) .Callback <byte[], ulong, uint, AsyncCallback, object>((handle, offset, length, callback, state) => { _chunk3BeginRead.Set(); var asyncResult = new SftpReadAsyncResult(callback, state); asyncResult.SetAsCompleted(_chunk3, false); }) .Returns((SftpReadAsyncResult)null); SftpSessionMock.InSequence(_seq) .Setup(p => p.RequestRead(_handle, 2 * ChunkLength - 10, 10)) .Returns(_chunk2CatchUp); }
public void DisposeShouldCompleteImmediatelyAndNotAttemptToCloseHandleAgain() { var stopwatch = Stopwatch.StartNew(); _reader.Dispose(); stopwatch.Stop(); Assert.IsTrue(stopwatch.ElapsedMilliseconds < 200, "Dispose took too long to complete: " + stopwatch.ElapsedMilliseconds); SftpSessionMock.Verify(p => p.BeginClose(_handle, null, null), Times.Once); SftpSessionMock.Verify(p => p.EndClose(_closeAsyncResult), Times.Once); }
protected override void SetupMocks() { SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, false)) .Returns(_handle); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize)) .Returns(_readBufferSize); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle)) .Returns(_writeBufferSize); }
public void WriteShouldStartWritingAtBeginningOfFile() { var buffer = new byte[_writeBufferSize]; SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull <AutoResetEvent>(), null)); _target.Write(buffer, 0, buffer.Length); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1)); SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull <AutoResetEvent>(), null), Times.Once); }
public void SubsequentReadShouldReturnAllRemaningBytesFromReadBufferWhenCountIsEqualToNumberOfRemainingBytes() { SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); var buffer = new byte[_numberOfBytesToWriteToReadBuffer]; var actual = _target.Read(buffer, 0, _numberOfBytesToWriteToReadBuffer); Assert.AreEqual(_numberOfBytesToWriteToReadBuffer, actual); Assert.IsTrue(_serverData.Take(_numberOfBytesToRead, _numberOfBytesToWriteToReadBuffer).IsEqualTo(buffer)); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); }
protected override void SetupMocks() { _seq = new MockSequence(); SftpSessionMock.InSequence(_seq) .Setup(p => p.CreateWaitHandleArray(It.IsNotNull <WaitHandle>(), It.IsNotNull <WaitHandle>())) .Returns <WaitHandle, WaitHandle>((disposingWaitHandle, semaphoreAvailableWaitHandle) => { _waitHandleArray[0] = disposingWaitHandle; _waitHandleArray[1] = semaphoreAvailableWaitHandle; return(_waitHandleArray); }); SftpSessionMock.InSequence(_seq).Setup(p => p.OperationTimeout).Returns(_operationTimeout); SftpSessionMock.InSequence(_seq) .Setup(p => p.WaitAny(_waitHandleArray, _operationTimeout)) .Returns(() => WaitAny(_waitHandleArray, _operationTimeout)); SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, 0, ChunkLength, It.IsNotNull <AsyncCallback>(), It.IsAny <BufferedRead>())) .Callback <byte[], ulong, uint, AsyncCallback, object>((handle, offset, length, callback, state) => { var asyncResult = new SftpReadAsyncResult(callback, state); asyncResult.SetAsCompleted(_chunk1, false); }) .Returns((SftpReadAsyncResult)null); SftpSessionMock.InSequence(_seq).Setup(p => p.OperationTimeout).Returns(_operationTimeout); SftpSessionMock.InSequence(_seq) .Setup(p => p.WaitAny(_waitHandleArray, _operationTimeout)) .Returns(() => WaitAny(_waitHandleArray, _operationTimeout)); SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, ChunkLength, ChunkLength, It.IsNotNull <AsyncCallback>(), It.IsAny <BufferedRead>())) .Callback <byte[], ulong, uint, AsyncCallback, object>((handle, offset, length, callback, state) => { ThreadAbstraction.ExecuteThread(() => { // signal that we're in the read-ahead for chunk2 _readAheadChunk2.Set(); // wait for client to start reading this chunk _readChunk2.WaitOne(TimeSpan.FromSeconds(5)); // sleep a short time to make sure the client is in the blocking wait Thread.Sleep(500); // complete async read of chunk2 with exception var asyncResult = new SftpReadAsyncResult(callback, state); asyncResult.SetAsCompleted(_exception, false); }); }) .Returns((SftpReadAsyncResult)null); SftpSessionMock.InSequence(_seq).Setup(p => p.OperationTimeout).Returns(_operationTimeout); SftpSessionMock.InSequence(_seq) .Setup(p => p.WaitAny(_waitHandleArray, _operationTimeout)) .Returns(() => WaitAny(_waitHandleArray, _operationTimeout)); }
public void TearDown() { if (SftpSessionMock != null) { // allow Dispose to complete successfully SftpSessionMock.InSequence(MockSequence) .Setup(p => p.IsOpen) .Returns(true); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestWrite(_handle, _expectedWrittenByteCount, It.IsAny <byte[]>(), 0, _expectedBufferedByteCount, It.IsAny <AutoResetEvent>(), null)); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestClose(_handle)); } }
protected override void SetupMocks() { SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestOpen(_path, Flags.Read, false)) .Returns(_handle); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) .Returns(_readBufferSize); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) .Returns(_writeBufferSize); SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestClose(_handle)); }
public void ReadShouldReadStartFromSamePositionAsBeforeSetLength() { SftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); SftpSessionMock.InSequence(_sequence) .Setup(p => p.RequestRead(_handle, (uint)(_readBytes.Length + _writeBytes.Length), _readBufferSize)) .Returns(new byte[] { 0x0f }); var byteRead = _sftpFileStream.ReadByte(); Assert.AreEqual(0x0f, byteRead); SftpSessionMock.Verify(p => p.RequestRead(_handle, (uint)(_readBytes.Length + _writeBytes.Length), _readBufferSize), Times.Once); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(4)); }
public void ReadShouldStartFromEndOfStream() { SftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); SftpSessionMock.InSequence(_sequence) .Setup(p => p.RequestRead(_handle, (uint)_length, _readBufferSize)) .Returns(Array <byte> .Empty); var byteRead = _sftpFileStream.ReadByte(); Assert.AreEqual(-1, byteRead); SftpSessionMock.Verify(p => p.RequestRead(_handle, (uint)_length, _readBufferSize), Times.Once); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(4)); }
public void DisposeShouldCloseHandleAndCompleteImmediately() { SftpSessionMock.InSequence(_seq).Setup(p => p.BeginClose(_handle, null, null)).Returns(_closeAsyncResult); SftpSessionMock.InSequence(_seq).Setup(p => p.EndClose(_closeAsyncResult)); var stopwatch = Stopwatch.StartNew(); _reader.Dispose(); stopwatch.Stop(); Assert.IsTrue(stopwatch.ElapsedMilliseconds < 200, "Dispose took too long to complete: " + stopwatch.ElapsedMilliseconds); SftpSessionMock.Verify(p => p.BeginClose(_handle, null, null), Times.Once); SftpSessionMock.Verify(p => p.EndClose(_closeAsyncResult), Times.Once); }
public void ReadShouldReturnAllRemaningBytesFromReadBufferWhenCountIsEqualToNumberOfRemainingBytes() { SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); var numberOfBytesRemainingInReadBuffer = _serverData1Length + _serverData2Length - _numberOfBytesToRead; _buffer = new byte[numberOfBytesRemainingInReadBuffer]; var actual = _target.Read(_buffer, 0, _buffer.Length); Assert.AreEqual(_buffer.Length, actual); Assert.IsTrue(_serverData2.Take(_numberOfBytesToRead - _serverData1Length, _buffer.Length).IsEqualTo(_buffer)); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); }
public void ReadBytesThatWereBufferedBeforeSeekShouldReadBytesFromServer() { SftpSessionMock.InSequence(MockSequence) .Setup(p => p.IsOpen) .Returns(true); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize)) .Returns(_serverData2); var buffer = new byte[_buffer.Length + 1]; // we read one byte that was previously buffered var bytesRead = _target.Read(buffer, 0, buffer.Length); Assert.AreEqual(buffer.Length, bytesRead); Assert.IsTrue(_serverData2.Take(buffer.Length).IsEqualTo(buffer)); }
protected override void SetupMocks() { SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Append | Flags.CreateNewOrOpen, false)) .Returns(_handle); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize)) .Returns(_readBufferSize); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle)) .Returns(_writeBufferSize); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestFStat(_handle, false)) .Returns(_fileAttributes); }
public void SubsequentReadShouldReadAgainFromCurrentPositionFromServerAndNotUpdatePositionWhenServerReturnsZeroBytes() { SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestRead(_handle, (ulong)_actual, _readBufferSize)) .Returns(Array <byte> .Empty); SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); _target.Read(new byte[10], 0, 10); Assert.AreEqual(_actual, _target.Position); SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)_actual, _readBufferSize), Times.Once); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3)); }
public void ReadByteShouldStartReadingAtBeginningOfFile() { var data = GenerateRandom(5, _random); SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize)) .Returns(data); var actual = _target.ReadByte(); Assert.AreEqual(data[0], actual); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1)); SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once); }
public void WriteByteShouldThrowNotSupportedException() { SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); try { _target.WriteByte(0x0a); } catch (NotSupportedException ex) { Assert.IsNull(ex.InnerException); Assert.AreEqual("Write not supported.", ex.Message); } SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1)); }
public void SubsequentReadShouldReturnAllRemaningBytesFromReadBufferAndReadAgainWhenCountIsGreaterThanNumberOfRemainingBytesAndNewReadReturnsZeroBytes() { SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, (ulong)(_serverData.Length), _readBufferSize)).Returns(Array <byte> .Empty); var buffer = new byte[_numberOfBytesToWriteToReadBuffer + 1]; var actual = _target.Read(buffer, 0, buffer.Length); Assert.AreEqual(_numberOfBytesToWriteToReadBuffer, actual); Assert.IsTrue(_serverData.Take(_numberOfBytesToRead, _numberOfBytesToWriteToReadBuffer).IsEqualTo(buffer.Take(_numberOfBytesToWriteToReadBuffer))); Assert.AreEqual(0, buffer[_numberOfBytesToWriteToReadBuffer]); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)(_serverData.Length), _readBufferSize)); }
public void SubsequentReadShouldReadAgainFromCurrentPositionFromServerAndReturnZeroWhenServerReturnsZeroBytes() { SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestRead(_handle, (ulong)_actual, _readBufferSize)) .Returns(Array <byte> .Empty); var buffer = _originalBuffer.Copy(); var actual = _target.Read(buffer, 0, buffer.Length); Assert.AreEqual(0, actual); Assert.IsTrue(_originalBuffer.IsEqualTo(buffer)); SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)_actual, _readBufferSize), Times.Once); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); }
public void ReadShouldStartReadingAtBeginningOfFile() { var buffer = new byte[8]; var data = new byte[] { 5, 4, 3, 2, 1 }; var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 }; SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize)).Returns(data); var actual = _target.Read(buffer, 1, data.Length); Assert.AreEqual(data.Length, actual); Assert.IsTrue(buffer.IsEqualTo(expected)); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1)); SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once); }
public void ReadBytesThatWereNotBufferedBeforeSeekShouldReadBytesFromServer() { SftpSessionMock.InSequence(MockSequence) .Setup(p => p.IsOpen) .Returns(true); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize)) .Returns(_serverData2); var bytesRead = _target.Read(_buffer, 0, _buffer.Length); Assert.AreEqual(_buffer.Length, bytesRead); Assert.IsTrue(_serverData2.Take(_buffer.Length).IsEqualTo(_buffer)); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3)); SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Exactly(2)); }
protected override void SetupMocks() { _seq = new MockSequence(); SftpSessionMock.InSequence(_seq) .Setup(p => p.CreateWaitHandleArray(It.IsNotNull <WaitHandle>(), It.IsNotNull <WaitHandle>())) .Returns <WaitHandle, WaitHandle>((disposingWaitHandle, semaphoreAvailableWaitHandle) => { _waitHandleArray[0] = disposingWaitHandle; _waitHandleArray[1] = semaphoreAvailableWaitHandle; return(_waitHandleArray); }); SftpSessionMock.InSequence(_seq) .Setup(p => p.OperationTimeout) .Returns(_operationTimeout); SftpSessionMock.InSequence(_seq) .Setup(p => p.WaitAny(_waitHandleArray, _operationTimeout)) .Returns(() => WaitAny(_waitHandleArray, _operationTimeout)); SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, 0, ChunkLength, It.IsNotNull <AsyncCallback>(), It.IsAny <BufferedRead>())) .Callback(() => { // harden test by making sure that we've invoked BeginRead before Dispose is invoked _beginReadInvoked.Set(); }) .Returns <byte[], ulong, uint, AsyncCallback, object>((handle, offset, length, callback, state) => { _readAsyncCallback = callback; return(null); }) .Callback(() => { // wait until Dispose has been invoked on reader to allow us to harden test, and // verify whether Dispose will prevent us from entering the read-ahead loop again _waitHandleArray[0].WaitOne(); }); SftpSessionMock.InSequence(_seq) .Setup(p => p.IsOpen) .Returns(true); SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginClose(_handle, null, null)) .Returns(_closeAsyncResult); SftpSessionMock.InSequence(_seq) .Setup(p => p.EndClose(_closeAsyncResult)) .Throws(new SshException()); }
protected override void SetupMocks() { SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) .Returns(_handle); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) .Returns(_readBufferSize); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) .Returns(_writeBufferSize); SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestWrite(_handle, 0, _data, _offset, (int)_writeBufferSize, It.IsAny <AutoResetEvent>(), null)); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestWrite(_handle, _writeBufferSize, _data, _offset + (int)_writeBufferSize, (int)_writeBufferSize, It.IsAny <AutoResetEvent>(), null)); }
public void FlushShouldFlushBuffer() { byte[] actualFlushedData = null; SftpSessionMock.InSequence(MockSequence) .Setup(p => p.IsOpen) .Returns(true); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestWrite(_handle, _expectedWrittenByteCount, It.IsAny <byte[]>(), 0, _expectedBufferedByteCount, It.IsAny <AutoResetEvent>(), null)) .Callback <byte[], ulong, byte[], int, int, AutoResetEvent, Action <SftpStatusResponse> >((handle, serverFileOffset, data, offset, length, wait, writeCompleted) => actualFlushedData = data.Take(offset, length)); _target.Flush(); Assert.IsTrue(actualFlushedData.IsEqualTo(_expectedBufferedBytes)); SftpSessionMock.Verify(p => p.RequestWrite(_handle, _expectedWrittenByteCount, It.IsAny <byte[]>(), 0, _expectedBufferedByteCount, It.IsAny <AutoResetEvent>(), null), Times.Once); }
public void WriteShouldThrowNotSupportedException() { var buffer = new byte[_writeBufferSize]; SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true); try { _target.Write(buffer, 0, buffer.Length); } catch (NotSupportedException ex) { Assert.IsNull(ex.InnerException); Assert.AreEqual("Write not supported.", ex.Message); } SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1)); }
public void ReadShouldReturnReadBytesFromServer() { SftpSessionMock.InSequence(MockSequence) .Setup(p => p.IsOpen) .Returns(true); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize)) .Returns(new byte[] { 0x05, 0x04 }); var buffer = new byte[1]; var bytesRead = _target.Read(buffer, 0, buffer.Length); Assert.AreEqual(buffer.Length, bytesRead); Assert.AreEqual(0x05, buffer[0]); SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3)); SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Exactly(2)); }
protected override void SetupMocks() { SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.CreateNewOrOpen, false)) .Returns(_handle); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize)) .Returns(_readBufferSize); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle)) .Returns(_writeBufferSize); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.IsOpen) .Returns(true); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize)) .Returns(_serverData1); SftpSessionMock.InSequence(MockSequence) .Setup(p => p.IsOpen) .Returns(true); }