protected void Arrange()
        {
            var random = new Random();

            _path            = random.Next().ToString();
            _handle          = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) };
            _bufferSize      = (uint)random.Next(1, 1000);
            _readBufferSize  = (uint)random.Next(0, 1000);
            _writeBufferSize = (uint)random.Next(0, 1000);

            _sftpSessionMock = new Mock <ISftpSession>(MockBehavior.Strict);

            var sequence = new MockSequence();

            _sftpSessionMock.InSequence(sequence)
            .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true))
            .Returns(_handle);
            _sftpSessionMock.InSequence(sequence)
            .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
            .Returns(_readBufferSize);
            _sftpSessionMock.InSequence(sequence)
            .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
            .Returns(_writeBufferSize);
            _sftpSessionMock.InSequence(sequence)
            .Setup(p => p.IsOpen)
            .Returns(true);
            _sftpSessionMock.InSequence(sequence)
            .Setup(p => p.RequestClose(_handle));

            _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize);
            _sftpFileStream.Dispose();
        }
Ejemplo n.º 2
0
        protected override void Arrange()
        {
            base.Arrange();

            _target = new SftpFileStream(SftpSessionMock.Object,
                                         _path,
                                         FileMode.OpenOrCreate,
                                         FileAccess.Write,
                                         (int)_bufferSize);
            _target.Dispose();
        }
        public void DisposeShouldFlushBufferAndCloseRequest()
        {
            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));
            SftpSessionMock.InSequence(MockSequence)
            .Setup(p => p.RequestClose(_handle));

            _target.Dispose();

            Assert.IsTrue(actualFlushedData.IsEqualTo(_expectedBufferedBytes));

            SftpSessionMock.Verify(p => p.RequestWrite(_handle, _expectedWrittenByteCount, It.IsAny <byte[]>(), 0, _expectedBufferedByteCount, It.IsAny <AutoResetEvent>(), null), Times.Once);
            SftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once);
        }
    protected virtual void Dispose(bool disposing)
    {
        if (!_disposed)
        {
            if (disposing)
            {
                if (sftp != null)
                {
                    sftp.Dispose();
                }
                if (file != null)
                {
                    file.Dispose();
                }
            }

            // Indicate that the instance has been disposed.
            _disposed = true;
        }
    }
Ejemplo n.º 5
0
 protected override void Act()
 {
     _target.Dispose();
 }
 protected void Act()
 {
     _sftpFileStream.Dispose();
 }