Browse Source

Modify ShellStream.ReadLine() to take into account multi-byte character.
Fixes issue #2190.
Modify ShellStream.Write(string) to write nothing when text is null.
Added unit tests.

Gert Driesen 11 years ago
parent
commit
8678d087d9

+ 1 - 0
Renci.SshClient/Build/nuget/SSH.NET.nuspec

@@ -28,6 +28,7 @@
           * Stack overflow during authentication when server returns same allowed methods after partial success (issue #2399)
           * SshCommand doesn't cleanup subscribed events (issue #2295)
           * Lines before protocol identification string are not skipped (issue #1935 and #2223)
+          * ShellStream.ReadLine produces incorrect output when reading multi-byte characters (issue #2190)
 
           2014.4.6-beta1
           ==============

+ 80 - 570
Renci.SshClient/Renci.SshNet.Tests/Classes/ShellStreamTest.cs

@@ -1,10 +1,14 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+using Renci.SshNet.Channels;
 using Renci.SshNet.Common;
 using Renci.SshNet.Tests.Common;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text.RegularExpressions;
 
 namespace Renci.SshNet.Tests.Classes
 {
@@ -14,598 +18,104 @@ namespace Renci.SshNet.Tests.Classes
     [TestClass]
     public class ShellStreamTest : TestBase
     {
-        /// <summary>
-        ///A test for BeginExpect
-        ///</summary>
-        [TestMethod()]
-        public void BeginExpectTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            TimeSpan timeout = new TimeSpan(); // TODO: Initialize to an appropriate value
-            AsyncCallback callback = null; // TODO: Initialize to an appropriate value
-            object state = null; // TODO: Initialize to an appropriate value
-            ExpectAction[] expectActions = null; // TODO: Initialize to an appropriate value
-            IAsyncResult expected = null; // TODO: Initialize to an appropriate value
-            IAsyncResult actual;
-            actual = target.BeginExpect(timeout, callback, state, expectActions);
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
+        private Mock<ISession> _sessionMock;
+        private Mock<IConnectionInfo> _connectionInfoMock;
+        private Encoding _encoding;
+        private string _terminalName;
+        private uint _widthColumns;
+        private uint _heightRows;
+        private uint _widthPixels;
+        private uint _heightPixels;
+        private int _bufferSize;
+        private Dictionary<TerminalModes, uint> _terminalModes;
+        private Mock<IChannelSession> _channelSessionMock;
 
-        /// <summary>
-        ///A test for BeginExpect
-        ///</summary>
-        [TestMethod()]
-        public void BeginExpectTest1()
+        protected override void OnInit()
         {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            ExpectAction[] expectActions = null; // TODO: Initialize to an appropriate value
-            IAsyncResult expected = null; // TODO: Initialize to an appropriate value
-            IAsyncResult actual;
-            actual = target.BeginExpect(expectActions);
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
+            base.OnInit();
 
-        /// <summary>
-        ///A test for BeginExpect
-        ///</summary>
-        [TestMethod()]
-        public void BeginExpectTest2()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            AsyncCallback callback = null; // TODO: Initialize to an appropriate value
-            ExpectAction[] expectActions = null; // TODO: Initialize to an appropriate value
-            IAsyncResult expected = null; // TODO: Initialize to an appropriate value
-            IAsyncResult actual;
-            actual = target.BeginExpect(callback, expectActions);
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
+            var random = new Random();
+            _terminalName = random.Next().ToString(CultureInfo.InvariantCulture);
+            _widthColumns = (uint) random.Next();
+            _heightRows = (uint) random.Next();
+            _widthPixels = (uint)random.Next();
+            _heightPixels = (uint)random.Next();
+            _bufferSize = random.Next();
+            _terminalModes = new Dictionary<TerminalModes, uint>();
 
-        /// <summary>
-        ///A test for BeginExpect
-        ///</summary>
-        [TestMethod()]
-        public void BeginExpectTest3()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            AsyncCallback callback = null; // TODO: Initialize to an appropriate value
-            object state = null; // TODO: Initialize to an appropriate value
-            ExpectAction[] expectActions = null; // TODO: Initialize to an appropriate value
-            IAsyncResult expected = null; // TODO: Initialize to an appropriate value
-            IAsyncResult actual;
-            actual = target.BeginExpect(callback, state, expectActions);
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
+            _encoding = Encoding.UTF8;
+            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
+            _connectionInfoMock = new Mock<IConnectionInfo>(MockBehavior.Strict);
+            _channelSessionMock = new Mock<IChannelSession>(MockBehavior.Strict);
         }
 
-        /// <summary>
-        ///A test for EndExpect
-        ///</summary>
-        [TestMethod()]
-        public void EndExpectTest()
+        [TestMethod] // issue #2190
+        public void ReadLine_MultiByteCharacters()
         {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value
-            target.EndExpect(asyncResult);
-            Assert.Inconclusive("A method that does not return a value cannot be verified.");
-        }
+            // bash: /root/menu.sh: Отказан
+            const string data1 = "bash: /root/menu.sh: \u041e\u0442\u043a\u0430\u0437\u0430\u043d";
+            // о в доступе
+            const string data2 = "\u043e \u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0435";
+            // done
+            const string data3 = "done";
 
-        /// <summary>
-        ///A test for Expect
-        ///</summary>
-        [TestMethod()]
-        public void ExpectTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            Regex regex = null; // TODO: Initialize to an appropriate value
-            TimeSpan timeout = new TimeSpan(); // TODO: Initialize to an appropriate value
-            string expected = string.Empty; // TODO: Initialize to an appropriate value
-            string actual;
-            actual = target.Expect(regex, timeout);
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
+            var shellStream = CreateShellStream();
 
-        /// <summary>
-        ///A test for Expect
-        ///</summary>
-        [TestMethod()]
-        public void ExpectTest1()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            Regex regex = null; // TODO: Initialize to an appropriate value
-            string expected = string.Empty; // TODO: Initialize to an appropriate value
-            string actual;
-            actual = target.Expect(regex);
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
+            var channelDataPublishTask = Task.Factory.StartNew(() =>
+                {
+                    _channelSessionMock.Raise(p => p.DataReceived += null,
+                        new ChannelDataEventArgs(5, _encoding.GetBytes(data1)));
+                    Thread.Sleep(50);
+                    _channelSessionMock.Raise(p => p.DataReceived += null,
+                        new ChannelDataEventArgs(5, _encoding.GetBytes(data2 + "\r\n")));
+                    _channelSessionMock.Raise(p => p.DataReceived += null,
+                        new ChannelDataEventArgs(5, _encoding.GetBytes(data3 + "\r\n")));
+                });
 
-        /// <summary>
-        ///A test for Expect
-        ///</summary>
-        [TestMethod()]
-        public void ExpectTest2()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            string text = string.Empty; // TODO: Initialize to an appropriate value
-            TimeSpan timeout = new TimeSpan(); // TODO: Initialize to an appropriate value
-            string expected = string.Empty; // TODO: Initialize to an appropriate value
-            string actual;
-            actual = target.Expect(text, timeout);
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
 
-        /// <summary>
-        ///A test for Expect
-        ///</summary>
-        [TestMethod()]
-        public void ExpectTest3()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            string text = string.Empty; // TODO: Initialize to an appropriate value
-            string expected = string.Empty; // TODO: Initialize to an appropriate value
-            string actual;
-            actual = target.Expect(text);
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
+            Assert.AreEqual(data1 + data2, shellStream.ReadLine());
+            Assert.AreEqual(data3, shellStream.ReadLine());
 
-        /// <summary>
-        ///A test for Expect
-        ///</summary>
-        [TestMethod()]
-        public void ExpectTest4()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            ExpectAction[] expectActions = null; // TODO: Initialize to an appropriate value
-            target.Expect(expectActions);
-            Assert.Inconclusive("A method that does not return a value cannot be verified.");
+            channelDataPublishTask.Wait();
         }
 
-        /// <summary>
-        ///A test for Expect
-        ///</summary>
-        [TestMethod()]
-        public void ExpectTest5()
+        [TestMethod]
+        public void Write_Text_ShouldWriteNothingWhenTextIsNull()
         {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            TimeSpan timeout = new TimeSpan(); // TODO: Initialize to an appropriate value
-            ExpectAction[] expectActions = null; // TODO: Initialize to an appropriate value
-            target.Expect(timeout, expectActions);
-            Assert.Inconclusive("A method that does not return a value cannot be verified.");
-        }
+            var shellStream = CreateShellStream();
+            const string text = null;
 
-        /// <summary>
-        ///A test for Flush
-        ///</summary>
-        [TestMethod()]
-        public void FlushTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            target.Flush();
-            Assert.Inconclusive("A method that does not return a value cannot be verified.");
-        }
+            shellStream.Write(text);
 
-        /// <summary>
-        ///A test for Read
-        ///</summary>
-        [TestMethod()]
-        public void ReadTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // 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
-            int expected = 0; // TODO: Initialize to an appropriate value
-            int actual;
-            actual = target.Read(buffer, offset, count);
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
+            _channelSessionMock.Verify(p => p.SendData(It.IsAny<byte[]>()), Times.Never);
         }
 
-        /// <summary>
-        ///A test for Read
-        ///</summary>
-        [TestMethod()]
-        public void ReadTest1()
+        [TestMethod]
+        public void WriteLine_Line_ShouldOnlyWriteLineTerminatorWhenLineIsNull()
         {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            string expected = string.Empty; // TODO: Initialize to an appropriate value
-            string actual;
-            actual = target.Read();
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
+            var shellStream = CreateShellStream();
+            const string line = null;
+            var lineTerminator = _encoding.GetBytes("\r");
 
-        /// <summary>
-        ///A test for ReadLine
-        ///</summary>
-        [TestMethod()]
-        public void ReadLineTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            string expected = string.Empty; // TODO: Initialize to an appropriate value
-            string actual;
-            actual = target.ReadLine();
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
+            _channelSessionMock.Setup(p => p.SendData(lineTerminator));
 
-        /// <summary>
-        ///A test for ReadLine
-        ///</summary>
-        [TestMethod()]
-        public void ReadLineTest1()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            TimeSpan timeout = new TimeSpan(); // TODO: Initialize to an appropriate value
-            string expected = string.Empty; // TODO: Initialize to an appropriate value
-            string actual;
-            actual = target.ReadLine(timeout);
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
+            shellStream.WriteLine(line);
 
-        /// <summary>
-        ///A test for Seek
-        ///</summary>
-        [TestMethod()]
-        public void SeekTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            long offset = 0; // TODO: Initialize to an appropriate value
-            SeekOrigin origin = new SeekOrigin(); // TODO: Initialize to an appropriate value
-            long expected = 0; // TODO: Initialize to an appropriate value
-            long actual;
-            actual = target.Seek(offset, origin);
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
+            _channelSessionMock.Verify(p => p.SendData(lineTerminator), Times.Once);
         }
 
-        /// <summary>
-        ///A test for SetLength
-        ///</summary>
-        [TestMethod()]
-        public void SetLengthTest()
+        private ShellStream CreateShellStream()
         {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            long value = 0; // TODO: Initialize to an appropriate value
-            target.SetLength(value);
-            Assert.Inconclusive("A method that does not return a value cannot be verified.");
-        }
-
-        /// <summary>
-        ///A test for Write
-        ///</summary>
-        [TestMethod()]
-        public void WriteTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // 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.");
-        }
-
-        /// <summary>
-        ///A test for Write
-        ///</summary>
-        [TestMethod()]
-        public void WriteTest1()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            string text = string.Empty; // TODO: Initialize to an appropriate value
-            target.Write(text);
-            Assert.Inconclusive("A method that does not return a value cannot be verified.");
-        }
+            _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
+            _connectionInfoMock.Setup(p => p.Encoding).Returns(_encoding);
+            _sessionMock.Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object);
+            _channelSessionMock.Setup(p => p.Open());
+            _channelSessionMock.Setup(p => p.SendPseudoTerminalRequest(_terminalName, _widthColumns, _heightRows,
+                _widthPixels, _heightPixels, _terminalModes)).Returns(true);
+            _channelSessionMock.Setup(p => p.SendShellRequest()).Returns(true);
 
-        /// <summary>
-        ///A test for WriteLine
-        ///</summary>
-        [TestMethod()]
-        public void WriteLineTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            string line = string.Empty; // TODO: Initialize to an appropriate value
-            target.WriteLine(line);
-            Assert.Inconclusive("A method that does not return a value cannot be verified.");
-        }
-
-        /// <summary>
-        ///A test for CanRead
-        ///</summary>
-        [TestMethod()]
-        public void CanReadTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            bool actual;
-            actual = target.CanRead;
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
-
-        /// <summary>
-        ///A test for CanSeek
-        ///</summary>
-        [TestMethod()]
-        public void CanSeekTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            bool actual;
-            actual = target.CanSeek;
-            Assert.Inconclusive("Verify the correctness of this test method.");
+            return new ShellStream(_sessionMock.Object, _terminalName, _widthColumns, _heightRows,
+                _widthPixels, _heightPixels, _bufferSize, _terminalModes);
         }
-
-        /// <summary>
-        ///A test for CanWrite
-        ///</summary>
-        [TestMethod()]
-        public void CanWriteTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            bool actual;
-            actual = target.CanWrite;
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
-
-        /// <summary>
-        ///A test for DataAvailable
-        ///</summary>
-        [TestMethod()]
-        public void DataAvailableTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            bool actual;
-            actual = target.DataAvailable;
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
-
-        /// <summary>
-        ///A test for Length
-        ///</summary>
-        [TestMethod()]
-        public void LengthTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            long actual;
-            actual = target.Length;
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
-
-        /// <summary>
-        ///A test for Position
-        ///</summary>
-        [TestMethod()]
-        public void PositionTest()
-        {
-            Session session = null; // TODO: Initialize to an appropriate value
-            string terminalName = string.Empty; // TODO: Initialize to an appropriate value
-            uint columns = 0; // TODO: Initialize to an appropriate value
-            uint rows = 0; // TODO: Initialize to an appropriate value
-            uint width = 0; // TODO: Initialize to an appropriate value
-            uint height = 0; // TODO: Initialize to an appropriate value
-            int maxLines = 0; // TODO: Initialize to an appropriate value
-            IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
-            ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
-            long expected = 0; // TODO: Initialize to an appropriate value
-            long actual;
-            target.Position = expected;
-            actual = target.Position;
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
-        }
-
     }
 }

+ 5 - 0
Renci.SshClient/Renci.SshNet/ConnectionInfo.cs

@@ -396,6 +396,11 @@ namespace Renci.SshNet
             clientAuthentication.Authenticate(this, session);
         }
 
+        /// <summary>
+        /// Signals that an authentication banner message was received from the server.
+        /// </summary>
+        /// <param name="sender">The session in which the banner message was received.</param>
+        /// <param name="e">The banner message.{</param>
         void IConnectionInfo.UserAuthenticationBannerReceived(object sender, MessageEventArgs<BannerMessage> e)
         {
             var authenticationBanner = AuthenticationBanner;

+ 17 - 0
Renci.SshClient/Renci.SshNet/IConnectionInfo.cs

@@ -1,10 +1,22 @@
 using System.Collections.Generic;
+using System.Text;
 using Renci.SshNet.Messages.Authentication;
 
 namespace Renci.SshNet
 {
+    /// <summary>
+    /// Represents remote connection information.
+    /// </summary>
     internal interface IConnectionInfo
     {
+        /// <summary>
+        /// Gets the character encoding.
+        /// </summary>
+        /// <value>
+        /// The character encoding.
+        /// </value>
+        Encoding Encoding { get; }
+
         /// <summary>
         /// Gets the supported authentication methods for this connection.
         /// </summary>
@@ -13,6 +25,11 @@ namespace Renci.SshNet
         /// </value>
         IEnumerable<IAuthenticationMethod> AuthenticationMethods { get; }
 
+        /// <summary>
+        /// Signals that an authentication banner message was received from the server.
+        /// </summary>
+        /// <param name="sender">The session in which the banner message was received.</param>
+        /// <param name="e">The banner message.{</param>
         void UserAuthenticationBannerReceived(object sender, MessageEventArgs<BannerMessage> e);
 
         /// <summary>

+ 1 - 1
Renci.SshClient/Renci.SshNet/ISession.cs

@@ -15,7 +15,7 @@ namespace Renci.SshNet
         ///// Gets or sets the connection info.
         ///// </summary>
         ///// <value>The connection info.</value>
-        //IConnectionInfo ConnectionInfo { get; }
+        IConnectionInfo ConnectionInfo { get; }
 
         /// <summary>
         /// Create a new SSH session channel.

+ 38 - 25
Renci.SshClient/Renci.SshNet/Session.cs

@@ -650,17 +650,6 @@ namespace Renci.SshNet
             }
         }
 
-        /// <summary>
-        /// Create a new SSH session channel.
-        /// </summary>
-        /// <returns>
-        /// A new SSH session channel.
-        /// </returns>
-        IChannelSession ISession.CreateChannelSession()
-        {
-            return CreateClientChannel<ChannelSession>();
-        }
-
         /// <summary>
         /// Create a new client channel.
         /// </summary>
@@ -777,18 +766,6 @@ namespace Renci.SshNet
             }
         }
 
-        /// <summary>
-        /// Sends a message to the server.
-        /// </summary>
-        /// <param name="message">The message to send.</param>
-        /// <exception cref="SshConnectionException">The client is not connected.</exception>
-        /// <exception cref="SshOperationTimeoutException">The operation timed out.</exception>
-        /// <exception cref="InvalidOperationException">The size of the packet exceeds the maximum size defined by the protocol.</exception>
-        void ISession.SendMessage(Message message)
-        {
-            SendMessage(message);
-        }
-
         /// <summary>
         /// Sends a message to the server.
         /// </summary>
@@ -2108,7 +2085,7 @@ namespace Renci.SshNet
             _keyExchangeInProgress = false;
         }
 
-        #region IDisposable Members
+        #region IDisposable implementation
 
         private bool _disposed;
 
@@ -2197,7 +2174,43 @@ namespace Renci.SshNet
             Dispose(false);
         }
 
-        #endregion
+        #endregion IDisposable implementation
+
+        #region ISession implementation
+
+        /// <summary>
+        /// Gets or sets the connection info.
+        /// </summary>
+        /// <value>The connection info.</value>
+        IConnectionInfo ISession.ConnectionInfo
+        {
+            get { return ConnectionInfo; }
+        }
+
+        /// <summary>
+        /// Create a new SSH session channel.
+        /// </summary>
+        /// <returns>
+        /// A new SSH session channel.
+        /// </returns>
+        IChannelSession ISession.CreateChannelSession()
+        {
+            return CreateClientChannel<ChannelSession>();
+        }
+
+        /// <summary>
+        /// Sends a message to the server.
+        /// </summary>
+        /// <param name="message">The message to send.</param>
+        /// <exception cref="SshConnectionException">The client is not connected.</exception>
+        /// <exception cref="SshOperationTimeoutException">The operation timed out.</exception>
+        /// <exception cref="InvalidOperationException">The size of the packet exceeds the maximum size defined by the protocol.</exception>
+        void ISession.SendMessage(Message message)
+        {
+            SendMessage(message);
+        }
+
+        #endregion ISession implementation
 
         private class MessageMetadata
         {

+ 64 - 74
Renci.SshClient/Renci.SshNet/ShellStream.cs

@@ -15,9 +15,10 @@ namespace Renci.SshNet
     /// </summary>
     public partial class ShellStream : Stream
     {
+        private const string CrLf = "\r\n";
         private const int BufferSize = 1024;
 
-        private readonly Session _session;
+        private readonly ISession _session;
         private readonly Encoding _encoding;
         private readonly Queue<byte> _incoming;
         private readonly Queue<byte> _outgoing;
@@ -38,7 +39,7 @@ namespace Renci.SshNet
         /// Gets a value that indicates whether data is available on the <see cref="ShellStream"/> to be read.
         /// </summary>
         /// <value>
-        ///   <c>true</c> if data is available to be read; otherwise, <c>false</c>.
+        /// <c>true</c> if data is available to be read; otherwise, <c>false</c>.
         /// </value>
         public bool DataAvailable
         {
@@ -51,14 +52,14 @@ namespace Renci.SshNet
             }
         }
 
-        internal ShellStream(Session session, string terminalName, uint columns, uint rows, uint width, uint height, int maxLines, IDictionary<TerminalModes, uint> terminalModeValues)
+        internal ShellStream(ISession session, string terminalName, uint columns, uint rows, uint width, uint height, int maxLines, IDictionary<TerminalModes, uint> terminalModeValues)
         {
             _encoding = session.ConnectionInfo.Encoding;
             _session = session;
             _incoming = new Queue<byte>();
             _outgoing = new Queue<byte>();
 
-            _channel = _session.CreateClientChannel<ChannelSession>();
+            _channel = _session.CreateChannelSession();
             _channel.DataReceived += Channel_DataReceived;
             _channel.Closed += Channel_Closed;
             _session.Disconnected += Session_Disconnected;
@@ -74,7 +75,9 @@ namespace Renci.SshNet
         /// <summary>
         /// Gets a value indicating whether the current stream supports reading.
         /// </summary>
-        /// <returns>true if the stream supports reading; otherwise, false.</returns>
+        /// <returns>
+        /// <c>true</c> if the stream supports reading; otherwise, <c>false</c>.
+        /// </returns>
         public override bool CanRead
         {
             get { return true; }
@@ -83,7 +86,9 @@ namespace Renci.SshNet
         /// <summary>
         /// Gets a value indicating whether the current stream supports seeking.
         /// </summary>
-        /// <returns>true if the stream supports seeking; otherwise, false.</returns>
+        /// <returns>
+        /// <c>true</c> if the stream supports seeking; otherwise, <c>false</c>.
+        /// </returns>
         public override bool CanSeek
         {
             get { return false; }
@@ -92,7 +97,9 @@ namespace Renci.SshNet
         /// <summary>
         /// Gets a value indicating whether the current stream supports writing.
         /// </summary>
-        /// <returns>true if the stream supports writing; otherwise, false.</returns>
+        /// <returns>
+        /// <c>true</c> if the stream supports writing; otherwise, <c>false</c>.
+        /// </returns>
         public override bool CanWrite
         {
             get { return true; }
@@ -101,7 +108,7 @@ namespace Renci.SshNet
         /// <summary>
         /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
         /// </summary>
-        /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
+        /// <exception cref="T:System.IO.IOException">An I/O error occurs.</exception>
         public override void Flush()
         {
             if (_channel == null)
@@ -116,10 +123,8 @@ namespace Renci.SshNet
         /// Gets the length in bytes of the stream.
         /// </summary>
         /// <returns>A long value representing the length of the stream in bytes.</returns>
-        ///   
-        /// <exception cref="T:System.NotSupportedException">A class derived from Stream does not support seeking. </exception>
-        ///   
-        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
+        /// <exception cref="T:System.NotSupportedException">A class derived from Stream does not support seeking.</exception>
+        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.</exception>
         public override long Length
         {
             get
@@ -134,13 +139,12 @@ namespace Renci.SshNet
         /// <summary>
         /// Gets or sets the position within the current stream.
         /// </summary>
-        /// <returns>The current position within the stream.</returns>
-        ///   
-        /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
-        ///   
-        /// <exception cref="T:System.NotSupportedException">The stream does not support seeking. </exception>
-        ///   
-        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
+        /// <returns>
+        /// The current position within the stream.
+        /// </returns>
+        /// <exception cref="T:System.IO.IOException">An I/O error occurs.</exception>
+        /// <exception cref="T:System.NotSupportedException">The stream does not support seeking.</exception>
+        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.</exception>
         public override long Position
         {
             get { return 0; }
@@ -157,18 +161,11 @@ namespace Renci.SshNet
         /// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
         /// </returns>
         /// <exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is larger than the buffer length. </exception>
-        ///   
-        /// <exception cref="T:System.ArgumentNullException">
-        ///   <paramref name="buffer"/> is null. </exception>
-        ///   
-        /// <exception cref="T:System.ArgumentOutOfRangeException">
-        ///   <paramref name="offset"/> or <paramref name="count"/> is negative. </exception>
-        ///   
-        /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
-        ///   
-        /// <exception cref="T:System.NotSupportedException">The stream does not support reading. </exception>
-        ///   
-        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
+        /// <exception cref="T:System.ArgumentNullException"><paramref name="buffer"/> is null.</exception>
+        /// <exception cref="T:System.ArgumentOutOfRangeException"><paramref name="offset"/> or <paramref name="count"/> is negative.</exception>
+        /// <exception cref="T:System.IO.IOException">An I/O error occurs.</exception>   
+        /// <exception cref="T:System.NotSupportedException">The stream does not support reading.</exception>   
+        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.</exception>
         public override int Read(byte[] buffer, int offset, int count)
         {
             var i = 0;
@@ -192,11 +189,9 @@ namespace Renci.SshNet
         /// <returns>
         /// The new position within the current stream.
         /// </returns>
-        /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
-        ///   
-        /// <exception cref="T:System.NotSupportedException">The stream does not support seeking, such as if the stream is constructed from a pipe or console output. </exception>
-        ///   
-        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
+        /// <exception cref="T:System.IO.IOException">An I/O error occurs.</exception>
+        /// <exception cref="T:System.NotSupportedException">The stream does not support seeking, such as if the stream is constructed from a pipe or console output.</exception>
+        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.</exception>
         public override long Seek(long offset, SeekOrigin origin)
         {
             throw new NotSupportedException();
@@ -206,11 +201,9 @@ namespace Renci.SshNet
         /// This method is not supported.
         /// </summary>
         /// <param name="value">The desired length of the current stream in bytes.</param>
-        /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
-        ///   
-        /// <exception cref="T:System.NotSupportedException">The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output. </exception>
-        ///   
-        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
+        /// <exception cref="T:System.IO.IOException">An I/O error occurs.</exception>
+        /// <exception cref="T:System.NotSupportedException">The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output.</exception>
+        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.</exception>
         public override void SetLength(long value)
         {
             throw new NotSupportedException();
@@ -222,19 +215,12 @@ namespace Renci.SshNet
         /// <param name="buffer">An array of bytes. This method copies <paramref name="count"/> bytes from <paramref name="buffer"/> to the current stream.</param>
         /// <param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin copying bytes to the current stream.</param>
         /// <param name="count">The number of bytes to be written to the current stream.</param>
-        /// <exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is greater than the buffer length. </exception>
-        ///   
-        /// <exception cref="T:System.ArgumentNullException">
-        ///   <paramref name="buffer"/> is null. </exception>
-        ///   
-        /// <exception cref="T:System.ArgumentOutOfRangeException">
-        ///   <paramref name="offset"/> or <paramref name="count"/> is negative. </exception>
-        ///   
-        /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
-        ///   
-        /// <exception cref="T:System.NotSupportedException">The stream does not support writing. </exception>
-        ///   
-        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
+        /// <exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is greater than the buffer length.</exception>
+        /// <exception cref="T:System.ArgumentNullException"><paramref name="buffer"/> is null.</exception>
+        /// <exception cref="T:System.ArgumentOutOfRangeException"><paramref name="offset"/> or <paramref name="count"/> is negative.</exception>
+        /// <exception cref="T:System.IO.IOException">An I/O error occurs.</exception>
+        /// <exception cref="T:System.NotSupportedException">The stream does not support writing.</exception>
+        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.</exception>
         public override void Write(byte[] buffer, int offset, int count)
         {
             foreach (var b in buffer.Skip(offset).Take(count).ToArray())
@@ -513,7 +499,6 @@ namespace Renci.SshNet
         /// </returns>
         public string Expect(Regex regex, TimeSpan timeout)
         {
-            //  TODO:   Refactor this method, will deda lock
             var text = string.Empty;
 
             while (true)
@@ -558,18 +543,20 @@ namespace Renci.SshNet
         /// <summary>
         /// Reads the line from the shell. If line is not available it will block the execution and will wait for new line.
         /// </summary>
-        /// <returns>The line read from the shell.</returns>
+        /// <returns>
+        /// The line read from the shell.
+        /// </returns>
         public string ReadLine()
         {
             return ReadLine(TimeSpan.Zero);
         }
 
         /// <summary>
-        /// Reads the line from the shell. If line is not available it will block the execution and will wait for new line.
+        /// Reads a line from the shell. If line is not available it will block the execution and will wait for new line.
         /// </summary>
         /// <param name="timeout">Time to wait for input.</param>
         /// <returns>
-        /// The line read from the shell, if the specified time elapsed returns null.
+        /// The line read from the shell, or <c>null</c> when no input is received for the specified timeout.
         /// </returns>
         public string ReadLine(TimeSpan timeout)
         {
@@ -584,17 +571,19 @@ namespace Renci.SshNet
                         text = _encoding.GetString(_incoming.ToArray(), 0, _incoming.Count);
                     }
 
-                    var index = text.IndexOf("\r\n", StringComparison.Ordinal);
+                    var index = text.IndexOf(CrLf, StringComparison.Ordinal);
 
                     if (index >= 0)
                     {
                         text = text.Substring(0, index);
 
-                        //  Remove processed items from the queue
-                        for (int i = 0; i < index + 2 && _incoming.Count > 0; i++)
-                        {
+                        // determine how many bytes to remove from buffer
+                        var bytesProcessed = _encoding.GetByteCount(text + CrLf);
+
+                        // remove processed bytes from the queue
+                        for (var i = 0; i < bytesProcessed; i++)
                             _incoming.Dequeue();
-                        }
+
                         break;
                     }
                 }
@@ -619,7 +608,9 @@ namespace Renci.SshNet
         /// <summary>
         /// Reads text available in the shell.
         /// </summary>
-        /// <returns>The text available in the shell.</returns>
+        /// <returns>
+        /// The text available in the shell.
+        /// </returns>
         public string Read()
         {
             string text;
@@ -637,8 +628,14 @@ namespace Renci.SshNet
         /// Writes the specified text to the shell.
         /// </summary>
         /// <param name="text">The text to be written to the shell.</param>
+        /// <remarks>
+        /// If <paramref name="text"/> is <c>null</c>, nothing is written.
+        /// </remarks>
         public void Write(string text)
         {
+            if (text == null)
+                return;
+
             if (_channel == null)
             {
                 throw new ObjectDisposedException("ShellStream");
@@ -652,6 +649,9 @@ namespace Renci.SshNet
         /// Writes the line to the shell.
         /// </summary>
         /// <param name="line">The line to be written to the shell.</param>
+        /// <remarks>
+        /// If <paramref name="line"/> is <c>null</c>, only the line terminator is written.
+        /// </remarks>
         public void WriteLine(string line)
         {
             var commandText = string.Format("{0}{1}", line, "\r");
@@ -687,15 +687,6 @@ namespace Renci.SshNet
             }
         }
 
-        /// <summary>
-        /// Waits for the handle to be signaled or for an error to occurs.
-        /// </summary>
-        /// <param name="waitHandle">The wait handle.</param>
-        protected void WaitOnHandle(WaitHandle waitHandle)
-        {
-            _session.WaitOnHandle(waitHandle);
-        }
-
         partial void ExecuteThread(Action action);
 
         private void Session_ErrorOccured(object sender, ExceptionEventArgs e)
@@ -709,7 +700,6 @@ namespace Renci.SshNet
             if (_channel != null && _channel.IsOpen)
             {
                 _channel.SendEof();
-
                 _channel.Close();
             }
         }