Example #1
0
        protected void Arrange()
        {
            var random = new Random();

            _path            = random.Next().ToString(CultureInfo.InvariantCulture);
            _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.Close();
        }
Example #2
0
        public void CloseTest()
        {
            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

            target.Close();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
        protected override void Arrange()
        {
            base.Arrange();

            _target = new SftpFileStream(SftpSessionMock.Object,
                                         _path,
                                         FileMode.Open,
                                         FileAccess.Write,
                                         (int)_bufferSize);
            _target.Close();
        }
Example #4
0
 public override void CloseFile()
 {
     if (fileStream != null)
     {
         bool wasWriting = fileStream.CanWrite && !fileStream.CanRead;
         fileStream.Close();
         if (wasWriting)
         {
             sftpClient.SetLastWriteTimeUtc(WireEncodedString(fileName), fileLastWriteTimeUtc);
         }
     }
     fileName             = null;
     fileStream           = null;
     fileLastWriteTimeUtc = DateTime.MinValue;
 }
Example #5
0
        public void DownloadFile(string remotePath, string localPath, AsyncCallback callback)
        {
            SftpFileStream inSt  = null;
            FileStream     outSt = null;

            try
            {
                SftpFile file     = sftp.Get(remotePath);
                long     fileSize = file.Length;

                inSt  = sftp.OpenRead(remotePath);
                outSt = new FileStream(localPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);

                byte[] buf   = new byte[8092];
                int    len   = 0;
                long   count = 0;
                while ((len = inSt.Read(buf, 0, 8092)) > 0)
                {
                    outSt.Write(buf, 0, len);
                    count += len;

                    if (callback != null) // 下载进度回调通知
                    {
                        DownloadAsyncResult result = new DownloadAsyncResult(count, fileSize);
                        callback.Invoke(result);
                    }
                }
            }
            finally
            {
                if (inSt != null)
                {
                    inSt.Close();
                }
                if (outSt != null)
                {
                    outSt.Close();
                }
            }
        }
Example #6
0
 protected void Act()
 {
     _sftpFileStream.Close();
 }
 protected override void Act()
 {
     _target.Close();
 }