Example #1
0
        protected override void Arrange()
        {
            base.Arrange();

            _target = new SftpFileStream(SftpSessionMock.Object,
                                         _path,
                                         FileMode.Open,
                                         FileAccess.ReadWrite,
                                         (int)_bufferSize);
            _target.Write(_writeBytes1, 0, _writeBytes1.Length);
            _target.Write(_writeBytes2, 0, _writeBytes2.Length);
            _target.Write(_writeBytes3, 0, _writeBytes3.Length);
        }
Example #2
0
        protected override void Arrange()
        {
            base.Arrange();

            _sftpFileStream = new SftpFileStream(SftpSessionMock.Object, _path, FileMode.Open, FileAccess.ReadWrite, (int)_bufferSize);
            _sftpFileStream.Read(_readBytes, 0, _readBytes.Length);
            _sftpFileStream.Write(new byte[] { 0x01, 0x02, 0x03, 0x04 }, 0, 4);
        }
Example #3
0
        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);
        }
Example #4
0
        public void WriteTest()
        {
            SftpSession    session = null;                                    // TODO: Initialize to an appropriate value
            string         path    = string.Empty;                            // TODO: Initialize to an appropriate value
            FileMode       mode    = new FileMode();                          // TODO: Initialize to an appropriate value
            SftpFileStream target  = new SftpFileStream(session, path, mode); // TODO: Initialize to an appropriate value

            byte[] buffer = null;                                             // TODO: Initialize to an appropriate value
            int    offset = 0;                                                // TODO: Initialize to an appropriate value
            int    count  = 0;                                                // TODO: Initialize to an appropriate value

            target.Write(buffer, offset, count);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Example #5
0
        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));
        }
Example #6
0
        public NtStatus WriteFile(string fileName, byte[] buffer, out int bytesWritten, long offset, DokanFileInfo info)
        {
            if (info.Context == null)
            {
                using (SftpFileStream stream = sftpClient.Open(fileName, FileMode.Open, System.IO.FileAccess.Write))
                {
                    stream.Position = offset;
                    stream.Write(buffer, 0, buffer.Length);
                    bytesWritten = buffer.Length;
                }
            }
            else
            {
                var stream = info.Context as SftpFileStream;
                stream.Write(buffer, 0, buffer.Length);
                bytesWritten = buffer.Length;
            }

            return(DokanResult.Success);
        }
Example #7
0
        public void WriteShouldStartFromEndOfStream()
        {
            var bytesToWrite = GenerateRandom(_writeBufferSize);

            byte[] bytesWritten = null;

            SftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true);
            SftpSessionMock.InSequence(_sequence)
            .Setup(p => p.RequestWrite(_handle, (uint)_length, It.IsAny <byte[]>(), 0, bytesToWrite.Length, It.IsAny <AutoResetEvent>(), null))
            .Callback <byte[], ulong, byte[], int, int, AutoResetEvent, Action <SftpStatusResponse> >((handle, serverOffset, data, offset, length, wait, writeCompleted) =>
            {
                bytesWritten = data.Take(offset, length);
                wait.Set();
            });

            _sftpFileStream.Write(bytesToWrite, 0, bytesToWrite.Length);

            Assert.IsNotNull(bytesWritten);
            CollectionAssert.AreEqual(bytesToWrite, bytesWritten);

            SftpSessionMock.Verify(p => p.RequestWrite(_handle, (uint)_length, It.IsAny <byte[]>(), 0, bytesToWrite.Length, It.IsAny <AutoResetEvent>(), null), Times.Once);
            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(4));
        }
 protected override void Act()
 {
     _target.Write(_data, _offset, _count);
 }
Example #9
0
 public override void Write(byte[] buffer, int offset, int count)
 {
     _fs.Write(buffer, offset, count);
 }
 protected void Act()
 {
     _sftpFileStream.Write(_data, _offset, _count);
 }