Procházet zdrojové kódy

Add new method to Extensions class for test purposes
Add argument checking based on test
Correct some tests and add few more

olegkap_cp před 14 roky
rodič
revize
e9167373f7

+ 149 - 143
Renci.SshClient/Renci.SshNet.Tests/ConnectionTest.cs

@@ -11,133 +11,147 @@ using System.Net;
 
 namespace Renci.SshNet.Tests
 {
-    [TestClass]
-    public class ConnectionTest
-    {
-        [TestMethod]
-        public void Test_Connect_Using_Correct_Password()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        [ExpectedException(typeof(SshAuthenticationException))]
-        public void Test_Connect_Using_Invalid_Password()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password"))
-            {
-                client.Connect();
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Connect_Using_Rsa_Key_Without_PassPhrase()
-        {
-            MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS));
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream)))
-            {
-                client.Connect();
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Connect_Using_RsaKey_With_PassPhrase()
-        {
-            MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS));
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, Resources.PASSWORD)))
-            {
-                client.Connect();
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        [ExpectedException(typeof(SshPassPhraseNullOrEmptyException))]
-        public void Test_Connect_Using_Key_With_Empty_PassPhrase()
-        {
-            MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS));
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, null)))
-            {
-                client.Connect();
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Connect_Using_DsaKey_Without_PassPhrase()
-        {
-            MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITHOUT_PASS));
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream)))
-            {
-                client.Connect();
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Connect_Using_DsaKey_With_PassPhrase()
-        {
-            MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITH_PASS));
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, Resources.PASSWORD)))
-            {
-                client.Connect();
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        [ExpectedException(typeof(SshAuthenticationException))]
-        public void Test_Connect_Using_Invalid_PrivateKey()
-        {
-            MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.INVALID_KEY));
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream)))
-            {
-                client.Connect();
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Connect_Using_Multiple_PrivateKeys()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME,
-                new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.INVALID_KEY))),
-                new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITH_PASS)), Resources.PASSWORD),
-                new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS)), Resources.PASSWORD),
-                new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS))),
-                new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITHOUT_PASS)))
-                ))
-            {
-                client.Connect();
-                client.Disconnect();
-            }
-        }
-
-
-        [TestMethod]
-        public void Test_Connect_Then_Reconnect()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                client.Disconnect();
-                client.Connect();
-                client.Disconnect();
-            }
-        }
+	[TestClass]
+	public class ConnectionTest
+	{
+		[TestMethod]
+		public void Test_Connect_Using_Correct_Password()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		[ExpectedException(typeof(SshAuthenticationException))]
+		public void Test_Connect_Using_Invalid_Password()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password"))
+			{
+				client.Connect();
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Connect_Using_Rsa_Key_Without_PassPhrase()
+		{
+			MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS));
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream)))
+			{
+				client.Connect();
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Connect_Using_RsaKey_With_PassPhrase()
+		{
+			MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS));
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, Resources.PASSWORD)))
+			{
+				client.Connect();
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		[ExpectedException(typeof(SshPassPhraseNullOrEmptyException))]
+		public void Test_Connect_Using_Key_With_Empty_PassPhrase()
+		{
+			MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS));
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, null)))
+			{
+				client.Connect();
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Connect_Using_DsaKey_Without_PassPhrase()
+		{
+			MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITHOUT_PASS));
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream)))
+			{
+				client.Connect();
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Connect_Using_DsaKey_With_PassPhrase()
+		{
+			MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITH_PASS));
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, Resources.PASSWORD)))
+			{
+				client.Connect();
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		[ExpectedException(typeof(SshAuthenticationException))]
+		public void Test_Connect_Using_Invalid_PrivateKey()
+		{
+			MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.INVALID_KEY));
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream)))
+			{
+				client.Connect();
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Connect_Using_Multiple_PrivateKeys()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME,
+				new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.INVALID_KEY))),
+				new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITH_PASS)), Resources.PASSWORD),
+				new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS)), Resources.PASSWORD),
+				new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS))),
+				new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITHOUT_PASS)))
+				))
+			{
+				client.Connect();
+				client.Disconnect();
+			}
+		}
+
+
+		[TestMethod]
+		public void Test_Connect_Then_Reconnect()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				client.Disconnect();
+				client.Connect();
+				client.Disconnect();
+			}
+		}
 
 		[WorkItem(703), TestMethod]
-        [ExpectedException(typeof(ArgumentNullException))]
-        public void Test_ConnectionInfo_NullHost()
-        {
-            var connectionInfo = new PasswordConnectionInfo(null, null, null);
-        }
+		[ExpectedException(typeof(ArgumentException))]
+		public void Test_ConnectionInfo_Host_Is_Null()
+		{
+			var connectionInfo = new PasswordConnectionInfo(null, "username", "password");
+		}
+
+		[WorkItem(703), TestMethod]
+		[ExpectedException(typeof(ArgumentException))]
+		public void Test_ConnectionInfo_Username_Is_Null()
+		{
+			var connectionInfo = new PasswordConnectionInfo("host", null, "password");
+		}
+
+		[WorkItem(703), TestMethod]
+		[ExpectedException(typeof(ArgumentNullException))]
+		public void Test_ConnectionInfo_Password_Is_Null()
+		{
+			var connectionInfo = new PasswordConnectionInfo("host", "username", null);
+		}
 
 		[TestMethod]
 		[Description("Test passing whitespace to host parameter.")]
@@ -155,27 +169,19 @@ namespace Renci.SshNet.Tests
 			var connectionInfo = new PasswordConnectionInfo(Resources.HOST, " ", Resources.PASSWORD);
 		}
 
-		[TestMethod]
-		[Description("Test passing whitespace to password parameter.")]
-		[ExpectedException(typeof(ArgumentException))]
-		public void Test_ConnectionInfo_Password_Is_Whitespace()
+		[WorkItem(703), TestMethod]
+		[ExpectedException(typeof(ArgumentOutOfRangeException))]
+		public void Test_ConnectionInfo_SmallPortNumber()
 		{
-			var connectionInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, " ");
+			var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MinPort - 1, null, null);
 		}
 
 		[WorkItem(703), TestMethod]
-        [ExpectedException(typeof(ArgumentOutOfRangeException))]
-        public void Test_ConnectionInfo_SmallPortNumber()
-        {
-            var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MinPort - 1, null, null);
-        }
-
-		[WorkItem(703), TestMethod]
-        [ExpectedException(typeof(ArgumentOutOfRangeException))]
-        public void Test_ConnectionInfo_BigPortNumber()
-        {
-            var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MaxPort + 1, null, null);
-        }
+		[ExpectedException(typeof(ArgumentOutOfRangeException))]
+		public void Test_ConnectionInfo_BigPortNumber()
+		{
+			var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MaxPort + 1, null, null);
+		}
 
-    }
+	}
 }

+ 1 - 1
Renci.SshClient/Renci.SshNet.Tests/SftpClientTests/CreateDirectoryTest.cs

@@ -109,7 +109,7 @@ namespace Renci.SshNet.Tests.SftpClientTests
 		[TestMethod]
 		[TestCategory("Sftp")]
 		[Description("Test passing null to CreateDirectory.")]
-		[ExpectedException(typeof(ArgumentNullException))]
+		[ExpectedException(typeof(ArgumentException))]
 		public void Test_Sftp_CreateDirectory_Null()
 		{
 			using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))

+ 2 - 2
Renci.SshClient/Renci.SshNet.Tests/SftpClientTests/DeleteDirectoryTest.cs

@@ -84,8 +84,8 @@ namespace Renci.SshNet.Tests.SftpClientTests
 
 		[TestMethod]
 		[TestCategory("Sftp")]
-		[Description("Test passing null to DeleteDirectory.")]		
-		[ExpectedException(typeof(ArgumentNullException))]
+		[Description("Test passing null to DeleteDirectory.")]
+        [ExpectedException(typeof(ArgumentException))]
 		public void Test_Sftp_DeleteDirectory_Null()
 		{
 			using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))

+ 1 - 1
Renci.SshClient/Renci.SshNet.Tests/SftpClientTests/DeleteFileTest.cs

@@ -29,7 +29,7 @@ namespace Renci.SshNet.Tests.SftpClientTests
 		[TestMethod]
 		[TestCategory("Sftp")]
 		[Description("Test passing null to DeleteFile.")]
-		[ExpectedException(typeof(ArgumentNullException))]
+		[ExpectedException(typeof(ArgumentException))]
 		public void Test_Sftp_DeleteFile_Null()
 		{
 			using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))

+ 82 - 26
Renci.SshClient/Renci.SshNet.Tests/SftpClientTests/UploadDownloadFileTest.cs

@@ -391,33 +391,89 @@ namespace Renci.SshNet.Tests.SftpClientTests
 			}
 		}
 
-		[TestMethod]
-		[TestCategory("Sftp")]
-		[Description("Test passing null to BeginUploadFile")]
-		[ExpectedException(typeof(ArgumentNullException))]
-		public void Test_Sftp_BeginUploadFile_Null()
-		{
-			using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-			{
-				sftp.Connect();
-				sftp.BeginUploadFile(null, null, null, null);
-				sftp.Disconnect();
-			}
-		}
+        [TestMethod]
+        [TestCategory("Sftp")]
+        [Description("Test passing null to BeginUploadFile")]
+        [ExpectedException(typeof(ArgumentNullException))]
+        public void Test_Sftp_BeginUploadFile_StreamIsNull()
+        {
+            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+            {
+                sftp.Connect();
+                sftp.BeginUploadFile(null, "aaaaa", null, null);
+                sftp.Disconnect();
+            }
+        }
 
-		[TestMethod]
-		[TestCategory("Sftp")]
-		[Description("Test passing null to BeginDownloadFile")]
-		[ExpectedException(typeof(ArgumentNullException))]
-		public void Test_Sftp_BeginDownloadFile_Null()
-		{
-			using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-			{
-				sftp.Connect();
-				sftp.BeginDownloadFile(null, null, null, null);
-				sftp.Disconnect();
-			}
-		}
+        [TestMethod]
+        [TestCategory("Sftp")]
+        [Description("Test passing null to BeginUploadFile")]
+        [ExpectedException(typeof(ArgumentException))]
+        public void Test_Sftp_BeginUploadFile_FileNameIsWhiteSpace()
+        {
+            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+            {
+                sftp.Connect();
+                sftp.BeginUploadFile(new MemoryStream(), "   ", null, null);
+                sftp.Disconnect();
+            }
+        }
+
+        [TestMethod]
+        [TestCategory("Sftp")]
+        [Description("Test passing null to BeginUploadFile")]
+        [ExpectedException(typeof(ArgumentException))]
+        public void Test_Sftp_BeginUploadFile_FileNameIsNull()
+        {
+            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+            {
+                sftp.Connect();
+                sftp.BeginUploadFile(new MemoryStream(), null, null, null);
+                sftp.Disconnect();
+            }
+        }
+
+        [TestMethod]
+        [TestCategory("Sftp")]
+        [Description("Test passing null to BeginDownloadFile")]
+        [ExpectedException(typeof(ArgumentNullException))]
+        public void Test_Sftp_BeginDownloadFile_StreamIsNull()
+        {
+            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+            {
+                sftp.Connect();
+                sftp.BeginDownloadFile("aaaa", null, null, null);
+                sftp.Disconnect();
+            }
+        }
+
+        [TestMethod]
+        [TestCategory("Sftp")]
+        [Description("Test passing null to BeginDownloadFile")]
+        [ExpectedException(typeof(ArgumentException))]
+        public void Test_Sftp_BeginDownloadFile_FileNameIsWhiteSpace()
+        {
+            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+            {
+                sftp.Connect();
+                sftp.BeginDownloadFile("   ", new MemoryStream(), null, null);
+                sftp.Disconnect();
+            }
+        }
+
+        [TestMethod]
+        [TestCategory("Sftp")]
+        [Description("Test passing null to BeginDownloadFile")]
+        [ExpectedException(typeof(ArgumentException))]
+        public void Test_Sftp_BeginDownloadFile_FileNameIsNull()
+        {
+            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+            {
+                sftp.Connect();
+                sftp.BeginDownloadFile(null, new MemoryStream(), null, null);
+                sftp.Disconnect();
+            }
+        }
 
         /// <summary>
         /// Creates the test file.

+ 128 - 126
Renci.SshClient/Renci.SshNet.Tests/SshClientTests/TestPortForwarding.cs

@@ -8,115 +8,115 @@ using Renci.SshNet.Common;
 
 namespace Renci.SshNet.Tests.SshClientTests
 {
-    /// <summary>
-    /// Summary description for UnitTest1
-    /// </summary>
-    [TestClass]
-    public class TestPortForwarding
-    {
-        [TestMethod]
-        [ExpectedException(typeof(SshConnectionException))]
-        public void Test_PortForwarding_Local_Without_Connecting()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                var port1 = client.AddForwardedPort<ForwardedPortLocal>("localhost", 8084, "www.renci.org", 80);
-                port1.Exception += delegate(object sender, ExceptionEventArgs e)
-                {
-                    Assert.Fail(e.Exception.ToString());
-                };
-                port1.Start();
-
-                System.Threading.Tasks.Parallel.For(0, 100,
-                    //new ParallelOptions
-                    //{
-                    //    MaxDegreeOfParallelism = 20,
-                    //},
-                    (counter) =>
-                    {
-                        var start = DateTime.Now;
-                        var req = HttpWebRequest.Create("http://localhost:8084");
-                        using (var response = req.GetResponse())
-                        {
-
-                            var data = ReadStream(response.GetResponseStream());
-                            var end = DateTime.Now;
-
-                            Debug.WriteLine(string.Format("Request# {2}: Lenght: {0} Time: {1}", data.Length, (end - start), counter));
-                        }
-                    }
-                );
-            }
-        }
-
-        [TestMethod]
-        public void Test_PortForwarding_Local()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var port1 = client.AddForwardedPort<ForwardedPortLocal>("localhost", 8084, "www.renci.org", 80);
-                port1.Exception += delegate(object sender, ExceptionEventArgs e)
-                {
-                    Assert.Fail(e.Exception.ToString());
-                };
-                port1.Start();
-
-                System.Threading.Tasks.Parallel.For(0, 100,
-                    //new ParallelOptions
-                    //{
-                    //    MaxDegreeOfParallelism = 20,
-                    //},
-                    (counter) =>
-                    {
-                        var start = DateTime.Now;
-                        var req = HttpWebRequest.Create("http://localhost:8084");
-                        using (var response = req.GetResponse())
-                        {
-
-                            var data = ReadStream(response.GetResponseStream());
-                            var end = DateTime.Now;
-
-                            Debug.WriteLine(string.Format("Request# {2}: Length: {0} Time: {1}", data.Length, (end - start), counter));
-                        }
-                    }
-                );
-            }
-        }
-
-        [TestMethod]
-        public void Test_PortForwarding_Remote()
-        {
-            //  ******************************************************************
-            //  ************* Tests are still in not finished ********************
-            //  ******************************************************************
-
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var port1 = client.AddForwardedPort<ForwardedPortRemote>("", 8082, "www.renci.org", 80);
-                port1.Exception += delegate(object sender, ExceptionEventArgs e)
-                {
-                    Assert.Fail(e.Exception.ToString());
-                };
-                port1.Start();
-                var boundport = port1.BoundPort;
-
-                System.Threading.Tasks.Parallel.For(0, 5,
-                    //new ParallelOptions
-                    //{
-                    //    MaxDegreeOfParallelism = 1,
-                    //},
-                    (counter) =>
-                    {
-                        var cmd = client.CreateCommand(string.Format("wget -O- http://localhost:{0}", boundport));
-                        var result = cmd.Execute();
-                        var end = DateTime.Now;
-                        Debug.WriteLine(string.Format("Length: {0}", result.Length));
-                    }
-                );
-            }
-        }
+	/// <summary>
+	/// Summary description for UnitTest1
+	/// </summary>
+	[TestClass]
+	public class TestPortForwarding
+	{
+		[TestMethod]
+		[ExpectedException(typeof(SshConnectionException))]
+		public void Test_PortForwarding_Local_Without_Connecting()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				var port1 = client.AddForwardedPort<ForwardedPortLocal>("localhost", 8084, "www.renci.org", 80);
+				port1.Exception += delegate(object sender, ExceptionEventArgs e)
+				{
+					Assert.Fail(e.Exception.ToString());
+				};
+				port1.Start();
+
+				System.Threading.Tasks.Parallel.For(0, 100,
+					//new ParallelOptions
+					//{
+					//    MaxDegreeOfParallelism = 20,
+					//},
+					(counter) =>
+					{
+						var start = DateTime.Now;
+						var req = HttpWebRequest.Create("http://localhost:8084");
+						using (var response = req.GetResponse())
+						{
+
+							var data = ReadStream(response.GetResponseStream());
+							var end = DateTime.Now;
+
+							Debug.WriteLine(string.Format("Request# {2}: Lenght: {0} Time: {1}", data.Length, (end - start), counter));
+						}
+					}
+				);
+			}
+		}
+
+		[TestMethod]
+		public void Test_PortForwarding_Local()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var port1 = client.AddForwardedPort<ForwardedPortLocal>("localhost", 8084, "www.renci.org", 80);
+				port1.Exception += delegate(object sender, ExceptionEventArgs e)
+				{
+					Assert.Fail(e.Exception.ToString());
+				};
+				port1.Start();
+
+				System.Threading.Tasks.Parallel.For(0, 100,
+					//new ParallelOptions
+					//{
+					//    MaxDegreeOfParallelism = 20,
+					//},
+					(counter) =>
+					{
+						var start = DateTime.Now;
+						var req = HttpWebRequest.Create("http://localhost:8084");
+						using (var response = req.GetResponse())
+						{
+
+							var data = ReadStream(response.GetResponseStream());
+							var end = DateTime.Now;
+
+							Debug.WriteLine(string.Format("Request# {2}: Length: {0} Time: {1}", data.Length, (end - start), counter));
+						}
+					}
+				);
+			}
+		}
+
+		[TestMethod]
+		public void Test_PortForwarding_Remote()
+		{
+			//  ******************************************************************
+			//  ************* Tests are still in not finished ********************
+			//  ******************************************************************
+
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var port1 = client.AddForwardedPort<ForwardedPortRemote>("", 8082, "www.renci.org", 80);
+				port1.Exception += delegate(object sender, ExceptionEventArgs e)
+				{
+					Assert.Fail(e.Exception.ToString());
+				};
+				port1.Start();
+				var boundport = port1.BoundPort;
+
+				System.Threading.Tasks.Parallel.For(0, 5,
+					//new ParallelOptions
+					//{
+					//    MaxDegreeOfParallelism = 1,
+					//},
+					(counter) =>
+					{
+						var cmd = client.CreateCommand(string.Format("wget -O- http://localhost:{0}", boundport));
+						var result = cmd.Execute();
+						var end = DateTime.Now;
+						Debug.WriteLine(string.Format("Length: {0}", result.Length));
+					}
+				);
+			}
+		}
 
 		[TestMethod]
 		[Description("Test passing null to AddForwardedPort hosts (local).")]
@@ -134,6 +134,7 @@ namespace Renci.SshNet.Tests.SshClientTests
 
 		[TestMethod]
 		[Description("Test passing null to AddForwardedPort hosts (remote).")]
+		[ExpectedException(typeof(ArgumentNullException))]
 		public void Test_AddForwardedPort_Remote_Hosts_Are_Null()
 		{
 			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
@@ -159,6 +160,7 @@ namespace Renci.SshNet.Tests.SshClientTests
 
 		[TestMethod]
 		[Description("Test passing string.Empty to AddForwardedPort host (local).")]
+		[ExpectedException(typeof(ArgumentException))]
 		public void Test_AddForwardedPort_Local_Hosts_Are_Empty()
 		{
 			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
@@ -206,21 +208,21 @@ namespace Renci.SshNet.Tests.SshClientTests
 			var args = new PortForwardEventArgs("string", IPEndPoint.MaxPort + 1);
 		}
 
-        private static byte[] ReadStream(Stream stream)
-        {
-            byte[] buffer = new byte[1024];
-            using (MemoryStream ms = new MemoryStream())
-            {
-                while (true)
-                {
-                    int read = stream.Read(buffer, 0, buffer.Length);
-                    if (read > 0)
-                        ms.Write(buffer, 0, read);
-                    else
-                        return ms.ToArray();
-                }
-            }
-        }
-
-    }
+		private static byte[] ReadStream(Stream stream)
+		{
+			byte[] buffer = new byte[1024];
+			using (MemoryStream ms = new MemoryStream())
+			{
+				while (true)
+				{
+					int read = stream.Read(buffer, 0, buffer.Length);
+					if (read > 0)
+						ms.Write(buffer, 0, read);
+					else
+						return ms.ToArray();
+				}
+			}
+		}
+
+	}
 }

+ 363 - 363
Renci.SshClient/Renci.SshNet.Tests/SshClientTests/TestSshCommand.cs

@@ -10,370 +10,370 @@ using System.IO;
 
 namespace Renci.SshNet.Tests.SshClientTests
 {
-    [TestClass]
-    public class TestSshCommand
-    {
-        [TestMethod]
-        [ExpectedException(typeof(SshConnectionException))]
-        public void Test_Execute_SingleCommand_Without_Connecting()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                var result = ExecuteTestCommand(client);
-
-                Assert.IsTrue(result);
-            }
-        }
-
-        [TestMethod]
-        public void Test_Execute_SingleCommand()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var result = ExecuteTestCommand(client);
-                client.Disconnect();
-
-                Assert.IsTrue(result);
-            }
-        }
-
-        [TestMethod]
-        [ExpectedException(typeof(SshOperationTimeoutException))]
-        public void Test_Execute_Timeout()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var cmd = client.CreateCommand("sleep 10s");
-                cmd.CommandTimeout = TimeSpan.FromSeconds(5);
-                cmd.Execute();
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Execute_Infinite_Timeout()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var cmd = client.CreateCommand("sleep 10s");
-                cmd.Execute();
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_MultipleThread_10000_MultipleSessions()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                System.Threading.Tasks.Parallel.For(0, 10000,
-                    (counter) =>
-                    {
-                        var result = ExecuteTestCommand(client);
-                        Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
-                        Assert.IsTrue(result);
-                    }
-                );
-
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_MultipleThread_10000_MultipleConnections()
-        {
-            try
-            {
-                System.Threading.Tasks.Parallel.For(0, 10000,
-                    () =>
-                    {
-                        var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD);
-                        client.Connect();
-                        return client;
-                    },
-                    (int counter, ParallelLoopState pls, SshClient client) =>
-                    {
-                        var result = ExecuteTestCommand(client);
-                        Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
-                        Assert.IsTrue(result);
-                        return client;
-                    },
-                    (SshClient client) =>
-                    {
-                        client.Disconnect();
-                        client.Dispose();
-                    }
-                );
-            }
-            catch (Exception exp)
-            {
-                Assert.Fail(exp.ToString());
-            }
-        }
-
-        [TestMethod]
-        public void Test_Execute_InvalidCommand()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-
-                var cmd = client.CreateCommand(";");
-                cmd.Execute();
-                if (string.IsNullOrEmpty(cmd.Error))
-                {
-                    Assert.Fail("Operation should fail");
-                }
-                Assert.IsTrue(cmd.ExitStatus > 0);
-
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Execute_InvalidCommand_Then_Execute_ValidCommand()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var cmd = client.CreateCommand(";");
-                cmd.Execute();
-                if (string.IsNullOrEmpty(cmd.Error))
-                {
-                    Assert.Fail("Operation should fail");
-                }
-                Assert.IsTrue(cmd.ExitStatus > 0);
-
-                var result = ExecuteTestCommand(client);
-
-                client.Disconnect();
-
-                Assert.IsTrue(result);
-            }
-        }
-
-        [TestMethod]
-        public void Test_Execute_Command_with_ExtendedOutput()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var cmd = client.CreateCommand("echo 12345; echo 654321 >&2");
-                cmd.Execute();
-                //var extendedData = Encoding.ASCII.GetString(cmd.ExtendedOutputStream.ToArray());
-                var extendedData = new StreamReader(cmd.ExtendedOutputStream, Encoding.ASCII).ReadToEnd();
-                client.Disconnect();
-
-                Assert.AreEqual("12345\n", cmd.Result);
-                Assert.AreEqual("654321\n", extendedData);
-            }
-        }
-
-        [TestMethod]
-        public void Test_Execute_Command_Reconnect_Execute_Command()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var result = ExecuteTestCommand(client);
-                Assert.IsTrue(result);
-
-                client.Disconnect();
-                client.Connect();
-                result = ExecuteTestCommand(client);
-                Assert.IsTrue(result);
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Execute_Command_ExitStatus()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                
-                var cmd = client.RunCommand("exit 128");
-                Assert.IsTrue(cmd.ExitStatus == 128);
-
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Execute_Command_Asynchronously()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-
-                var cmd = client.CreateCommand("sleep 5s; echo 'test'");
-                var asyncResult = cmd.BeginExecute(null, null);
-                while (!asyncResult.IsCompleted)
-                {
-                    Thread.Sleep(100);
-                }
-
-                cmd.EndExecute(asyncResult);
-
-                Assert.IsTrue(cmd.Result == "test\n");
-
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Execute_Command_Asynchronously_With_Error()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-
-                var cmd = client.CreateCommand("sleep 5s; ;");
-                var asyncResult = cmd.BeginExecute(null, null);
-                while (!asyncResult.IsCompleted)
-                {
-                    Thread.Sleep(100);
-                }
-
-                cmd.EndExecute(asyncResult);
-
-                Assert.IsFalse(string.IsNullOrEmpty(cmd.Error));
-
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Execute_Command_Asynchronously_With_Callback()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-
-
-                var callbackCalled = false;
-
-                var cmd = client.CreateCommand("sleep 5s; echo 'test'");
-                var asyncResult = cmd.BeginExecute(new AsyncCallback((s) =>
-                {
-                    callbackCalled = true;
-                }), null);
-                while (!asyncResult.IsCompleted)
-                {
-                    Thread.Sleep(100);
-                }
-
-                cmd.EndExecute(asyncResult);
-
-                Assert.IsTrue(callbackCalled);
-
-
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Execute_Command_Asynchronously_With_Callback_On_Different_Thread()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-
-                var currentThreadId = Thread.CurrentThread.ManagedThreadId;
-                int callbackThreadId = 0;
-
-                var cmd = client.CreateCommand("sleep 5s; echo 'test'");
-                var asyncResult = cmd.BeginExecute(new AsyncCallback((s) =>
-                {
-                    callbackThreadId = Thread.CurrentThread.ManagedThreadId;
-                }), null);
-                while (!asyncResult.IsCompleted)
-                {
-                    Thread.Sleep(100);
-                }
-
-                cmd.EndExecute(asyncResult);
-
-                Assert.AreNotEqual(currentThreadId, callbackThreadId);
-
-                client.Disconnect();
-            }
-        }
-
-        /// <summary>
-        /// Tests for Issue 563.
-        /// </summary>
-        [WorkItem(563), TestMethod]
-        public void Test_Execute_Command_Same_Object_Different_Commands()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var cmd = client.CreateCommand("echo 12345");
-                cmd.Execute();
-                Assert.AreEqual("12345\n", cmd.Result);
-                cmd.Execute("echo 23456");
-                Assert.AreEqual("23456\n", cmd.Result);
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Get_Result_Without_Execution()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var cmd = client.CreateCommand("ls -l");
-
-                Assert.IsTrue(string.IsNullOrEmpty(cmd.Result));
-                client.Disconnect();
-            }
-        }
-
-        [TestMethod]
-        public void Test_Get_Error_Without_Execution()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var cmd = client.CreateCommand("ls -l");
-
-                Assert.IsTrue(string.IsNullOrEmpty(cmd.Error));
-                client.Disconnect();
-            }
-        }
+	[TestClass]
+	public class TestSshCommand
+	{
+		[TestMethod]
+		[ExpectedException(typeof(SshConnectionException))]
+		public void Test_Execute_SingleCommand_Without_Connecting()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				var result = ExecuteTestCommand(client);
+
+				Assert.IsTrue(result);
+			}
+		}
+
+		[TestMethod]
+		public void Test_Execute_SingleCommand()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var result = ExecuteTestCommand(client);
+				client.Disconnect();
+
+				Assert.IsTrue(result);
+			}
+		}
+
+		[TestMethod]
+		[ExpectedException(typeof(SshOperationTimeoutException))]
+		public void Test_Execute_Timeout()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var cmd = client.CreateCommand("sleep 10s");
+				cmd.CommandTimeout = TimeSpan.FromSeconds(5);
+				cmd.Execute();
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Execute_Infinite_Timeout()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var cmd = client.CreateCommand("sleep 10s");
+				cmd.Execute();
+				client.Disconnect();
+			}
+		}
+
+		//[TestMethod]
+		public void Test_MultipleThread_10000_MultipleSessions()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				System.Threading.Tasks.Parallel.For(0, 10000,
+					(counter) =>
+					{
+						var result = ExecuteTestCommand(client);
+						Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
+						Assert.IsTrue(result);
+					}
+				);
+
+				client.Disconnect();
+			}
+		}
+
+		//[TestMethod]
+		public void Test_MultipleThread_10000_MultipleConnections()
+		{
+			try
+			{
+				System.Threading.Tasks.Parallel.For(0, 10000,
+					() =>
+					{
+						var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD);
+						client.Connect();
+						return client;
+					},
+					(int counter, ParallelLoopState pls, SshClient client) =>
+					{
+						var result = ExecuteTestCommand(client);
+						Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter));
+						Assert.IsTrue(result);
+						return client;
+					},
+					(SshClient client) =>
+					{
+						client.Disconnect();
+						client.Dispose();
+					}
+				);
+			}
+			catch (Exception exp)
+			{
+				Assert.Fail(exp.ToString());
+			}
+		}
+
+		[TestMethod]
+		public void Test_Execute_InvalidCommand()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+
+				var cmd = client.CreateCommand(";");
+				cmd.Execute();
+				if (string.IsNullOrEmpty(cmd.Error))
+				{
+					Assert.Fail("Operation should fail");
+				}
+				Assert.IsTrue(cmd.ExitStatus > 0);
+
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Execute_InvalidCommand_Then_Execute_ValidCommand()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var cmd = client.CreateCommand(";");
+				cmd.Execute();
+				if (string.IsNullOrEmpty(cmd.Error))
+				{
+					Assert.Fail("Operation should fail");
+				}
+				Assert.IsTrue(cmd.ExitStatus > 0);
+
+				var result = ExecuteTestCommand(client);
+
+				client.Disconnect();
+
+				Assert.IsTrue(result);
+			}
+		}
+
+		[TestMethod]
+		public void Test_Execute_Command_with_ExtendedOutput()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var cmd = client.CreateCommand("echo 12345; echo 654321 >&2");
+				cmd.Execute();
+				//var extendedData = Encoding.ASCII.GetString(cmd.ExtendedOutputStream.ToArray());
+				var extendedData = new StreamReader(cmd.ExtendedOutputStream, Encoding.ASCII).ReadToEnd();
+				client.Disconnect();
+
+				Assert.AreEqual("12345\n", cmd.Result);
+				Assert.AreEqual("654321\n", extendedData);
+			}
+		}
+
+		[TestMethod]
+		public void Test_Execute_Command_Reconnect_Execute_Command()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var result = ExecuteTestCommand(client);
+				Assert.IsTrue(result);
+
+				client.Disconnect();
+				client.Connect();
+				result = ExecuteTestCommand(client);
+				Assert.IsTrue(result);
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Execute_Command_ExitStatus()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				
+				var cmd = client.RunCommand("exit 128");
+				Assert.IsTrue(cmd.ExitStatus == 128);
+
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Execute_Command_Asynchronously()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+
+				var cmd = client.CreateCommand("sleep 5s; echo 'test'");
+				var asyncResult = cmd.BeginExecute(null, null);
+				while (!asyncResult.IsCompleted)
+				{
+					Thread.Sleep(100);
+				}
+
+				cmd.EndExecute(asyncResult);
+
+				Assert.IsTrue(cmd.Result == "test\n");
+
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Execute_Command_Asynchronously_With_Error()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+
+				var cmd = client.CreateCommand("sleep 5s; ;");
+				var asyncResult = cmd.BeginExecute(null, null);
+				while (!asyncResult.IsCompleted)
+				{
+					Thread.Sleep(100);
+				}
+
+				cmd.EndExecute(asyncResult);
+
+				Assert.IsFalse(string.IsNullOrEmpty(cmd.Error));
+
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Execute_Command_Asynchronously_With_Callback()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+
+
+				var callbackCalled = false;
+
+				var cmd = client.CreateCommand("sleep 5s; echo 'test'");
+				var asyncResult = cmd.BeginExecute(new AsyncCallback((s) =>
+				{
+					callbackCalled = true;
+				}), null);
+				while (!asyncResult.IsCompleted)
+				{
+					Thread.Sleep(100);
+				}
+
+				cmd.EndExecute(asyncResult);
+
+				Assert.IsTrue(callbackCalled);
+
+
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Execute_Command_Asynchronously_With_Callback_On_Different_Thread()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+
+				var currentThreadId = Thread.CurrentThread.ManagedThreadId;
+				int callbackThreadId = 0;
+
+				var cmd = client.CreateCommand("sleep 5s; echo 'test'");
+				var asyncResult = cmd.BeginExecute(new AsyncCallback((s) =>
+				{
+					callbackThreadId = Thread.CurrentThread.ManagedThreadId;
+				}), null);
+				while (!asyncResult.IsCompleted)
+				{
+					Thread.Sleep(100);
+				}
+
+				cmd.EndExecute(asyncResult);
+
+				Assert.AreNotEqual(currentThreadId, callbackThreadId);
+
+				client.Disconnect();
+			}
+		}
+
+		/// <summary>
+		/// Tests for Issue 563.
+		/// </summary>
+		[WorkItem(563), TestMethod]
+		public void Test_Execute_Command_Same_Object_Different_Commands()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var cmd = client.CreateCommand("echo 12345");
+				cmd.Execute();
+				Assert.AreEqual("12345\n", cmd.Result);
+				cmd.Execute("echo 23456");
+				Assert.AreEqual("23456\n", cmd.Result);
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Get_Result_Without_Execution()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var cmd = client.CreateCommand("ls -l");
+
+				Assert.IsTrue(string.IsNullOrEmpty(cmd.Result));
+				client.Disconnect();
+			}
+		}
+
+		[TestMethod]
+		public void Test_Get_Error_Without_Execution()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var cmd = client.CreateCommand("ls -l");
+
+				Assert.IsTrue(string.IsNullOrEmpty(cmd.Error));
+				client.Disconnect();
+			}
+		}
 
 
 		[WorkItem(703), TestMethod]
-        [ExpectedException(typeof(ArgumentException))]
-        public void Test_EndExecute_Before_BeginExecute()
-        {
-            using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
-            {
-                client.Connect();
-                var cmd = client.CreateCommand("ls -l");
-                cmd.EndExecute(null);
-                client.Disconnect();
-            }
-        }
-
-
-
-        private static bool ExecuteTestCommand(SshClient s)
-        {
-            var testValue = Guid.NewGuid().ToString();
-            var command = string.Format("echo {0}", testValue);
-            var cmd = s.CreateCommand(command);
-            var result = cmd.Execute();
-            result = result.Substring(0, result.Length - 1);    //  Remove \n character returned by command
-            return result.Equals(testValue);
-        }
-
-    }
+		[ExpectedException(typeof(ArgumentException))]
+		public void Test_EndExecute_Before_BeginExecute()
+		{
+			using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
+			{
+				client.Connect();
+				var cmd = client.CreateCommand("ls -l");
+				cmd.EndExecute(null);
+				client.Disconnect();
+			}
+		}
+
+
+
+		private static bool ExecuteTestCommand(SshClient s)
+		{
+			var testValue = Guid.NewGuid().ToString();
+			var command = string.Format("echo {0}", testValue);
+			var cmd = s.CreateCommand(command);
+			var result = cmd.Execute();
+			result = result.Substring(0, result.Length - 1);    //  Remove \n character returned by command
+			return result.Equals(testValue);
+		}
+
+	}
 }

+ 40 - 8
Renci.SshClient/Renci.SshNet/Common/Extensions.cs

@@ -4,6 +4,8 @@ using System.Diagnostics;
 using System.Linq;
 using System;
 using System.Globalization;
+using System.Text.RegularExpressions;
+using System.Net;
 
 namespace Renci.SshNet
 {
@@ -19,7 +21,7 @@ namespace Renci.SshNet
         /// <param name="compareList">The collection to compare with</param>
         /// <param name="comparer">The comparer object to use to compare each item in the collection.  If null uses EqualityComparer(T).Default</param>
         /// <returns>True if the two collections contain all the same items in the same order</returns>
-        public static bool IsEqualTo<TSource>(this IEnumerable<TSource> value, IEnumerable<TSource> compareList, IEqualityComparer<TSource> comparer)
+        internal static bool IsEqualTo<TSource>(this IEnumerable<TSource> value, IEnumerable<TSource> compareList, IEqualityComparer<TSource> comparer)
         {
             if (value == compareList)
             {
@@ -71,7 +73,7 @@ namespace Renci.SshNet
         /// <param name="value">The current instance object</param>
         /// <param name="compareList">The collection to compare with</param>
         /// <returns>True if the two collections contain all the same items in the same order</returns>
-        public static bool IsEqualTo<TSource>(this IEnumerable<TSource> value, IEnumerable<TSource> compareList)
+        internal static bool IsEqualTo<TSource>(this IEnumerable<TSource> value, IEnumerable<TSource> compareList)
         {
             return IsEqualTo(value, compareList, null);
         }
@@ -80,7 +82,7 @@ namespace Renci.SshNet
         /// Prints out 
         /// </summary>
         /// <param name="bytes">The bytes.</param>
-        public static void DebugPrint(this IEnumerable<byte> bytes)
+        internal static void DebugPrint(this IEnumerable<byte> bytes)
         {
             foreach (var b in bytes)
             {
@@ -94,7 +96,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="data">The data.</param>
         /// <returns></returns>
-        public static IEnumerable<byte> TrimLeadingZero(this IEnumerable<byte> data)
+        internal static IEnumerable<byte> TrimLeadingZero(this IEnumerable<byte> data)
         {
             bool leadingZero = true;
             foreach (var item in data)
@@ -130,7 +132,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="value">The number to convert.</param>
         /// <returns>An array of bytes with length 2.</returns>
-        public static byte[] GetBytes(this UInt16 value)
+        internal static byte[] GetBytes(this UInt16 value)
         {
             return new byte[] { (byte)(value >> 8), (byte)(value & 0xFF) };
         }
@@ -140,7 +142,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="value">The number to convert.</param>
         /// <returns>An array of bytes with length 4.</returns>
-        public static byte[] GetBytes(this UInt32 value)
+        internal static byte[] GetBytes(this UInt32 value)
         {
             return new byte[] { (byte)(value >> 24), (byte)(value >> 16), (byte)(value >> 8), (byte)(value & 0xFF) };
         }
@@ -150,7 +152,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="value">The number to convert.</param>
         /// <returns>An array of bytes with length 8.</returns>
-        public static byte[] GetBytes(this UInt64 value)
+        internal static byte[] GetBytes(this UInt64 value)
         {
             return new byte[] { (byte)(value >> 56), (byte)(value >> 48), (byte)(value >> 40), (byte)(value >> 32), (byte)(value >> 24), (byte)(value >> 16), (byte)(value >> 8), (byte)(value & 0xFF) };
         }
@@ -160,9 +162,39 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="value">The number to convert.</param>
         /// <returns>An array of bytes with length 8.</returns>
-        public static byte[] GetBytes(this Int64 value)
+        internal static byte[] GetBytes(this Int64 value)
         {
             return new byte[] { (byte)(value >> 56), (byte)(value >> 48), (byte)(value >> 40), (byte)(value >> 32), (byte)(value >> 24), (byte)(value >> 16), (byte)(value >> 8), (byte)(value & 0xFF) };
         }
+
+        private static Regex _rehost = new Regex(@"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
+
+        internal static bool IsValidHost(this string value)
+        {
+            if (value == null)
+                return false;
+
+            return _rehost.Match(value).Success;
+        }
+
+        internal static bool IsValidPort(this uint value)
+        {
+            if (value < IPEndPoint.MinPort)
+                return false;
+
+            if (value > IPEndPoint.MaxPort)
+                return false;
+            return true;
+        }
+
+        internal static bool IsValidPort(this int value)
+        {
+            if (value < IPEndPoint.MinPort)
+                return false;
+
+            if (value > IPEndPoint.MaxPort)
+                return false;
+            return true;
+        }
     }
 }

+ 9 - 3
Renci.SshClient/Renci.SshNet/Common/PortForwardEventArgs.cs

@@ -1,7 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
 
 namespace Renci.SshNet.Common
 {
@@ -27,6 +24,15 @@ namespace Renci.SshNet.Common
         /// <param name="port">The port.</param>
         public PortForwardEventArgs(string host, uint port)
         {
+            if (host == null)
+                throw new ArgumentNullException("host");
+
+            if (!host.IsValidHost())
+                throw new ArgumentException("host");
+
+            if (!port.IsValidPort())
+                throw new ArgumentOutOfRangeException("port");
+
             this.OriginatorHost = host;
             this.OriginatorPort = port;
         }

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

@@ -202,14 +202,14 @@ namespace Renci.SshNet
         protected ConnectionInfo(string host, int port, string username)
             : this()
         {
-            if (string.IsNullOrEmpty(host))
-                throw new ArgumentNullException("host");
+            if (!host.IsValidHost())
+                throw new ArgumentException("host");
 
-            if (port < IPEndPoint.MinPort)
+            if (!port.IsValidPort())
                 throw new ArgumentOutOfRangeException("port");
 
-            if (port > IPEndPoint.MaxPort)
-                throw new ArgumentOutOfRangeException("port");
+            if (string.IsNullOrWhiteSpace(username))
+                throw new ArgumentException("username");
 
             this.Host = host;
             this.Port = port;

+ 3 - 0
Renci.SshClient/Renci.SshNet/PasswordConnectionInfo.cs

@@ -61,6 +61,9 @@ namespace Renci.SshNet
         public PasswordConnectionInfo(string host, int port, string username, string password)
             : base(host, port, username)
         {
+            if (password == null)
+                throw new ArgumentNullException("password");
+
             this._password = password;
             this._requestMessage = new RequestMessagePassword(ServiceName.Connection, this.Username, password);
         }

+ 45 - 0
Renci.SshClient/Renci.SshNet/SftpClient.cs

@@ -113,6 +113,9 @@ namespace Renci.SshNet
         /// <param name="path">New directory path.</param>
         public void ChangeDirectory(string path)
         {
+            if (path == null)
+                throw new ArgumentNullException("path");
+
             //  Ensure that connection is established.
             this.EnsureConnection();
 
@@ -126,6 +129,9 @@ namespace Renci.SshNet
         /// <param name="mode">The mode.</param>
         public void ChangePermissions(string path, ushort mode)
         {
+            if (path == null)
+                throw new ArgumentNullException("path");
+
             //  Ensure that connection is established.
             this.EnsureConnection();
 
@@ -142,6 +148,9 @@ namespace Renci.SshNet
         /// <exception cref="Renci.SshNet.Common.SshException"></exception>
         public void CreateDirectory(string path)
         {
+            if (string.IsNullOrWhiteSpace(path))
+                throw new ArgumentException(path);
+
             //  Ensure that connection is established.
             this.EnsureConnection();
 
@@ -160,6 +169,9 @@ namespace Renci.SshNet
         /// <param name="path">Directory to be deleted path.</param>
         public void DeleteDirectory(string path)
         {
+            if (string.IsNullOrWhiteSpace(path))
+                throw new ArgumentException("path");
+
             //  Ensure that connection is established.
             this.EnsureConnection();
 
@@ -179,6 +191,9 @@ namespace Renci.SshNet
         /// <param name="path">File to be deleted path.</param>
         public void DeleteFile(string path)
         {
+            if (string.IsNullOrWhiteSpace(path))
+                throw new ArgumentException("path");
+
             //  Ensure that connection is established.
             this.EnsureConnection();
 
@@ -199,6 +214,12 @@ namespace Renci.SshNet
         /// <param name="newPath">Path to the new file location.</param>
         public void RenameFile(string oldPath, string newPath)
         {
+            if (oldPath == null)
+                throw new ArgumentNullException("oldPath");
+
+            if (newPath == null)
+                throw new ArgumentNullException("newPath");
+            
             //  Ensure that connection is established.
             this.EnsureConnection();
 
@@ -221,6 +242,12 @@ namespace Renci.SshNet
         /// <param name="linkPath">The new path.</param>
         public void SymbolicLink(string path, string linkPath)
         {
+            if (string.IsNullOrWhiteSpace(path))
+                throw new ArgumentException("path");
+
+            if (string.IsNullOrWhiteSpace(linkPath))
+                throw new ArgumentException("linkPath");
+
             //  Ensure that connection is established.
             this.EnsureConnection();
 
@@ -255,6 +282,9 @@ namespace Renci.SshNet
         /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
         public IAsyncResult BeginListDirectory(string path, AsyncCallback asyncCallback, object state)
         {
+            if (path == null)
+                throw new ArgumentNullException("path");
+
             //  Ensure that connection is established.
             this.EnsureConnection();
 
@@ -299,6 +329,9 @@ namespace Renci.SshNet
         /// <returns></returns>
         public SftpFile Get(string path)
         {
+            if (path == null)
+                throw new ArgumentNullException("path");
+
             //  Ensure that connection is established.
             this.EnsureConnection();
 
@@ -333,6 +366,12 @@ namespace Renci.SshNet
         /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
         public IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback asyncCallback, object state)
         {
+            if (string.IsNullOrWhiteSpace(path))
+                throw new ArgumentException("path");
+
+            if (output == null)
+                throw new ArgumentNullException("output");
+
             //  Ensure that connection is established.
             this.EnsureConnection();
 
@@ -386,6 +425,12 @@ namespace Renci.SshNet
         /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
         public IAsyncResult BeginUploadFile(Stream input, string path, AsyncCallback asyncCallback, object state)
         {
+            if (input == null)
+                throw new ArgumentNullException("input");
+
+            if (string.IsNullOrWhiteSpace(path))
+                throw new ArgumentException("path");
+
             //  Ensure that connection is established.
             this.EnsureConnection();
 

+ 18 - 0
Renci.SshClient/Renci.SshNet/SshClient.cs

@@ -112,6 +112,24 @@ namespace Renci.SshNet
         /// </returns>
         public T AddForwardedPort<T>(string boundHost, uint boundPort, string connectedHost, uint connectedPort) where T : ForwardedPort, new()
         {
+            if (boundHost == null)
+                throw new ArgumentNullException("boundHost");
+
+            if (connectedHost == null)
+                throw new ArgumentNullException("connectedHost");
+
+            if (!boundHost.IsValidHost())
+                throw new ArgumentException("boundHost");
+
+            if (!boundPort.IsValidPort())
+                throw new ArgumentOutOfRangeException("boundPort");
+
+            if (!connectedHost.IsValidHost())
+                throw new ArgumentException("connectedHost");
+
+            if (!connectedPort.IsValidPort())
+                throw new ArgumentOutOfRangeException("connectedPort");
+
             //  Ensure that connection is established.
             this.EnsureConnection();