| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 | using System;using System.IO;using Microsoft.VisualStudio.TestTools.UnitTesting;using Moq;using Renci.SshNet.Sftp;namespace Renci.SshNet.Tests.Classes.Sftp{    [TestClass]    public class SftpFileStreamTest_SetLength_SessionNotOpen : SftpFileStreamTestBase    {        private SftpFileStream _target;        private string _path;        private byte[] _handle;        private uint _bufferSize;        private uint _readBufferSize;        private uint _writeBufferSize;        private long _length;        private ObjectDisposedException _actualException;        protected override void SetupData()        {            base.SetupData();            var random = new Random();            _path = random.Next().ToString();            _handle = GenerateRandom(4, random);            _bufferSize = (uint)random.Next(1, 1000);            _readBufferSize = (uint)random.Next(1, 1000);            _writeBufferSize = (uint)random.Next(1, 1000);            _length = 5555;        }        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(false);        }        protected override void Arrange()        {            base.Arrange();            _target = new SftpFileStream(SftpSessionMock.Object,                                         _path,                                         FileMode.Open,                                         FileAccess.Read,                                         (int)_bufferSize);        }        protected override void Act()        {            try            {                _target.SetLength(_length);                Assert.Fail();            }            catch (ObjectDisposedException ex)            {                _actualException = ex;            }        }        [TestMethod]        public void SetLengthShouldHaveThrownObjectDisposedException()        {            Assert.IsNotNull(_actualException);            Assert.IsNull(_actualException.InnerException);            Assert.AreEqual(                string.Format(                   "Cannot access a closed SFTP session.{0}Object name: '{1}'.",                    Environment.NewLine,                    _actualException.ObjectName),                _actualException.Message);            Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName);        }    }}
 |