diff --git a/src/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs b/src/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs index 6634c0ef..6ea7a33f 100644 --- a/src/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs +++ b/src/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs @@ -1,106 +1,106 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; -using System; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides functionality to perform private key authentication. - /// - [TestClass] - public class PrivateKeyAuthenticationMethodTest : TestBase - { - [TestMethod] - [TestCategory("AuthenticationMethod")] - [TestCategory("PrivateKeyAuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("PrivateKeyAuthenticationMethod: Pass null as username, null as password.")] - [ExpectedException(typeof(ArgumentException))] - public void PrivateKey_Test_Pass_Null() - { - new PrivateKeyAuthenticationMethod(null, null); - } - - [TestMethod] - [TestCategory("AuthenticationMethod")] - [TestCategory("PrivateKeyAuthenticationMethod")] - [Owner("olegkap")] - [Description("PrivateKeyAuthenticationMethod: Pass valid username, null as password.")] - [ExpectedException(typeof(ArgumentNullException))] - public void PrivateKey_Test_Pass_PrivateKey_Null() - { - new PrivateKeyAuthenticationMethod("username", null); - } - - [TestMethod] - [TestCategory("AuthenticationMethod")] - [TestCategory("PrivateKeyAuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("PrivateKeyAuthenticationMethod: Pass String.Empty as username, null as password.")] - [ExpectedException(typeof(ArgumentException))] - public void PrivateKey_Test_Pass_Whitespace() - { - new PrivateKeyAuthenticationMethod(string.Empty, null); - } - - /// - ///A test for Name - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NameTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Authenticate - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AuthenticateTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value - Session session = null; // TODO: Initialize to an appropriate value - AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value - AuthenticationResult actual; - actual = target.Authenticate(session); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for PrivateKeyAuthenticationMethod Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyAuthenticationMethodConstructorTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; +using System; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides functionality to perform private key authentication. + /// + [TestClass] + public class PrivateKeyAuthenticationMethodTest : TestBase + { + [TestMethod] + [TestCategory("AuthenticationMethod")] + [TestCategory("PrivateKeyAuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("PrivateKeyAuthenticationMethod: Pass null as username, null as password.")] + [ExpectedException(typeof(ArgumentException))] + public void PrivateKey_Test_Pass_Null() + { + new PrivateKeyAuthenticationMethod(null, null); + } + + [TestMethod] + [TestCategory("AuthenticationMethod")] + [TestCategory("PrivateKeyAuthenticationMethod")] + [Owner("olegkap")] + [Description("PrivateKeyAuthenticationMethod: Pass valid username, null as password.")] + [ExpectedException(typeof(ArgumentNullException))] + public void PrivateKey_Test_Pass_PrivateKey_Null() + { + new PrivateKeyAuthenticationMethod("username", null); + } + + [TestMethod] + [TestCategory("AuthenticationMethod")] + [TestCategory("PrivateKeyAuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("PrivateKeyAuthenticationMethod: Pass String.Empty as username, null as password.")] + [ExpectedException(typeof(ArgumentException))] + public void PrivateKey_Test_Pass_Whitespace() + { + new PrivateKeyAuthenticationMethod(string.Empty, null); + } + + /// + ///A test for Name + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NameTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value + string actual; + actual = target.Name; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Authenticate + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AuthenticateTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value + Session session = null; // TODO: Initialize to an appropriate value + AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value + AuthenticationResult actual; + actual = target.Authenticate(session); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for PrivateKeyAuthenticationMethod Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyAuthenticationMethodConstructorTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/PrivateKeyConnectionInfoTest.cs b/src/Renci.SshNet.Tests/Classes/PrivateKeyConnectionInfoTest.cs index cee67e17..f8c863ba 100644 --- a/src/Renci.SshNet.Tests/Classes/PrivateKeyConnectionInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/PrivateKeyConnectionInfoTest.cs @@ -1,217 +1,217 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.IO; -using System.Text; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides connection information when private key authentication method is used - /// - [TestClass] - public class PrivateKeyConnectionInfoTest : TestBase - { - [TestMethod] - [TestCategory("PrivateKeyConnectionInfo")] - [TestCategory("integration")] - public void Test_PrivateKeyConnectionInfo() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); - - #region Example PrivateKeyConnectionInfo PrivateKeyFile - var connectionInfo = new PrivateKeyConnectionInfo(host, username, new PrivateKeyFile(keyFileStream)); - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - #endregion - - Assert.AreEqual(connectionInfo.Host, Resources.HOST); - Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); - } - - [TestMethod] - [TestCategory("PrivateKeyConnectionInfo")] - [TestCategory("integration")] - public void Test_PrivateKeyConnectionInfo_MultiplePrivateKey() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - MemoryStream keyFileStream1 = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); - MemoryStream keyFileStream2 = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); - - #region Example PrivateKeyConnectionInfo PrivateKeyFile Multiple - var connectionInfo = new PrivateKeyConnectionInfo(host, username, - new PrivateKeyFile(keyFileStream1), - new PrivateKeyFile(keyFileStream2)); - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - #endregion - - Assert.AreEqual(connectionInfo.Host, Resources.HOST); - Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, keyFiles); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest1() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest2() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest3() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest4() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest5() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest6() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest7() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.IO; +using System.Text; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides connection information when private key authentication method is used + /// + [TestClass] + public class PrivateKeyConnectionInfoTest : TestBase + { + [TestMethod] + [TestCategory("PrivateKeyConnectionInfo")] + [TestCategory("integration")] + public void Test_PrivateKeyConnectionInfo() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); + + #region Example PrivateKeyConnectionInfo PrivateKeyFile + var connectionInfo = new PrivateKeyConnectionInfo(host, username, new PrivateKeyFile(keyFileStream)); + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + #endregion + + Assert.AreEqual(connectionInfo.Host, Resources.HOST); + Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); + } + + [TestMethod] + [TestCategory("PrivateKeyConnectionInfo")] + [TestCategory("integration")] + public void Test_PrivateKeyConnectionInfo_MultiplePrivateKey() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + MemoryStream keyFileStream1 = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); + MemoryStream keyFileStream2 = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); + + #region Example PrivateKeyConnectionInfo PrivateKeyFile Multiple + var connectionInfo = new PrivateKeyConnectionInfo(host, username, + new PrivateKeyFile(keyFileStream1), + new PrivateKeyFile(keyFileStream2)); + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + #endregion + + Assert.AreEqual(connectionInfo.Host, Resources.HOST); + Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, keyFiles); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest1() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest2() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest3() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest4() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest5() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest6() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest7() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs b/src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs index 8c979848..77efff4a 100644 --- a/src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs +++ b/src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs @@ -1,504 +1,504 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using System; -using System.IO; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// old private key information/ - /// - [TestClass] - public class PrivateKeyFileTest : TestBase - { - private string _temporaryFile; - - [TestInitialize] - public void SetUp() - { - _temporaryFile = GetTempFileName(); - } - - [TestCleanup] - public void TearDown() - { - if (_temporaryFile != null) - File.Delete(_temporaryFile); - } - - /// - /// A test for ctor. - /// - [WorkItem(703), TestMethod] - public void ConstructorWithFileNameShouldThrowArgumentNullExceptionWhenFileNameIsEmpty() - { - var fileName = string.Empty; - try - { - new PrivateKeyFile(fileName); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("fileName", ex.ParamName); - } - } - - /// - /// A test for ctor. - /// - [WorkItem(703), TestMethod] - public void ConstructorWithFileNameShouldThrowArgumentNullExceptionWhenFileNameIsNull() - { - var fileName = string.Empty; - try - { - new PrivateKeyFile(fileName); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("fileName", ex.ParamName); - } - } - - /// - /// A test for ctor. - /// - [WorkItem(703), TestMethod] - public void ConstructorWithFileNameAndPassphraseShouldThrowArgumentNullExceptionWhenFileNameIsEmpty() - { - var fileName = string.Empty; - try - { - new PrivateKeyFile(fileName, "12345"); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("fileName", ex.ParamName); - } - } - - /// - /// A test for ctor. - /// - [WorkItem(703), TestMethod] - public void ConstructorWithFileNameAndPassphraseShouldThrowArgumentNullExceptionWhenFileNameIsNull() - { - var fileName = string.Empty; - try - { - new PrivateKeyFile(fileName, "12345"); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("fileName", ex.ParamName); - } - } - - [WorkItem(703), TestMethod] - public void ConstructorWithPrivateKeyShouldThrowArgumentNullExceptionWhenPrivateKeyIsNull() - { - Stream privateKey = null; - try - { - new PrivateKeyFile(privateKey); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("privateKey", ex.ParamName); - } - } - - [WorkItem(703), TestMethod] - public void ConstructorWithPrivateKeyAndPassphraseShouldThrowArgumentNullExceptionWhenPrivateKeyIsNull() - { - Stream privateKey = null; - try - { - new PrivateKeyFile(privateKey, "12345"); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("privateKey", ex.ParamName); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA() - { - using (var stream = this.GetData("Key.RSA.txt")) - { - new PrivateKeyFile(stream); - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_DSA() - { - using (var stream = this.GetData("Key.SSH2.DSA.txt")) - { - new PrivateKeyFile(stream); - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_RSA() - { - using (var stream = this.GetData("Key.SSH2.RSA.txt")) - { - new PrivateKeyFile(stream); - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_Encrypted_DSA_DES_CBC() - { - using (var stream = this.GetData("Key.SSH2.DSA.Encrypted.Des.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_Encrypted_RSA_DES_CBC() - { - using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshExceptionWhenPassphraseIsWrong() - { - using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) - { - try - { - new PrivateKeyFile(stream, "34567"); - Assert.Fail(); - } - catch (SshException ex) - { - Assert.IsInstanceOfType(ex, typeof(SshException)); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Invalid passphrase.", ex.Message); - } - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsNull() - { - using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) - { - try - { - new PrivateKeyFile(stream, null); - Assert.Fail(); - } - catch (SshPassPhraseNullOrEmptyException ex) - { - Assert.IsInstanceOfType(ex, typeof(SshPassPhraseNullOrEmptyException)); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); - } - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsEmpty() - { - using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) - { - try - { - new PrivateKeyFile(stream, string.Empty); - Assert.Fail(); - } - catch (SshPassPhraseNullOrEmptyException ex) - { - Assert.IsInstanceOfType(ex, typeof(SshPassPhraseNullOrEmptyException)); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); - } - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_DES_CBC() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Des.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_DES_EDE3_CBC() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_AES_128_CBC() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_AES_192_CBC() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Aes.192.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_AES_256_CBC() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Aes.256.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_DES_EDE3_CFB() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt")) - { - new PrivateKeyFile(stream, "1234567890"); - } - } - - /// - ///A test for Dispose - /// - [TestMethod()] - public void DisposeTest() - { - using (var privateKeyStream = GetData("Key.RSA.txt")) - { - var target = new PrivateKeyFile(privateKeyStream); - target.Dispose(); - } - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithStreamAndPassphrase() - { - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - var privateKeyFile = new PrivateKeyFile(stream, "12345"); - Assert.IsNotNull(privateKeyFile.HostKey); - } - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithFileNameAndPassphrase() - { - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); - Assert.IsNotNull(privateKeyFile.HostKey); - - fs.Close(); - } - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithFileNameAndPassphraseShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPrivateKeyIsEncryptedAndPassphraseIsEmpty() - { - var passphrase = string.Empty; - - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - try - { - new PrivateKeyFile(_temporaryFile, passphrase); - Assert.Fail(); - } - catch (SshPassPhraseNullOrEmptyException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); - } - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithFileNameAndPassphraseShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPrivateKeyIsEncryptedAndPassphraseIsNull() - { - string passphrase = null; - - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - try - { - new PrivateKeyFile(_temporaryFile, passphrase); - Assert.Fail(); - } - catch (SshPassPhraseNullOrEmptyException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); - } - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithFileName() - { - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); - Assert.IsNotNull(privateKeyFile.HostKey); - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithStream() - { - using (var stream = GetData("Key.RSA.txt")) - { - var privateKeyFile = new PrivateKeyFile(stream); - Assert.IsNotNull(privateKeyFile.HostKey); - } - } - - [TestMethod] - [TestCategory("PrivateKey")] - public void ConstructorWithFileNameShouldBeAbleToReadFileThatIsSharedForReadAccess() - { - using (var stream = GetData("Key.RSA.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - var privateKeyFile = new PrivateKeyFile(_temporaryFile); - Assert.IsNotNull(privateKeyFile.HostKey); - - fs.Close(); - } - } - - [TestMethod] - [TestCategory("PrivateKey")] - public void ConstructorWithFileNameAndPassPhraseShouldBeAbleToReadFileThatIsSharedForReadAccess() - { - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); - Assert.IsNotNull(privateKeyFile.HostKey); - - fs.Close(); - } - } - - private void SaveStreamToFile(Stream stream, string fileName) - { - var buffer = new byte[4000]; - - using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) - { - var bytesRead = stream.Read(buffer, 0, buffer.Length); - while (bytesRead > 0) - { - fs.Write(buffer, 0, bytesRead); - bytesRead = stream.Read(buffer, 0, buffer.Length); - } - } - } - - private string GetTempFileName() - { - var tempFile = Path.GetTempFileName(); - File.Delete(tempFile); - return tempFile; - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using System; +using System.IO; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// old private key information/ + /// + [TestClass] + public class PrivateKeyFileTest : TestBase + { + private string _temporaryFile; + + [TestInitialize] + public void SetUp() + { + _temporaryFile = GetTempFileName(); + } + + [TestCleanup] + public void TearDown() + { + if (_temporaryFile != null) + File.Delete(_temporaryFile); + } + + /// + /// A test for ctor. + /// + [WorkItem(703), TestMethod] + public void ConstructorWithFileNameShouldThrowArgumentNullExceptionWhenFileNameIsEmpty() + { + var fileName = string.Empty; + try + { + new PrivateKeyFile(fileName); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("fileName", ex.ParamName); + } + } + + /// + /// A test for ctor. + /// + [WorkItem(703), TestMethod] + public void ConstructorWithFileNameShouldThrowArgumentNullExceptionWhenFileNameIsNull() + { + var fileName = string.Empty; + try + { + new PrivateKeyFile(fileName); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("fileName", ex.ParamName); + } + } + + /// + /// A test for ctor. + /// + [WorkItem(703), TestMethod] + public void ConstructorWithFileNameAndPassphraseShouldThrowArgumentNullExceptionWhenFileNameIsEmpty() + { + var fileName = string.Empty; + try + { + new PrivateKeyFile(fileName, "12345"); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("fileName", ex.ParamName); + } + } + + /// + /// A test for ctor. + /// + [WorkItem(703), TestMethod] + public void ConstructorWithFileNameAndPassphraseShouldThrowArgumentNullExceptionWhenFileNameIsNull() + { + var fileName = string.Empty; + try + { + new PrivateKeyFile(fileName, "12345"); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("fileName", ex.ParamName); + } + } + + [WorkItem(703), TestMethod] + public void ConstructorWithPrivateKeyShouldThrowArgumentNullExceptionWhenPrivateKeyIsNull() + { + Stream privateKey = null; + try + { + new PrivateKeyFile(privateKey); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("privateKey", ex.ParamName); + } + } + + [WorkItem(703), TestMethod] + public void ConstructorWithPrivateKeyAndPassphraseShouldThrowArgumentNullExceptionWhenPrivateKeyIsNull() + { + Stream privateKey = null; + try + { + new PrivateKeyFile(privateKey, "12345"); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("privateKey", ex.ParamName); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA() + { + using (var stream = this.GetData("Key.RSA.txt")) + { + new PrivateKeyFile(stream); + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_DSA() + { + using (var stream = this.GetData("Key.SSH2.DSA.txt")) + { + new PrivateKeyFile(stream); + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_RSA() + { + using (var stream = this.GetData("Key.SSH2.RSA.txt")) + { + new PrivateKeyFile(stream); + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_Encrypted_DSA_DES_CBC() + { + using (var stream = this.GetData("Key.SSH2.DSA.Encrypted.Des.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_Encrypted_RSA_DES_CBC() + { + using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshExceptionWhenPassphraseIsWrong() + { + using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) + { + try + { + new PrivateKeyFile(stream, "34567"); + Assert.Fail(); + } + catch (SshException ex) + { + Assert.IsInstanceOfType(ex, typeof(SshException)); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Invalid passphrase.", ex.Message); + } + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsNull() + { + using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) + { + try + { + new PrivateKeyFile(stream, null); + Assert.Fail(); + } + catch (SshPassPhraseNullOrEmptyException ex) + { + Assert.IsInstanceOfType(ex, typeof(SshPassPhraseNullOrEmptyException)); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); + } + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsEmpty() + { + using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) + { + try + { + new PrivateKeyFile(stream, string.Empty); + Assert.Fail(); + } + catch (SshPassPhraseNullOrEmptyException ex) + { + Assert.IsInstanceOfType(ex, typeof(SshPassPhraseNullOrEmptyException)); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); + } + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_DES_CBC() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Des.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_DES_EDE3_CBC() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_AES_128_CBC() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_AES_192_CBC() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Aes.192.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_AES_256_CBC() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Aes.256.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_DES_EDE3_CFB() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt")) + { + new PrivateKeyFile(stream, "1234567890"); + } + } + + /// + ///A test for Dispose + /// + [TestMethod()] + public void DisposeTest() + { + using (var privateKeyStream = GetData("Key.RSA.txt")) + { + var target = new PrivateKeyFile(privateKeyStream); + target.Dispose(); + } + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithStreamAndPassphrase() + { + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + var privateKeyFile = new PrivateKeyFile(stream, "12345"); + Assert.IsNotNull(privateKeyFile.HostKey); + } + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithFileNameAndPassphrase() + { + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); + Assert.IsNotNull(privateKeyFile.HostKey); + + fs.Close(); + } + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithFileNameAndPassphraseShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPrivateKeyIsEncryptedAndPassphraseIsEmpty() + { + var passphrase = string.Empty; + + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + try + { + new PrivateKeyFile(_temporaryFile, passphrase); + Assert.Fail(); + } + catch (SshPassPhraseNullOrEmptyException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); + } + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithFileNameAndPassphraseShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPrivateKeyIsEncryptedAndPassphraseIsNull() + { + string passphrase = null; + + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + try + { + new PrivateKeyFile(_temporaryFile, passphrase); + Assert.Fail(); + } + catch (SshPassPhraseNullOrEmptyException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); + } + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithFileName() + { + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); + Assert.IsNotNull(privateKeyFile.HostKey); + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithStream() + { + using (var stream = GetData("Key.RSA.txt")) + { + var privateKeyFile = new PrivateKeyFile(stream); + Assert.IsNotNull(privateKeyFile.HostKey); + } + } + + [TestMethod] + [TestCategory("PrivateKey")] + public void ConstructorWithFileNameShouldBeAbleToReadFileThatIsSharedForReadAccess() + { + using (var stream = GetData("Key.RSA.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + var privateKeyFile = new PrivateKeyFile(_temporaryFile); + Assert.IsNotNull(privateKeyFile.HostKey); + + fs.Close(); + } + } + + [TestMethod] + [TestCategory("PrivateKey")] + public void ConstructorWithFileNameAndPassPhraseShouldBeAbleToReadFileThatIsSharedForReadAccess() + { + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); + Assert.IsNotNull(privateKeyFile.HostKey); + + fs.Close(); + } + } + + private void SaveStreamToFile(Stream stream, string fileName) + { + var buffer = new byte[4000]; + + using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) + { + var bytesRead = stream.Read(buffer, 0, buffer.Length); + while (bytesRead > 0) + { + fs.Write(buffer, 0, bytesRead); + bytesRead = stream.Read(buffer, 0, buffer.Length); + } + } + } + + private string GetTempFileName() + { + var tempFile = Path.GetTempFileName(); + File.Delete(tempFile); + return tempFile; + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/AlgorithmTest.cs b/src/Renci.SshNet.Tests/Classes/Security/AlgorithmTest.cs index 26c9c134..00c9d5d2 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/AlgorithmTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/AlgorithmTest.cs @@ -1,34 +1,34 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for AlgorithmTest and is intended - ///to contain all AlgorithmTest Unit Tests - /// - [TestClass()] - public class AlgorithmTest : TestBase - { - internal virtual Algorithm CreateAlgorithm() - { - // TODO: Instantiate an appropriate concrete class. - Algorithm target = null; - return target; - } - - /// - ///A test for Name - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NameTest() - { - Algorithm target = CreateAlgorithm(); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for AlgorithmTest and is intended + ///to contain all AlgorithmTest Unit Tests + /// + [TestClass()] + public class AlgorithmTest : TestBase + { + internal virtual Algorithm CreateAlgorithm() + { + // TODO: Instantiate an appropriate concrete class. + Algorithm target = null; + return target; + } + + /// + ///A test for Name + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NameTest() + { + Algorithm target = CreateAlgorithm(); // TODO: Initialize to an appropriate value + string actual; + actual = target.Name; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/CertificateHostAlgorithmTest.cs b/src/Renci.SshNet.Tests/Classes/Security/CertificateHostAlgorithmTest.cs index 049a31ff..813fec59 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/CertificateHostAlgorithmTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/CertificateHostAlgorithmTest.cs @@ -1,74 +1,74 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for CertificateHostAlgorithmTest and is intended - ///to contain all CertificateHostAlgorithmTest Unit Tests - /// - [TestClass()] - public class CertificateHostAlgorithmTest : TestBase - { - /// - ///A test for CertificateHostAlgorithm Constructor - /// - [TestMethod] - public void CertificateHostAlgorithmConstructorTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for VerifySignature - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifySignatureTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.VerifySignature(data, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Data - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DataTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Data; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for CertificateHostAlgorithmTest and is intended + ///to contain all CertificateHostAlgorithmTest Unit Tests + /// + [TestClass()] + public class CertificateHostAlgorithmTest : TestBase + { + /// + ///A test for CertificateHostAlgorithm Constructor + /// + [TestMethod] + public void CertificateHostAlgorithmConstructorTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for VerifySignature + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifySignatureTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.VerifySignature(data, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Data + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DataTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Data; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/BlockCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/BlockCipherTest.cs index 6442b4ea..49546d61 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/BlockCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/BlockCipherTest.cs @@ -1,77 +1,77 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - [TestClass] - public class BlockCipherTest : TestBase - { - [TestMethod] - public void EncryptShouldTakeIntoAccountPaddingForLengthOfOutputBufferPassedToEncryptBlock() - { - var input = new byte[] { 0x2c, 0x1a, 0x05, 0x00, 0x68 }; - var output = new byte[] { 0x0a, 0x00, 0x03, 0x02, 0x06, 0x08, 0x07, 0x05 }; - var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; - var blockCipher = new BlockCipherStub(key, 8, null, new PKCS5Padding()) - { - EncryptBlockDelegate = (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset) => - { - Assert.AreEqual(8, outputBuffer.Length); - Buffer.BlockCopy(output, 0, outputBuffer, 0, output.Length); - return inputBuffer.Length; - } - }; - - var actual = blockCipher.Encrypt(input); - - Assert.IsTrue(output.SequenceEqual(actual)); - } - - [TestMethod] - public void DecryptShouldTakeIntoAccountPaddingForLengthOfOutputBufferPassedToDecryptBlock() - { - var input = new byte[] { 0x2c, 0x1a, 0x05, 0x00, 0x68 }; - var output = new byte[] { 0x0a, 0x00, 0x03, 0x02, 0x06, 0x08, 0x07, 0x05 }; - var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; - var blockCipher = new BlockCipherStub(key, 8, null, new PKCS5Padding()) - { - DecryptBlockDelegate = (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset) => - { - Assert.AreEqual(8, outputBuffer.Length); - Buffer.BlockCopy(output, 0, outputBuffer, 0, output.Length); - return inputBuffer.Length; - } - }; - - var actual = blockCipher.Decrypt(input); - - Assert.IsTrue(output.SequenceEqual(actual)); - } - - - private class BlockCipherStub : BlockCipher - { - public Func EncryptBlockDelegate; - public Func DecryptBlockDelegate; - - public BlockCipherStub(byte[] key, byte blockSize, CipherMode mode, CipherPadding padding) : base(key, blockSize, mode, padding) - { - } - - public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) - { - return EncryptBlockDelegate(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - } - - public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) - { - return DecryptBlockDelegate(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - } - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + [TestClass] + public class BlockCipherTest : TestBase + { + [TestMethod] + public void EncryptShouldTakeIntoAccountPaddingForLengthOfOutputBufferPassedToEncryptBlock() + { + var input = new byte[] { 0x2c, 0x1a, 0x05, 0x00, 0x68 }; + var output = new byte[] { 0x0a, 0x00, 0x03, 0x02, 0x06, 0x08, 0x07, 0x05 }; + var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; + var blockCipher = new BlockCipherStub(key, 8, null, new PKCS5Padding()) + { + EncryptBlockDelegate = (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset) => + { + Assert.AreEqual(8, outputBuffer.Length); + Buffer.BlockCopy(output, 0, outputBuffer, 0, output.Length); + return inputBuffer.Length; + } + }; + + var actual = blockCipher.Encrypt(input); + + Assert.IsTrue(output.SequenceEqual(actual)); + } + + [TestMethod] + public void DecryptShouldTakeIntoAccountPaddingForLengthOfOutputBufferPassedToDecryptBlock() + { + var input = new byte[] { 0x2c, 0x1a, 0x05, 0x00, 0x68 }; + var output = new byte[] { 0x0a, 0x00, 0x03, 0x02, 0x06, 0x08, 0x07, 0x05 }; + var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; + var blockCipher = new BlockCipherStub(key, 8, null, new PKCS5Padding()) + { + DecryptBlockDelegate = (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset) => + { + Assert.AreEqual(8, outputBuffer.Length); + Buffer.BlockCopy(output, 0, outputBuffer, 0, output.Length); + return inputBuffer.Length; + } + }; + + var actual = blockCipher.Decrypt(input); + + Assert.IsTrue(output.SequenceEqual(actual)); + } + + + private class BlockCipherStub : BlockCipher + { + public Func EncryptBlockDelegate; + public Func DecryptBlockDelegate; + + public BlockCipherStub(byte[] key, byte blockSize, CipherMode mode, CipherPadding padding) : base(key, blockSize, mode, padding) + { + } + + public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) + { + return EncryptBlockDelegate(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + } + + public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) + { + return DecryptBlockDelegate(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherDigitalSignatureTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherDigitalSignatureTest.cs index cbc5a65a..2bdce8e1 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherDigitalSignatureTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherDigitalSignatureTest.cs @@ -1,54 +1,54 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - ///This is a test class for CipherDigitalSignatureTest and is intended - ///to contain all CipherDigitalSignatureTest Unit Tests - /// - [TestClass()] - public class CipherDigitalSignatureTest : TestBase - { - internal virtual CipherDigitalSignature CreateCipherDigitalSignature() - { - // TODO: Instantiate an appropriate concrete class. - CipherDigitalSignature target = null; - return target; - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - CipherDigitalSignature target = CreateCipherDigitalSignature(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Verify - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifyTest() - { - CipherDigitalSignature target = CreateCipherDigitalSignature(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.Verify(input, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + ///This is a test class for CipherDigitalSignatureTest and is intended + ///to contain all CipherDigitalSignatureTest Unit Tests + /// + [TestClass()] + public class CipherDigitalSignatureTest : TestBase + { + internal virtual CipherDigitalSignature CreateCipherDigitalSignature() + { + // TODO: Instantiate an appropriate concrete class. + CipherDigitalSignature target = null; + return target; + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + CipherDigitalSignature target = CreateCipherDigitalSignature(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Verify + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifyTest() + { + CipherDigitalSignature target = CreateCipherDigitalSignature(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.Verify(input, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherTest.cs index c5f4a2b5..8af4f653 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherTest.cs @@ -1,53 +1,53 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - ///This is a test class for CipherTest and is intended - ///to contain all CipherTest Unit Tests - /// - [TestClass()] - public class CipherTest : TestBase - { - internal virtual Cipher CreateCipher() - { - // TODO: Instantiate an appropriate concrete class. - Cipher target = null; - return target; - } - - /// - ///A test for Decrypt - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptTest() - { - Cipher target = CreateCipher(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Decrypt(input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Encrypt - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptTest() - { - Cipher target = CreateCipher(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Encrypt(input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + ///This is a test class for CipherTest and is intended + ///to contain all CipherTest Unit Tests + /// + [TestClass()] + public class CipherTest : TestBase + { + internal virtual Cipher CreateCipher() + { + // TODO: Instantiate an appropriate concrete class. + Cipher target = null; + return target; + } + + /// + ///A test for Decrypt + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptTest() + { + Cipher target = CreateCipher(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Decrypt(input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Encrypt + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptTest() + { + Cipher target = CreateCipher(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Encrypt(input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs index 5d16c7b9..deeb0cb5 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs @@ -1,239 +1,239 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.Linq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// - /// - [TestClass] - public class AesCipherTest : TestBase - { - [TestMethod] - public void Test_Cipher_AES_128_CBC() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; - var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; - var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; - var output = new byte[] { 0x19, 0x7f, 0x80, 0xd8, 0xc9, 0x89, 0xc4, 0xa7, 0xc6, 0xc6, 0x3f, 0x9f, 0x1e, 0x00, 0x1f, 0x72, 0xa7, 0x5e, 0xde, 0x40, 0x88, 0xa2, 0x72, 0xf2, 0xed, 0x3f, 0x81, 0x45, 0xb6, 0xbd, 0x45, 0x87, 0x15, 0xa5, 0x10, 0x92, 0x4a, 0x37, 0x9e, 0xa9, 0x80, 0x1c, 0x14, 0x83, 0xa3, 0x39, 0x45, 0x28 }; - var testCipher = new AesCipher(key, new CbcCipherMode(iv), null); - var r = testCipher.Encrypt(input); - - if (!r.SequenceEqual(output)) - Assert.Fail("Invalid encryption"); - } - - [TestMethod] - public void Test_Cipher_AES_128_CTR() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0xb0, 0x74, 0x21, 0x87, 0x16, 0xb9, 0x69, 0x48, 0x33, 0xce, 0xb3, 0xe7, 0xdc, 0x3f, 0x50, 0xdc, 0xcc, 0xd5, 0x27, 0xb7, 0xfe, 0x7a, 0x78, 0x22, 0xae, 0xc8 }; - var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; - var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 }; - var expected = new byte[] { 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d }; - var testCipher = new AesCipher(key, new CtrCipherMode(iv), null); - - var actual = testCipher.Encrypt(input); - - Assert.IsTrue(actual.IsEqualTo(expected)); - } - - [TestMethod] - public void Decrypt_AES_128_CTR() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0xb0, 0x74, 0x21, 0x87, 0x16, 0xb9, 0x69, 0x48, 0x33, 0xce, 0xb3, 0xe7, 0xdc, 0x3f, 0x50, 0xdc, 0xcc, 0xd5, 0x27, 0xb7, 0xfe, 0x7a, 0x78, 0x22, 0xae, 0xc8 }; - var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; - var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 }; - var output = new byte[] { 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d }; - var testCipher = new AesCipher(key, new CtrCipherMode(iv), null); - - var actual = testCipher.Decrypt(output); - - Assert.IsTrue(input.IsEqualTo(actual)); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_AEes128CBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes128-cbc", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Aes192CBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes192-cbc", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Aes256CBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes256-cbc", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Aes128CTR_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes128-ctr", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Aes192CTR_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes192-ctr", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Aes256CTR_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes256-ctr", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Arcfour_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("arcfour", new CipherInfo(128, (key, iv) => { return new Arc4Cipher(key, false); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - AesCipher target = new AesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for AesCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AesCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - AesCipher target = new AesCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - AesCipher target = new AesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.Linq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// + /// + [TestClass] + public class AesCipherTest : TestBase + { + [TestMethod] + public void Test_Cipher_AES_128_CBC() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; + var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; + var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; + var output = new byte[] { 0x19, 0x7f, 0x80, 0xd8, 0xc9, 0x89, 0xc4, 0xa7, 0xc6, 0xc6, 0x3f, 0x9f, 0x1e, 0x00, 0x1f, 0x72, 0xa7, 0x5e, 0xde, 0x40, 0x88, 0xa2, 0x72, 0xf2, 0xed, 0x3f, 0x81, 0x45, 0xb6, 0xbd, 0x45, 0x87, 0x15, 0xa5, 0x10, 0x92, 0x4a, 0x37, 0x9e, 0xa9, 0x80, 0x1c, 0x14, 0x83, 0xa3, 0x39, 0x45, 0x28 }; + var testCipher = new AesCipher(key, new CbcCipherMode(iv), null); + var r = testCipher.Encrypt(input); + + if (!r.SequenceEqual(output)) + Assert.Fail("Invalid encryption"); + } + + [TestMethod] + public void Test_Cipher_AES_128_CTR() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0xb0, 0x74, 0x21, 0x87, 0x16, 0xb9, 0x69, 0x48, 0x33, 0xce, 0xb3, 0xe7, 0xdc, 0x3f, 0x50, 0xdc, 0xcc, 0xd5, 0x27, 0xb7, 0xfe, 0x7a, 0x78, 0x22, 0xae, 0xc8 }; + var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; + var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 }; + var expected = new byte[] { 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d }; + var testCipher = new AesCipher(key, new CtrCipherMode(iv), null); + + var actual = testCipher.Encrypt(input); + + Assert.IsTrue(actual.IsEqualTo(expected)); + } + + [TestMethod] + public void Decrypt_AES_128_CTR() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0xb0, 0x74, 0x21, 0x87, 0x16, 0xb9, 0x69, 0x48, 0x33, 0xce, 0xb3, 0xe7, 0xdc, 0x3f, 0x50, 0xdc, 0xcc, 0xd5, 0x27, 0xb7, 0xfe, 0x7a, 0x78, 0x22, 0xae, 0xc8 }; + var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; + var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 }; + var output = new byte[] { 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d }; + var testCipher = new AesCipher(key, new CtrCipherMode(iv), null); + + var actual = testCipher.Decrypt(output); + + Assert.IsTrue(input.IsEqualTo(actual)); + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_AEes128CBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes128-cbc", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Aes192CBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes192-cbc", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Aes256CBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes256-cbc", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Aes128CTR_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes128-ctr", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Aes192CTR_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes192-ctr", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Aes256CTR_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes256-ctr", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Arcfour_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("arcfour", new CipherInfo(128, (key, iv) => { return new Arc4Cipher(key, false); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + AesCipher target = new AesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for AesCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AesCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + AesCipher target = new AesCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + AesCipher target = new AesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs index addbfbf5..1bdcf837 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs @@ -1,177 +1,177 @@ -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements ARCH4 cipher algorithm - /// - [TestClass] - public class Arc4CipherTest : TestBase - { - /// - ///A test for Arc4Cipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void Arc4CipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - Arc4Cipher target = new Arc4Cipher(key, true); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - [TestMethod] - public void Decrypt_DischargeFirstBytes_False1() - { - const string key = "Key"; - const string expectedPlainText = "Plaintext"; - var encoding = Encoding.ASCII; - var cipher = new Arc4Cipher(encoding.GetBytes(key), false); - var cipherText = new byte[] { 0xBB, 0xF3, 0x16, 0xE8, 0xD9, 0x40, 0xAF, 0x0A, 0xD3 }; - - var actualPlainText = cipher.Decrypt(cipherText); - - Assert.AreEqual(expectedPlainText, encoding.GetString(actualPlainText)); - } - - [TestMethod] - public void Decrypt_DischargeFirstBytes_False2() - { - const string key = "Wiki"; - const string expectedPlainText = "pedia"; - var encoding = Encoding.ASCII; - var cipher = new Arc4Cipher(encoding.GetBytes(key), false); - var cipherText = new byte[] { 0x10, 0X21, 0xBF, 0x04, 0x20 }; - - var actualPlainText = cipher.Decrypt(cipherText); - - Assert.AreEqual(expectedPlainText, encoding.GetString(actualPlainText)); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - Arc4Cipher target = new Arc4Cipher(key, true); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - [TestMethod] - public void Encrypt_DischargeFirstBytes_False1() - { - const string key = "Key"; - const string plainText = "Plaintext"; - var encoding = Encoding.ASCII; - var cipher = new Arc4Cipher(encoding.GetBytes(key), false); - var expectedCipherText = new byte[] { 0xBB, 0xF3, 0x16, 0xE8, 0xD9, 0x40, 0xAF, 0x0A, 0xD3 }; - - var actualCipherText = cipher.Encrypt(encoding.GetBytes(plainText)); - - Assert.IsNotNull(actualCipherText); - Assert.AreEqual(expectedCipherText.Length, actualCipherText.Length); - Assert.AreEqual(expectedCipherText[0], actualCipherText[0]); - Assert.AreEqual(expectedCipherText[1], actualCipherText[1]); - Assert.AreEqual(expectedCipherText[2], actualCipherText[2]); - Assert.AreEqual(expectedCipherText[3], actualCipherText[3]); - Assert.AreEqual(expectedCipherText[4], actualCipherText[4]); - Assert.AreEqual(expectedCipherText[5], actualCipherText[5]); - Assert.AreEqual(expectedCipherText[6], actualCipherText[6]); - Assert.AreEqual(expectedCipherText[7], actualCipherText[7]); - Assert.AreEqual(expectedCipherText[8], actualCipherText[8]); - } - - [TestMethod] - public void Encrypt_DischargeFirstBytes_False2() - { - const string key = "Wiki"; - const string plainText = "pedia"; - var encoding = Encoding.ASCII; - var cipher = new Arc4Cipher(encoding.GetBytes(key), false); - var expectedCipherText = new byte[] { 0x10, 0X21, 0xBF, 0x04, 0x20 }; - - var actualCipherText = cipher.Encrypt(encoding.GetBytes(plainText)); - - Assert.IsNotNull(actualCipherText); - Assert.AreEqual(expectedCipherText.Length, actualCipherText.Length); - Assert.AreEqual(expectedCipherText[0], actualCipherText[0]); - Assert.AreEqual(expectedCipherText[1], actualCipherText[1]); - Assert.AreEqual(expectedCipherText[2], actualCipherText[2]); - Assert.AreEqual(expectedCipherText[3], actualCipherText[3]); - Assert.AreEqual(expectedCipherText[4], actualCipherText[4]); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - Arc4Cipher target = new Arc4Cipher(key, true); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Arcfour128_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("arcfour128", new CipherInfo(128, (key, iv) => { return new Arc4Cipher(key, true); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Arcfour256_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("arcfour256", new CipherInfo(256, (key, iv) => { return new Arc4Cipher(key, true); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - } +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements ARCH4 cipher algorithm + /// + [TestClass] + public class Arc4CipherTest : TestBase + { + /// + ///A test for Arc4Cipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void Arc4CipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + Arc4Cipher target = new Arc4Cipher(key, true); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + [TestMethod] + public void Decrypt_DischargeFirstBytes_False1() + { + const string key = "Key"; + const string expectedPlainText = "Plaintext"; + var encoding = Encoding.ASCII; + var cipher = new Arc4Cipher(encoding.GetBytes(key), false); + var cipherText = new byte[] { 0xBB, 0xF3, 0x16, 0xE8, 0xD9, 0x40, 0xAF, 0x0A, 0xD3 }; + + var actualPlainText = cipher.Decrypt(cipherText); + + Assert.AreEqual(expectedPlainText, encoding.GetString(actualPlainText)); + } + + [TestMethod] + public void Decrypt_DischargeFirstBytes_False2() + { + const string key = "Wiki"; + const string expectedPlainText = "pedia"; + var encoding = Encoding.ASCII; + var cipher = new Arc4Cipher(encoding.GetBytes(key), false); + var cipherText = new byte[] { 0x10, 0X21, 0xBF, 0x04, 0x20 }; + + var actualPlainText = cipher.Decrypt(cipherText); + + Assert.AreEqual(expectedPlainText, encoding.GetString(actualPlainText)); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + Arc4Cipher target = new Arc4Cipher(key, true); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + [TestMethod] + public void Encrypt_DischargeFirstBytes_False1() + { + const string key = "Key"; + const string plainText = "Plaintext"; + var encoding = Encoding.ASCII; + var cipher = new Arc4Cipher(encoding.GetBytes(key), false); + var expectedCipherText = new byte[] { 0xBB, 0xF3, 0x16, 0xE8, 0xD9, 0x40, 0xAF, 0x0A, 0xD3 }; + + var actualCipherText = cipher.Encrypt(encoding.GetBytes(plainText)); + + Assert.IsNotNull(actualCipherText); + Assert.AreEqual(expectedCipherText.Length, actualCipherText.Length); + Assert.AreEqual(expectedCipherText[0], actualCipherText[0]); + Assert.AreEqual(expectedCipherText[1], actualCipherText[1]); + Assert.AreEqual(expectedCipherText[2], actualCipherText[2]); + Assert.AreEqual(expectedCipherText[3], actualCipherText[3]); + Assert.AreEqual(expectedCipherText[4], actualCipherText[4]); + Assert.AreEqual(expectedCipherText[5], actualCipherText[5]); + Assert.AreEqual(expectedCipherText[6], actualCipherText[6]); + Assert.AreEqual(expectedCipherText[7], actualCipherText[7]); + Assert.AreEqual(expectedCipherText[8], actualCipherText[8]); + } + + [TestMethod] + public void Encrypt_DischargeFirstBytes_False2() + { + const string key = "Wiki"; + const string plainText = "pedia"; + var encoding = Encoding.ASCII; + var cipher = new Arc4Cipher(encoding.GetBytes(key), false); + var expectedCipherText = new byte[] { 0x10, 0X21, 0xBF, 0x04, 0x20 }; + + var actualCipherText = cipher.Encrypt(encoding.GetBytes(plainText)); + + Assert.IsNotNull(actualCipherText); + Assert.AreEqual(expectedCipherText.Length, actualCipherText.Length); + Assert.AreEqual(expectedCipherText[0], actualCipherText[0]); + Assert.AreEqual(expectedCipherText[1], actualCipherText[1]); + Assert.AreEqual(expectedCipherText[2], actualCipherText[2]); + Assert.AreEqual(expectedCipherText[3], actualCipherText[3]); + Assert.AreEqual(expectedCipherText[4], actualCipherText[4]); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + Arc4Cipher target = new Arc4Cipher(key, true); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Arcfour128_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("arcfour128", new CipherInfo(128, (key, iv) => { return new Arc4Cipher(key, true); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Arcfour256_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("arcfour256", new CipherInfo(256, (key, iv) => { return new Arc4Cipher(key, true); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/BlowfishCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/BlowfishCipherTest.cs index 780a697b..1fd7b7d1 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/BlowfishCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/BlowfishCipherTest.cs @@ -1,108 +1,108 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.Linq; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// - /// - [TestClass] - public class BlowfishCipherTest : TestBase - { - [TestMethod] - public void Test_Cipher_Blowfish_128_CBC() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; - var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; - var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; - var output = new byte[] { 0x50, 0x49, 0xe0, 0xce, 0x98, 0x93, 0x8b, 0xec, 0x82, 0x7d, 0x14, 0x1b, 0x3e, 0xdc, 0xca, 0x63, 0xef, 0x36, 0x20, 0x67, 0x58, 0x63, 0x1f, 0x9c, 0xd2, 0x12, 0x6b, 0xca, 0xea, 0xd0, 0x78, 0x8b, 0x61, 0x50, 0x4f, 0xc4, 0x5b, 0x32, 0x91, 0xd6, 0x65, 0xcb, 0x74, 0xe5, 0x6e, 0xf5, 0xde, 0x14 }; - var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.BlowfishCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); - var r = testCipher.Encrypt(input); - - if (!r.SequenceEqual(output)) - Assert.Fail("Invalid encryption"); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_BlowfishCBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("blowfish-cbc", new CipherInfo(128, (key, iv) => { return new BlowfishCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - /// - ///A test for BlowfishCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BlowfishCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - BlowfishCipher target = new BlowfishCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - BlowfishCipher target = new BlowfishCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - BlowfishCipher target = new BlowfishCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.Linq; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// + /// + [TestClass] + public class BlowfishCipherTest : TestBase + { + [TestMethod] + public void Test_Cipher_Blowfish_128_CBC() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; + var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; + var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; + var output = new byte[] { 0x50, 0x49, 0xe0, 0xce, 0x98, 0x93, 0x8b, 0xec, 0x82, 0x7d, 0x14, 0x1b, 0x3e, 0xdc, 0xca, 0x63, 0xef, 0x36, 0x20, 0x67, 0x58, 0x63, 0x1f, 0x9c, 0xd2, 0x12, 0x6b, 0xca, 0xea, 0xd0, 0x78, 0x8b, 0x61, 0x50, 0x4f, 0xc4, 0x5b, 0x32, 0x91, 0xd6, 0x65, 0xcb, 0x74, 0xe5, 0x6e, 0xf5, 0xde, 0x14 }; + var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.BlowfishCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); + var r = testCipher.Encrypt(input); + + if (!r.SequenceEqual(output)) + Assert.Fail("Invalid encryption"); + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_BlowfishCBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("blowfish-cbc", new CipherInfo(128, (key, iv) => { return new BlowfishCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + /// + ///A test for BlowfishCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BlowfishCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + BlowfishCipher target = new BlowfishCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + BlowfishCipher target = new BlowfishCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + BlowfishCipher target = new BlowfishCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CastCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CastCipherTest.cs index f0cc6313..d65d9673 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CastCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CastCipherTest.cs @@ -1,106 +1,106 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.Linq; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements CAST cipher algorithm - /// - [TestClass] - public class CastCipherTest : TestBase - { - [TestMethod] - public void Test_Cipher_CastCipher_128_CBC() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; - var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; - var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; - var output = new byte[] { 0x32, 0xef, 0xbd, 0xac, 0xb6, 0xfd, 0x1f, 0xae, 0x1b, 0x13, 0x5f, 0x31, 0x6d, 0x38, 0xcd, 0xb0, 0xe3, 0xca, 0xe1, 0xbc, 0xf8, 0xa7, 0xc2, 0x31, 0x62, 0x14, 0x3a, 0x9a, 0xda, 0xe3, 0xf8, 0xc8, 0x70, 0x87, 0x53, 0x21, 0x5d, 0xb7, 0x94, 0xb7, 0xe8, 0xc6, 0x9d, 0x46, 0x0c, 0x6d, 0x64, 0x6d }; - var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.CastCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); - var r = testCipher.Encrypt(input); - - if (!r.SequenceEqual(output)) - Assert.Fail("Invalid encryption"); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Cast128CBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("cast128-cbc", new CipherInfo(128, (key, iv) => { return new CastCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - /// - ///A test for CastCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CastCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - CastCipher target = new CastCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - CastCipher target = new CastCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - CastCipher target = new CastCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.Linq; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements CAST cipher algorithm + /// + [TestClass] + public class CastCipherTest : TestBase + { + [TestMethod] + public void Test_Cipher_CastCipher_128_CBC() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; + var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; + var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; + var output = new byte[] { 0x32, 0xef, 0xbd, 0xac, 0xb6, 0xfd, 0x1f, 0xae, 0x1b, 0x13, 0x5f, 0x31, 0x6d, 0x38, 0xcd, 0xb0, 0xe3, 0xca, 0xe1, 0xbc, 0xf8, 0xa7, 0xc2, 0x31, 0x62, 0x14, 0x3a, 0x9a, 0xda, 0xe3, 0xf8, 0xc8, 0x70, 0x87, 0x53, 0x21, 0x5d, 0xb7, 0x94, 0xb7, 0xe8, 0xc6, 0x9d, 0x46, 0x0c, 0x6d, 0x64, 0x6d }; + var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.CastCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); + var r = testCipher.Encrypt(input); + + if (!r.SequenceEqual(output)) + Assert.Fail("Invalid encryption"); + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Cast128CBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("cast128-cbc", new CipherInfo(128, (key, iv) => { return new CastCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + /// + ///A test for CastCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CastCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + CastCipher target = new CastCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + CastCipher target = new CastCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + CastCipher target = new CastCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherModeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherModeTest.cs index 23a0ff0c..d3b4c0ad 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherModeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherModeTest.cs @@ -1,61 +1,61 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - ///This is a test class for CipherModeTest and is intended - ///to contain all CipherModeTest Unit Tests - /// - [TestClass()] - public class CipherModeTest : TestBase - { - internal virtual CipherMode CreateCipherMode() - { - // TODO: Instantiate an appropriate concrete class. - CipherMode target = null; - return target; - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - CipherMode target = CreateCipherMode(); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - CipherMode target = CreateCipherMode(); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + ///This is a test class for CipherModeTest and is intended + ///to contain all CipherModeTest Unit Tests + /// + [TestClass()] + public class CipherModeTest : TestBase + { + internal virtual CipherMode CreateCipherMode() + { + // TODO: Instantiate an appropriate concrete class. + CipherMode target = null; + return target; + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + CipherMode target = CreateCipherMode(); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + CipherMode target = CreateCipherMode(); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherPaddingTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherPaddingTest.cs index de720376..c923584a 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherPaddingTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherPaddingTest.cs @@ -1,38 +1,38 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - ///This is a test class for CipherPaddingTest and is intended - ///to contain all CipherPaddingTest Unit Tests - /// - [TestClass()] - public class CipherPaddingTest : TestBase - { - internal virtual CipherPadding CreateCipherPadding() - { - // TODO: Instantiate an appropriate concrete class. - CipherPadding target = null; - return target; - } - - /// - ///A test for Pad - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PadTest() - { - CipherPadding target = CreateCipherPadding(); // TODO: Initialize to an appropriate value - int blockSize = 0; // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Pad(blockSize, input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + ///This is a test class for CipherPaddingTest and is intended + ///to contain all CipherPaddingTest Unit Tests + /// + [TestClass()] + public class CipherPaddingTest : TestBase + { + internal virtual CipherPadding CreateCipherPadding() + { + // TODO: Instantiate an appropriate concrete class. + CipherPadding target = null; + return target; + } + + /// + ///A test for Pad + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PadTest() + { + CipherPadding target = CreateCipherPadding(); // TODO: Initialize to an appropriate value + int blockSize = 0; // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Pad(blockSize, input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs index 6511d3fc..cff5b9db 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs @@ -1,73 +1,73 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements DES cipher algorithm. - /// - [TestClass] - public class DesCipherTest : TestBase - { - /// - ///A test for DesCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DesCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - DesCipher target = new DesCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - DesCipher target = new DesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - DesCipher target = new DesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements DES cipher algorithm. + /// + [TestClass] + public class DesCipherTest : TestBase + { + /// + ///A test for DesCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DesCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + DesCipher target = new DesCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + DesCipher target = new DesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + DesCipher target = new DesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CbcCipherModeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CbcCipherModeTest.cs index 230dce65..c43191c2 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CbcCipherModeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CbcCipherModeTest.cs @@ -1,67 +1,67 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes -{ - /// - ///This is a test class for CbcCipherModeTest and is intended - ///to contain all CbcCipherModeTest Unit Tests - /// - [TestClass()] - public class CbcCipherModeTest : TestBase - { - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CbcCipherMode target = new CbcCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CbcCipherMode target = new CbcCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CbcCipherMode Constructor - /// - [TestMethod()] - public void CbcCipherModeConstructorTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CbcCipherMode target = new CbcCipherMode(iv); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes +{ + /// + ///This is a test class for CbcCipherModeTest and is intended + ///to contain all CbcCipherModeTest Unit Tests + /// + [TestClass()] + public class CbcCipherModeTest : TestBase + { + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CbcCipherMode target = new CbcCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CbcCipherMode target = new CbcCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CbcCipherMode Constructor + /// + [TestMethod()] + public void CbcCipherModeConstructorTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CbcCipherMode target = new CbcCipherMode(iv); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CfbCipherModeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CfbCipherModeTest.cs index 8a4a2b27..f7dd046d 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CfbCipherModeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CfbCipherModeTest.cs @@ -1,68 +1,68 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes -{ - /// - ///This is a test class for CfbCipherModeTest and is intended - ///to contain all CfbCipherModeTest Unit Tests - /// - [TestClass()] - public class CfbCipherModeTest : TestBase - { - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CfbCipherMode target = new CfbCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CfbCipherMode target = new CfbCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CfbCipherMode Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CfbCipherModeConstructorTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CfbCipherMode target = new CfbCipherMode(iv); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes +{ + /// + ///This is a test class for CfbCipherModeTest and is intended + ///to contain all CfbCipherModeTest Unit Tests + /// + [TestClass()] + public class CfbCipherModeTest : TestBase + { + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CfbCipherMode target = new CfbCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CfbCipherMode target = new CfbCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CfbCipherMode Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CfbCipherModeConstructorTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CfbCipherMode target = new CfbCipherMode(iv); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CtrCipherModeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CtrCipherModeTest.cs index 76e6bae9..23e0391e 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CtrCipherModeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CtrCipherModeTest.cs @@ -1,68 +1,68 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes -{ - /// - ///This is a test class for CtrCipherModeTest and is intended - ///to contain all CtrCipherModeTest Unit Tests - /// - [TestClass()] - public class CtrCipherModeTest : TestBase - { - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CtrCipherMode target = new CtrCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CtrCipherMode target = new CtrCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CtrCipherMode Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CtrCipherModeConstructorTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CtrCipherMode target = new CtrCipherMode(iv); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes +{ + /// + ///This is a test class for CtrCipherModeTest and is intended + ///to contain all CtrCipherModeTest Unit Tests + /// + [TestClass()] + public class CtrCipherModeTest : TestBase + { + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CtrCipherMode target = new CtrCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CtrCipherMode target = new CtrCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CtrCipherMode Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CtrCipherModeConstructorTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CtrCipherMode target = new CtrCipherMode(iv); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/OfbCipherModeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/OfbCipherModeTest.cs index 5444be0d..d4719e25 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/OfbCipherModeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/OfbCipherModeTest.cs @@ -1,68 +1,68 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes -{ - /// - ///This is a test class for OfbCipherModeTest and is intended - ///to contain all OfbCipherModeTest Unit Tests - /// - [TestClass()] - public class OfbCipherModeTest : TestBase - { - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - OfbCipherMode target = new OfbCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - OfbCipherMode target = new OfbCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OfbCipherMode Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OfbCipherModeConstructorTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - OfbCipherMode target = new OfbCipherMode(iv); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes +{ + /// + ///This is a test class for OfbCipherModeTest and is intended + ///to contain all OfbCipherModeTest Unit Tests + /// + [TestClass()] + public class OfbCipherModeTest : TestBase + { + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + OfbCipherMode target = new OfbCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + OfbCipherMode target = new OfbCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OfbCipherMode Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OfbCipherModeConstructorTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + OfbCipherMode target = new OfbCipherMode(iv); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs index 205feb4e..554d4b6a 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs @@ -1,41 +1,41 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings -{ - /// - ///This is a test class for PKCS5PaddingTest and is intended - ///to contain all PKCS5PaddingTest Unit Tests - /// - [TestClass()] - public class PKCS5PaddingTest : TestBase - { - /// - ///A test for Pad - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PadTest() - { - PKCS5Padding target = new PKCS5Padding(); // TODO: Initialize to an appropriate value - int blockSize = 0; // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Pad(blockSize, input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for PKCS5Padding Constructor - /// - [TestMethod()] - public void PKCS5PaddingConstructorTest() - { - PKCS5Padding target = new PKCS5Padding(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings +{ + /// + ///This is a test class for PKCS5PaddingTest and is intended + ///to contain all PKCS5PaddingTest Unit Tests + /// + [TestClass()] + public class PKCS5PaddingTest : TestBase + { + /// + ///A test for Pad + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PadTest() + { + PKCS5Padding target = new PKCS5Padding(); // TODO: Initialize to an appropriate value + int blockSize = 0; // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Pad(blockSize, input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for PKCS5Padding Constructor + /// + [TestMethod()] + public void PKCS5PaddingConstructorTest() + { + PKCS5Padding target = new PKCS5Padding(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs index e20be109..e39ec7a7 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs @@ -1,41 +1,41 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings -{ - /// - ///This is a test class for PKCS7PaddingTest and is intended - ///to contain all PKCS7PaddingTest Unit Tests - /// - [TestClass()] - public class PKCS7PaddingTest : TestBase - { - /// - ///A test for Pad - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PadTest() - { - PKCS7Padding target = new PKCS7Padding(); // TODO: Initialize to an appropriate value - int blockSize = 0; // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Pad(blockSize, input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for PKCS7Padding Constructor - /// - [TestMethod()] - public void PKCS7PaddingConstructorTest() - { - PKCS7Padding target = new PKCS7Padding(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings +{ + /// + ///This is a test class for PKCS7PaddingTest and is intended + ///to contain all PKCS7PaddingTest Unit Tests + /// + [TestClass()] + public class PKCS7PaddingTest : TestBase + { + /// + ///A test for Pad + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PadTest() + { + PKCS7Padding target = new PKCS7Padding(); // TODO: Initialize to an appropriate value + int blockSize = 0; // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Pad(blockSize, input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for PKCS7Padding Constructor + /// + [TestMethod()] + public void PKCS7PaddingConstructorTest() + { + PKCS7Padding target = new PKCS7Padding(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/RsaCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/RsaCipherTest.cs index 423288b2..2de87cdd 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/RsaCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/RsaCipherTest.cs @@ -1,60 +1,60 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements RSA cipher algorithm. - /// - [TestClass] - public class RsaCipherTest : TestBase - { - /// - ///A test for RsaCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RsaCipherConstructorTest() - { - RsaKey key = null; // TODO: Initialize to an appropriate value - RsaCipher target = new RsaCipher(key); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Decrypt - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptTest() - { - RsaKey key = null; // TODO: Initialize to an appropriate value - RsaCipher target = new RsaCipher(key); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Decrypt(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Encrypt - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptTest() - { - RsaKey key = null; // TODO: Initialize to an appropriate value - RsaCipher target = new RsaCipher(key); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Encrypt(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements RSA cipher algorithm. + /// + [TestClass] + public class RsaCipherTest : TestBase + { + /// + ///A test for RsaCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RsaCipherConstructorTest() + { + RsaKey key = null; // TODO: Initialize to an appropriate value + RsaCipher target = new RsaCipher(key); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Decrypt + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptTest() + { + RsaKey key = null; // TODO: Initialize to an appropriate value + RsaCipher target = new RsaCipher(key); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Decrypt(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Encrypt + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptTest() + { + RsaKey key = null; // TODO: Initialize to an appropriate value + RsaCipher target = new RsaCipher(key); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Encrypt(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/SerpentCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/SerpentCipherTest.cs index ac79b452..f604f5dc 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/SerpentCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/SerpentCipherTest.cs @@ -1,73 +1,73 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements Serpent cipher algorithm. - /// - [TestClass] - public class SerpentCipherTest : TestBase - { - /// - ///A test for SerpentCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SerpentCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - SerpentCipher target = new SerpentCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - SerpentCipher target = new SerpentCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - SerpentCipher target = new SerpentCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements Serpent cipher algorithm. + /// + [TestClass] + public class SerpentCipherTest : TestBase + { + /// + ///A test for SerpentCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SerpentCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + SerpentCipher target = new SerpentCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + SerpentCipher target = new SerpentCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + SerpentCipher target = new SerpentCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TripleDesCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TripleDesCipherTest.cs index 9ba70c14..3a410514 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TripleDesCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TripleDesCipherTest.cs @@ -1,106 +1,106 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.Linq; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements 3DES cipher algorithm. - /// - [TestClass] - public class TripleDesCipherTest : TestBase - { - [TestMethod] - public void Test_Cipher_3DES_CBC() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x1c, 0x0a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x72, 0x4e, 0x06, 0x08, 0x28, 0x2d, 0xaa, 0xe2, 0xb3, 0xd9 }; - var key = new byte[] { 0x78, 0xf6, 0xc6, 0xbb, 0x57, 0x03, 0x69, 0xca, 0xba, 0x31, 0x18, 0x2f, 0x2f, 0x4c, 0x35, 0x34, 0x64, 0x06, 0x85, 0x30, 0xbe, 0x78, 0x60, 0xb3 }; - var iv = new byte[] { 0xc0, 0x75, 0xf2, 0x26, 0x0a, 0x2a, 0x42, 0x96 }; - var output = new byte[] { 0x28, 0x77, 0x2f, 0x07, 0x3e, 0xc2, 0x27, 0xa6, 0xdb, 0x36, 0x4d, 0xc6, 0x7a, 0x26, 0x7a, 0x38, 0xe6, 0x54, 0x0b, 0xab, 0x07, 0x87, 0xf0, 0xa4, 0x73, 0x1f, 0xde, 0xe6, 0x81, 0x1d, 0x4b, 0x4b }; - var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.TripleDesCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); - var r = testCipher.Encrypt(input); - - if (!r.SequenceEqual(output)) - Assert.Fail("Invalid encryption"); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_TripleDESCBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("3des-cbc", new CipherInfo(192, (key, iv) => { return new TripleDesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - /// - ///A test for TripleDesCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void TripleDesCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TripleDesCipher target = new TripleDesCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TripleDesCipher target = new TripleDesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TripleDesCipher target = new TripleDesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.Linq; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements 3DES cipher algorithm. + /// + [TestClass] + public class TripleDesCipherTest : TestBase + { + [TestMethod] + public void Test_Cipher_3DES_CBC() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x1c, 0x0a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x72, 0x4e, 0x06, 0x08, 0x28, 0x2d, 0xaa, 0xe2, 0xb3, 0xd9 }; + var key = new byte[] { 0x78, 0xf6, 0xc6, 0xbb, 0x57, 0x03, 0x69, 0xca, 0xba, 0x31, 0x18, 0x2f, 0x2f, 0x4c, 0x35, 0x34, 0x64, 0x06, 0x85, 0x30, 0xbe, 0x78, 0x60, 0xb3 }; + var iv = new byte[] { 0xc0, 0x75, 0xf2, 0x26, 0x0a, 0x2a, 0x42, 0x96 }; + var output = new byte[] { 0x28, 0x77, 0x2f, 0x07, 0x3e, 0xc2, 0x27, 0xa6, 0xdb, 0x36, 0x4d, 0xc6, 0x7a, 0x26, 0x7a, 0x38, 0xe6, 0x54, 0x0b, 0xab, 0x07, 0x87, 0xf0, 0xa4, 0x73, 0x1f, 0xde, 0xe6, 0x81, 0x1d, 0x4b, 0x4b }; + var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.TripleDesCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); + var r = testCipher.Encrypt(input); + + if (!r.SequenceEqual(output)) + Assert.Fail("Invalid encryption"); + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_TripleDESCBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("3des-cbc", new CipherInfo(192, (key, iv) => { return new TripleDesCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + /// + ///A test for TripleDesCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void TripleDesCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TripleDesCipher target = new TripleDesCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TripleDesCipher target = new TripleDesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TripleDesCipher target = new TripleDesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TwofishCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TwofishCipherTest.cs index abb2b35d..e0693e97 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TwofishCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TwofishCipherTest.cs @@ -1,73 +1,73 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements Twofish cipher algorithm - /// - [TestClass] - public class TwofishCipherTest : TestBase - { - /// - ///A test for TwofishCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void TwofishCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TwofishCipher target = new TwofishCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TwofishCipher target = new TwofishCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TwofishCipher target = new TwofishCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements Twofish cipher algorithm + /// + [TestClass] + public class TwofishCipherTest : TestBase + { + /// + ///A test for TwofishCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void TwofishCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TwofishCipher target = new TwofishCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TwofishCipher target = new TwofishCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TwofishCipher target = new TwofishCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DigitalSignatureTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DigitalSignatureTest.cs index a8733300..efe45c9c 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DigitalSignatureTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DigitalSignatureTest.cs @@ -1,54 +1,54 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - ///This is a test class for DigitalSignatureTest and is intended - ///to contain all DigitalSignatureTest Unit Tests - /// - [TestClass()] - public class DigitalSignatureTest : TestBase - { - internal virtual DigitalSignature CreateDigitalSignature() - { - // TODO: Instantiate an appropriate concrete class. - DigitalSignature target = null; - return target; - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - DigitalSignature target = CreateDigitalSignature(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Verify - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifyTest() - { - DigitalSignature target = CreateDigitalSignature(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.Verify(input, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + ///This is a test class for DigitalSignatureTest and is intended + ///to contain all DigitalSignatureTest Unit Tests + /// + [TestClass()] + public class DigitalSignatureTest : TestBase + { + internal virtual DigitalSignature CreateDigitalSignature() + { + // TODO: Instantiate an appropriate concrete class. + DigitalSignature target = null; + return target; + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + DigitalSignature target = CreateDigitalSignature(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Verify + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifyTest() + { + DigitalSignature target = CreateDigitalSignature(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.Verify(input, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaDigitalSignatureTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaDigitalSignatureTest.cs index 93bc28c8..0d3423c9 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaDigitalSignatureTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaDigitalSignatureTest.cs @@ -1,74 +1,74 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - /// Implements DSA digital signature algorithm. - /// - [TestClass] - public class DsaDigitalSignatureTest : TestBase - { - /// - ///A test for DsaDigitalSignature Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DsaDigitalSignatureConstructorTest() - { - DsaKey key = null; // TODO: Initialize to an appropriate value - DsaDigitalSignature target = new DsaDigitalSignature(key); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - DsaKey key = null; // TODO: Initialize to an appropriate value - DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - DsaKey key = null; // TODO: Initialize to an appropriate value - DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Verify - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifyTest() - { - DsaKey key = null; // TODO: Initialize to an appropriate value - DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.Verify(input, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + /// Implements DSA digital signature algorithm. + /// + [TestClass] + public class DsaDigitalSignatureTest : TestBase + { + /// + ///A test for DsaDigitalSignature Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DsaDigitalSignatureConstructorTest() + { + DsaKey key = null; // TODO: Initialize to an appropriate value + DsaDigitalSignature target = new DsaDigitalSignature(key); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + DsaKey key = null; // TODO: Initialize to an appropriate value + DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + DsaKey key = null; // TODO: Initialize to an appropriate value + DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Verify + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifyTest() + { + DsaKey key = null; // TODO: Initialize to an appropriate value + DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.Verify(input, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaKeyTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaKeyTest.cs index 033af1f7..2e4c22ee 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaKeyTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaKeyTest.cs @@ -1,151 +1,151 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - ///This is a test class for DsaKeyTest and is intended - ///to contain all DsaKeyTest Unit Tests - /// - [TestClass()] - public class DsaKeyTest : TestBase - { - /// - ///A test for DsaKey Constructor - /// - [TestMethod()] - public void DsaKeyConstructorTest() - { - DsaKey target = new DsaKey(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DsaKey Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DsaKeyConstructorTest1() - { - byte[] data = null; // TODO: Initialize to an appropriate value - DsaKey target = new DsaKey(data); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DsaKey Constructor - /// - [TestMethod()] - public void DsaKeyConstructorTest2() - { - BigInteger p = new BigInteger(); // TODO: Initialize to an appropriate value - BigInteger q = new BigInteger(); // TODO: Initialize to an appropriate value - BigInteger g = new BigInteger(); // TODO: Initialize to an appropriate value - BigInteger y = new BigInteger(); // TODO: Initialize to an appropriate value - BigInteger x = new BigInteger(); // TODO: Initialize to an appropriate value - DsaKey target = new DsaKey(p, q, g, y, x); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Dispose - /// - [TestMethod()] - public void DisposeTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for G - /// - [TestMethod()] - public void GTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.G; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for KeyLength - /// - [TestMethod()] - public void KeyLengthTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - int actual; - actual = target.KeyLength; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for P - /// - [TestMethod()] - public void PTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.P; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Public - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PublicTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger[] expected = null; // TODO: Initialize to an appropriate value - BigInteger[] actual; - target.Public = expected; - actual = target.Public; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Q - /// - [TestMethod()] - public void QTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.Q; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for X - /// - [TestMethod()] - public void XTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.X; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Y - /// - [TestMethod()] - public void YTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.Y; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + ///This is a test class for DsaKeyTest and is intended + ///to contain all DsaKeyTest Unit Tests + /// + [TestClass()] + public class DsaKeyTest : TestBase + { + /// + ///A test for DsaKey Constructor + /// + [TestMethod()] + public void DsaKeyConstructorTest() + { + DsaKey target = new DsaKey(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DsaKey Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DsaKeyConstructorTest1() + { + byte[] data = null; // TODO: Initialize to an appropriate value + DsaKey target = new DsaKey(data); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DsaKey Constructor + /// + [TestMethod()] + public void DsaKeyConstructorTest2() + { + BigInteger p = new BigInteger(); // TODO: Initialize to an appropriate value + BigInteger q = new BigInteger(); // TODO: Initialize to an appropriate value + BigInteger g = new BigInteger(); // TODO: Initialize to an appropriate value + BigInteger y = new BigInteger(); // TODO: Initialize to an appropriate value + BigInteger x = new BigInteger(); // TODO: Initialize to an appropriate value + DsaKey target = new DsaKey(p, q, g, y, x); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Dispose + /// + [TestMethod()] + public void DisposeTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for G + /// + [TestMethod()] + public void GTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.G; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for KeyLength + /// + [TestMethod()] + public void KeyLengthTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + int actual; + actual = target.KeyLength; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for P + /// + [TestMethod()] + public void PTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.P; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Public + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PublicTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger[] expected = null; // TODO: Initialize to an appropriate value + BigInteger[] actual; + target.Public = expected; + actual = target.Public; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Q + /// + [TestMethod()] + public void QTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.Q; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for X + /// + [TestMethod()] + public void XTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.X; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Y + /// + [TestMethod()] + public void YTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.Y; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/HMacTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/HMacTest.cs index 6c5311be..d36f9629 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/HMacTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/HMacTest.cs @@ -1,136 +1,136 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.Security.Cryptography; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - /// Provides HMAC algorithm implementation. - /// - /// - [TestClass] - public class HMacTest : TestBase - { - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_MD5_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-md5", new HashInfo(16 * 8, HashAlgorithmFactory.CreateHMACMD5)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_Sha1_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, HashAlgorithmFactory.CreateHMACSHA1)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_MD5_96_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-md5", new HashInfo(16 * 8, key => HashAlgorithmFactory.CreateHMACMD5(key, 96))); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_Sha1_96_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, key => HashAlgorithmFactory.CreateHMACSHA1(key, 96))); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_Sha256_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-sha2-256", new HashInfo(32 * 8, HashAlgorithmFactory.CreateHMACSHA256)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_Sha256_96_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-sha2-256-96", new HashInfo(32 * 8, (key) => HashAlgorithmFactory.CreateHMACSHA256(key, 96))); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_RIPEMD160_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-ripemd160", new HashInfo(160, HashAlgorithmFactory.CreateHMACRIPEMD160)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_RIPEMD160_OPENSSH_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-ripemd160@openssh.com", new HashInfo(160, HashAlgorithmFactory.CreateHMACRIPEMD160)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.Security.Cryptography; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + /// Provides HMAC algorithm implementation. + /// + /// + [TestClass] + public class HMacTest : TestBase + { + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_MD5_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-md5", new HashInfo(16 * 8, HashAlgorithmFactory.CreateHMACMD5)); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_Sha1_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, HashAlgorithmFactory.CreateHMACSHA1)); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_MD5_96_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-md5", new HashInfo(16 * 8, key => HashAlgorithmFactory.CreateHMACMD5(key, 96))); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_Sha1_96_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, key => HashAlgorithmFactory.CreateHMACSHA1(key, 96))); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_Sha256_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-sha2-256", new HashInfo(32 * 8, HashAlgorithmFactory.CreateHMACSHA256)); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_Sha256_96_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-sha2-256-96", new HashInfo(32 * 8, (key) => HashAlgorithmFactory.CreateHMACSHA256(key, 96))); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_RIPEMD160_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-ripemd160", new HashInfo(160, HashAlgorithmFactory.CreateHMACRIPEMD160)); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_RIPEMD160_OPENSSH_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-ripemd160@openssh.com", new HashInfo(160, HashAlgorithmFactory.CreateHMACRIPEMD160)); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaDigitalSignatureTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaDigitalSignatureTest.cs index 917ee730..93a76bbe 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaDigitalSignatureTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaDigitalSignatureTest.cs @@ -1,40 +1,40 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - /// Implements RSA digital signature algorithm. - /// - [TestClass] - public class RsaDigitalSignatureTest : TestBase - { - - /// - ///A test for RsaDigitalSignature Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RsaDigitalSignatureConstructorTest() - { - RsaKey rsaKey = null; // TODO: Initialize to an appropriate value - RsaDigitalSignature target = new RsaDigitalSignature(rsaKey); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - RsaKey rsaKey = null; // TODO: Initialize to an appropriate value - RsaDigitalSignature target = new RsaDigitalSignature(rsaKey); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + /// Implements RSA digital signature algorithm. + /// + [TestClass] + public class RsaDigitalSignatureTest : TestBase + { + + /// + ///A test for RsaDigitalSignature Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RsaDigitalSignatureConstructorTest() + { + RsaKey rsaKey = null; // TODO: Initialize to an appropriate value + RsaDigitalSignature target = new RsaDigitalSignature(rsaKey); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + RsaKey rsaKey = null; // TODO: Initialize to an appropriate value + RsaDigitalSignature target = new RsaDigitalSignature(rsaKey); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaKeyTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaKeyTest.cs index 2725511c..89323337 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaKeyTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaKeyTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - /// Contains RSA private and public key - /// - [TestClass] - public class RsaKeyTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + /// Contains RSA private and public key + /// + [TestClass] + public class RsaKeyTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/SymmetricCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/SymmetricCipherTest.cs index 45939e45..8dce8881 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/SymmetricCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/SymmetricCipherTest.cs @@ -1,62 +1,62 @@ -using Renci.SshNet.Security.Cryptography; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests -{ - /// - ///This is a test class for SymmetricCipherTest and is intended - ///to contain all SymmetricCipherTest Unit Tests - /// - [TestClass()] - public class SymmetricCipherTest : TestBase - { - internal virtual SymmetricCipher CreateSymmetricCipher() - { - // TODO: Instantiate an appropriate concrete class. - SymmetricCipher target = null; - return target; - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - SymmetricCipher target = CreateSymmetricCipher(); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - SymmetricCipher target = CreateSymmetricCipher(); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Security.Cryptography; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests +{ + /// + ///This is a test class for SymmetricCipherTest and is intended + ///to contain all SymmetricCipherTest Unit Tests + /// + [TestClass()] + public class SymmetricCipherTest : TestBase + { + internal virtual SymmetricCipher CreateSymmetricCipher() + { + // TODO: Instantiate an appropriate concrete class. + SymmetricCipher target = null; + return target; + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + SymmetricCipher target = CreateSymmetricCipher(); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + SymmetricCipher target = CreateSymmetricCipher(); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/HostAlgorithmTest.cs b/src/Renci.SshNet.Tests/Classes/Security/HostAlgorithmTest.cs index 5e2825be..a9547a54 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/HostAlgorithmTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/HostAlgorithmTest.cs @@ -1,67 +1,67 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for HostAlgorithmTest and is intended - ///to contain all HostAlgorithmTest Unit Tests - /// - [TestClass()] - public class HostAlgorithmTest : TestBase - { - internal virtual HostAlgorithm CreateHostAlgorithm() - { - // TODO: Instantiate an appropriate concrete class. - HostAlgorithm target = null; - return target; - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for VerifySignature - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifySignatureTest() - { - HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.VerifySignature(data, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Data - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DataTest() - { - HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Data; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for HostAlgorithmTest and is intended + ///to contain all HostAlgorithmTest Unit Tests + /// + [TestClass()] + public class HostAlgorithmTest : TestBase + { + internal virtual HostAlgorithm CreateHostAlgorithm() + { + // TODO: Instantiate an appropriate concrete class. + HostAlgorithm target = null; + return target; + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for VerifySignature + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifySignatureTest() + { + HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.VerifySignature(data, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Data + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DataTest() + { + HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Data; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs index afa838ee..f4fcb91f 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - /// Represents "diffie-hellman-group14-sha1" algorithm implementation. - /// - [TestClass] - public class KeyExchangeDiffieHellmanGroup14Sha1Test : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + /// Represents "diffie-hellman-group14-sha1" algorithm implementation. + /// + [TestClass] + public class KeyExchangeDiffieHellmanGroup14Sha1Test : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs index 0c729810..a06f8760 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs @@ -1,49 +1,49 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for KeyExchangeDiffieHellmanGroup1Sha1Test and is intended - ///to contain all KeyExchangeDiffieHellmanGroup1Sha1Test Unit Tests - /// - [TestClass()] - public class KeyExchangeDiffieHellmanGroup1Sha1Test : TestBase - { - /// - ///A test for KeyExchangeDiffieHellmanGroup1Sha1 Constructor - /// - [TestMethod()] - public void KeyExchangeDiffieHellmanGroup1Sha1ConstructorTest() - { - KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for GroupPrime - /// - [TestMethod()] - public void GroupPrimeTest() - { - KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.GroupPrime; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Name - /// - [TestMethod()] - public void NameTest() - { - KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for KeyExchangeDiffieHellmanGroup1Sha1Test and is intended + ///to contain all KeyExchangeDiffieHellmanGroup1Sha1Test Unit Tests + /// + [TestClass()] + public class KeyExchangeDiffieHellmanGroup1Sha1Test : TestBase + { + /// + ///A test for KeyExchangeDiffieHellmanGroup1Sha1 Constructor + /// + [TestMethod()] + public void KeyExchangeDiffieHellmanGroup1Sha1ConstructorTest() + { + KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for GroupPrime + /// + [TestMethod()] + public void GroupPrimeTest() + { + KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.GroupPrime; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Name + /// + [TestMethod()] + public void NameTest() + { + KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); // TODO: Initialize to an appropriate value + string actual; + actual = target.Name; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha1Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha1Test.cs index 87c45b60..980733e0 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha1Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha1Test.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - /// Represents "diffie-hellman-group-exchange-sha1" algorithm implementation. - /// - [TestClass] - public class KeyExchangeDiffieHellmanGroupExchangeSha1Test : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + /// Represents "diffie-hellman-group-exchange-sha1" algorithm implementation. + /// + [TestClass] + public class KeyExchangeDiffieHellmanGroupExchangeSha1Test : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha256Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha256Test.cs index 1fdd96ae..d6b5cfef 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha256Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha256Test.cs @@ -1,63 +1,63 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for KeyExchangeDiffieHellmanGroupExchangeSha256Test and is intended - ///to contain all KeyExchangeDiffieHellmanGroupExchangeSha256Test Unit Tests - /// - [TestClass()] - public class KeyExchangeDiffieHellmanGroupExchangeSha256Test : TestBase - { - /// - ///A test for KeyExchangeDiffieHellmanGroupExchangeSha256 Constructor - /// - [TestMethod()] - public void KeyExchangeDiffieHellmanGroupExchangeSha256ConstructorTest() - { - KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Finish - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void FinishTest() - { - KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value - target.Finish(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Start - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void StartTest() - { - KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value - Session session = null; // TODO: Initialize to an appropriate value - KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value - target.Start(session, message); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Name - /// - [TestMethod()] - public void NameTest() - { - KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for KeyExchangeDiffieHellmanGroupExchangeSha256Test and is intended + ///to contain all KeyExchangeDiffieHellmanGroupExchangeSha256Test Unit Tests + /// + [TestClass()] + public class KeyExchangeDiffieHellmanGroupExchangeSha256Test : TestBase + { + /// + ///A test for KeyExchangeDiffieHellmanGroupExchangeSha256 Constructor + /// + [TestMethod()] + public void KeyExchangeDiffieHellmanGroupExchangeSha256ConstructorTest() + { + KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Finish + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void FinishTest() + { + KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value + target.Finish(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Start + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void StartTest() + { + KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value + Session session = null; // TODO: Initialize to an appropriate value + KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value + target.Start(session, message); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Name + /// + [TestMethod()] + public void NameTest() + { + KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value + string actual; + actual = target.Name; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupSha1Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupSha1Test.cs index 8ad08550..40d6b3b8 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupSha1Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupSha1Test.cs @@ -1,62 +1,62 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for KeyExchangeDiffieHellmanGroupSha1Test and is intended - ///to contain all KeyExchangeDiffieHellmanGroupSha1Test Unit Tests - /// - [TestClass()] - public class KeyExchangeDiffieHellmanGroupSha1Test : TestBase - { - internal virtual KeyExchangeDiffieHellmanGroupSha1 CreateKeyExchangeDiffieHellmanGroupSha1() - { - // TODO: Instantiate an appropriate concrete class. - KeyExchangeDiffieHellmanGroupSha1 target = null; - return target; - } - - /// - ///A test for Finish - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void FinishTest() - { - KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value - target.Finish(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Start - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void StartTest() - { - KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value - Session session = null; // TODO: Initialize to an appropriate value - KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value - target.Start(session, message); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for GroupPrime - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GroupPrimeTest() - { - KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.GroupPrime; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for KeyExchangeDiffieHellmanGroupSha1Test and is intended + ///to contain all KeyExchangeDiffieHellmanGroupSha1Test Unit Tests + /// + [TestClass()] + public class KeyExchangeDiffieHellmanGroupSha1Test : TestBase + { + internal virtual KeyExchangeDiffieHellmanGroupSha1 CreateKeyExchangeDiffieHellmanGroupSha1() + { + // TODO: Instantiate an appropriate concrete class. + KeyExchangeDiffieHellmanGroupSha1 target = null; + return target; + } + + /// + ///A test for Finish + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void FinishTest() + { + KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value + target.Finish(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Start + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void StartTest() + { + KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value + Session session = null; // TODO: Initialize to an appropriate value + KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value + target.Start(session, message); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for GroupPrime + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GroupPrimeTest() + { + KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.GroupPrime; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanTest.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanTest.cs index 95d98e77..98b73858 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanTest.cs @@ -1,36 +1,36 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for KeyExchangeDiffieHellmanTest and is intended - ///to contain all KeyExchangeDiffieHellmanTest Unit Tests - /// - [TestClass()] - public class KeyExchangeDiffieHellmanTest : TestBase - { - internal virtual KeyExchangeDiffieHellman CreateKeyExchangeDiffieHellman() - { - // TODO: Instantiate an appropriate concrete class. - KeyExchangeDiffieHellman target = null; - return target; - } - - /// - ///A test for Start - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void StartTest() - { - KeyExchangeDiffieHellman target = CreateKeyExchangeDiffieHellman(); // TODO: Initialize to an appropriate value - Session session = null; // TODO: Initialize to an appropriate value - KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value - target.Start(session, message); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for KeyExchangeDiffieHellmanTest and is intended + ///to contain all KeyExchangeDiffieHellmanTest Unit Tests + /// + [TestClass()] + public class KeyExchangeDiffieHellmanTest : TestBase + { + internal virtual KeyExchangeDiffieHellman CreateKeyExchangeDiffieHellman() + { + // TODO: Instantiate an appropriate concrete class. + KeyExchangeDiffieHellman target = null; + return target; + } + + /// + ///A test for Start + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void StartTest() + { + KeyExchangeDiffieHellman target = CreateKeyExchangeDiffieHellman(); // TODO: Initialize to an appropriate value + Session session = null; // TODO: Initialize to an appropriate value + KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value + target.Start(session, message); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeTest.cs index d1bab190..839394e6 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeTest.cs @@ -1,16 +1,16 @@ -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Renci.SshNet.Tests -{ - /// - ///This is a test class for KeyExchangeTest and is intended - ///to contain all KeyExchangeTest Unit Tests - /// - [TestClass()] - public class KeyExchangeTest : TestBase - { - - } -} +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Renci.SshNet.Tests +{ + /// + ///This is a test class for KeyExchangeTest and is intended + ///to contain all KeyExchangeTest Unit Tests + /// + [TestClass()] + public class KeyExchangeTest : TestBase + { + + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyHostAlgorithmTest.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyHostAlgorithmTest.cs index 01c69c69..9bd5d10c 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyHostAlgorithmTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyHostAlgorithmTest.cs @@ -1,123 +1,123 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - /// Implements key support for host algorithm. - /// - [TestClass] - public class KeyHostAlgorithmTest : TestBase - { - [TestMethod] - [TestCategory("integration")] - public void Test_HostKey_SshRsa_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HostKeyAlgorithms.Clear(); - connectionInfo.HostKeyAlgorithms.Add("ssh-rsa", (data) => { return new KeyHostAlgorithm("ssh-rsa", new RsaKey(), data); }); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HostKey_SshDss_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HostKeyAlgorithms.Clear(); - connectionInfo.HostKeyAlgorithms.Add("ssh-dss", (data) => { return new KeyHostAlgorithm("ssh-dss", new DsaKey(), data); }); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - /// - ///A test for KeyHostAlgorithm Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyHostAlgorithmConstructorTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - Key key = null; // TODO: Initialize to an appropriate value - KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for KeyHostAlgorithm Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyHostAlgorithmConstructorTest1() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - Key key = null; // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - KeyHostAlgorithm target = new KeyHostAlgorithm(name, key, data); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - Key key = null; // TODO: Initialize to an appropriate value - KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for VerifySignature - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifySignatureTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - Key key = null; // TODO: Initialize to an appropriate value - KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.VerifySignature(data, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Data - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DataTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - Key key = null; // TODO: Initialize to an appropriate value - KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Data; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + /// Implements key support for host algorithm. + /// + [TestClass] + public class KeyHostAlgorithmTest : TestBase + { + [TestMethod] + [TestCategory("integration")] + public void Test_HostKey_SshRsa_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HostKeyAlgorithms.Clear(); + connectionInfo.HostKeyAlgorithms.Add("ssh-rsa", (data) => { return new KeyHostAlgorithm("ssh-rsa", new RsaKey(), data); }); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HostKey_SshDss_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HostKeyAlgorithms.Clear(); + connectionInfo.HostKeyAlgorithms.Add("ssh-dss", (data) => { return new KeyHostAlgorithm("ssh-dss", new DsaKey(), data); }); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + /// + ///A test for KeyHostAlgorithm Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyHostAlgorithmConstructorTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + Key key = null; // TODO: Initialize to an appropriate value + KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for KeyHostAlgorithm Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyHostAlgorithmConstructorTest1() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + Key key = null; // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + KeyHostAlgorithm target = new KeyHostAlgorithm(name, key, data); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + Key key = null; // TODO: Initialize to an appropriate value + KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for VerifySignature + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifySignatureTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + Key key = null; // TODO: Initialize to an appropriate value + KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.VerifySignature(data, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Data + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DataTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + Key key = null; // TODO: Initialize to an appropriate value + KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Data; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyTest.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyTest.cs index 81339921..bbbbacff 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyTest.cs @@ -1,84 +1,84 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for KeyTest and is intended - ///to contain all KeyTest Unit Tests - /// - [TestClass()] - public class KeyTest : TestBase - { - internal virtual Key CreateKey() - { - // TODO: Instantiate an appropriate concrete class. - Key target = null; - return target; - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - Key target = CreateKey(); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for VerifySignature - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifySignatureTest() - { - Key target = CreateKey(); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.VerifySignature(data, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for KeyLength - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyLengthTest() - { - Key target = CreateKey(); // TODO: Initialize to an appropriate value - int actual; - actual = target.KeyLength; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Public - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PublicTest() - { - Key target = CreateKey(); // TODO: Initialize to an appropriate value - BigInteger[] expected = null; // TODO: Initialize to an appropriate value - BigInteger[] actual; - target.Public = expected; - actual = target.Public; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for KeyTest and is intended + ///to contain all KeyTest Unit Tests + /// + [TestClass()] + public class KeyTest : TestBase + { + internal virtual Key CreateKey() + { + // TODO: Instantiate an appropriate concrete class. + Key target = null; + return target; + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + Key target = CreateKey(); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for VerifySignature + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifySignatureTest() + { + Key target = CreateKey(); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.VerifySignature(data, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for KeyLength + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyLengthTest() + { + Key target = CreateKey(); // TODO: Initialize to an appropriate value + int actual; + actual = target.KeyLength; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Public + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PublicTest() + { + Key target = CreateKey(); // TODO: Initialize to an appropriate value + BigInteger[] expected = null; // TODO: Initialize to an appropriate value + BigInteger[] actual; + target.Public = expected; + actual = target.Public; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest.HttpProxy.cs b/src/Renci.SshNet.Tests/Classes/SessionTest.HttpProxy.cs index af54db1b..7780d2d8 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest.HttpProxy.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest.HttpProxy.cs @@ -1,263 +1,263 @@ -using System; -using System.Net; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - public partial class SessionTest - { - [TestMethod] - public void ConnectShouldThrowProxyExceptionWhenHttpProxyResponseDoesNotContainStatusLine() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Whatever\r\n")); - proxyStub.Start(); - - using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("HTTP response does not contain status line.", ex.Message); - } - } - } - } - - [TestMethod] - public void ConnectShouldThrowProxyExceptionWhenHttpProxyReturnsHttpStatusOtherThan200() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); - proxyStub.Start(); - - using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("HTTP: Status code 501, \"Custom\"", ex.Message); - } - } - } - } - - [TestMethod] - public void ConnectShouldSkipHeadersWhenHttpProxyReturnsHttpStatus200() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("SSH-666-SshStub")); - proxyStub.Start(); - - using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server version '666' is not supported.", ex.Message); - } - } - } - } - - [TestMethod] - public void ConnectShouldSkipContentWhenHttpProxyReturnsHttpStatus200() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Length: 13\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("DUMMY_CONTENT")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("SSH-666-SshStub")); - proxyStub.Start(); - - using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server version '666' is not supported.", ex.Message); - } - } - } - } - - [TestMethod] - public void ConnectShouldWriteConnectMethodToHttpProxy() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); - proxyStub.Start(); - - using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException) - { - } - } - - Assert.AreEqual(string.Format("CONNECT {0} HTTP/1.0", serverEndPoint), proxyStub.HttpRequest.RequestLine); - } - } - - [TestMethod] - public void ConnectShouldWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNotNullAndNotEmpty() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); - proxyStub.Start(); - - var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"); - using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException) - { - } - } - - var expectedProxyAuthorizationHeader = CreateProxyAuthorizationHeader(connectionInfo); - Assert.IsNotNull(proxyStub.HttpRequest.Headers.SingleOrDefault(p => p == expectedProxyAuthorizationHeader)); - } - } - - [TestMethod] - public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsEmpty() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); - proxyStub.Start(); - - var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, string.Empty); - using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException) - { - } - } - - Assert.IsFalse(proxyStub.HttpRequest.Headers.Any(p => p.StartsWith("Proxy-Authorization:"))); - } - } - - [TestMethod] - public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNull() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); - proxyStub.Start(); - - var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, null); - using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException) - { - } - } - - Assert.IsFalse(proxyStub.HttpRequest.Headers.Any(p => p.StartsWith("Proxy-Authorization:"))); - } - } - - private static ConnectionInfo CreateConnectionInfoWithProxy(IPEndPoint proxyEndPoint, IPEndPoint serverEndPoint, string proxyUserName) - { - return new ConnectionInfo( - serverEndPoint.Address.ToString(), - serverEndPoint.Port, - "eric", - ProxyTypes.Http, - proxyEndPoint.Address.ToString(), - proxyEndPoint.Port, - proxyUserName, - "proxypwd", - new NoneAuthenticationMethod("eric")); - } - - private static string CreateProxyAuthorizationHeader(ConnectionInfo connectionInfo) - { - return string.Format("Proxy-Authorization: Basic {0}", - Convert.ToBase64String( - Encoding.ASCII.GetBytes(string.Format("{0}:{1}", connectionInfo.ProxyUsername, - connectionInfo.ProxyPassword)))); - } - } -} +using System; +using System.Net; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + public partial class SessionTest + { + [TestMethod] + public void ConnectShouldThrowProxyExceptionWhenHttpProxyResponseDoesNotContainStatusLine() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Whatever\r\n")); + proxyStub.Start(); + + using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("HTTP response does not contain status line.", ex.Message); + } + } + } + } + + [TestMethod] + public void ConnectShouldThrowProxyExceptionWhenHttpProxyReturnsHttpStatusOtherThan200() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); + proxyStub.Start(); + + using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("HTTP: Status code 501, \"Custom\"", ex.Message); + } + } + } + } + + [TestMethod] + public void ConnectShouldSkipHeadersWhenHttpProxyReturnsHttpStatus200() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("SSH-666-SshStub")); + proxyStub.Start(); + + using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server version '666' is not supported.", ex.Message); + } + } + } + } + + [TestMethod] + public void ConnectShouldSkipContentWhenHttpProxyReturnsHttpStatus200() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Length: 13\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("DUMMY_CONTENT")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("SSH-666-SshStub")); + proxyStub.Start(); + + using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server version '666' is not supported.", ex.Message); + } + } + } + } + + [TestMethod] + public void ConnectShouldWriteConnectMethodToHttpProxy() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); + proxyStub.Start(); + + using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException) + { + } + } + + Assert.AreEqual(string.Format("CONNECT {0} HTTP/1.0", serverEndPoint), proxyStub.HttpRequest.RequestLine); + } + } + + [TestMethod] + public void ConnectShouldWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNotNullAndNotEmpty() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); + proxyStub.Start(); + + var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"); + using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException) + { + } + } + + var expectedProxyAuthorizationHeader = CreateProxyAuthorizationHeader(connectionInfo); + Assert.IsNotNull(proxyStub.HttpRequest.Headers.SingleOrDefault(p => p == expectedProxyAuthorizationHeader)); + } + } + + [TestMethod] + public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsEmpty() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); + proxyStub.Start(); + + var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, string.Empty); + using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException) + { + } + } + + Assert.IsFalse(proxyStub.HttpRequest.Headers.Any(p => p.StartsWith("Proxy-Authorization:"))); + } + } + + [TestMethod] + public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNull() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); + proxyStub.Start(); + + var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, null); + using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException) + { + } + } + + Assert.IsFalse(proxyStub.HttpRequest.Headers.Any(p => p.StartsWith("Proxy-Authorization:"))); + } + } + + private static ConnectionInfo CreateConnectionInfoWithProxy(IPEndPoint proxyEndPoint, IPEndPoint serverEndPoint, string proxyUserName) + { + return new ConnectionInfo( + serverEndPoint.Address.ToString(), + serverEndPoint.Port, + "eric", + ProxyTypes.Http, + proxyEndPoint.Address.ToString(), + proxyEndPoint.Port, + proxyUserName, + "proxypwd", + new NoneAuthenticationMethod("eric")); + } + + private static string CreateProxyAuthorizationHeader(ConnectionInfo connectionInfo) + { + return string.Format("Proxy-Authorization: Basic {0}", + Convert.ToBase64String( + Encoding.ASCII.GetBytes(string.Format("{0}:{1}", connectionInfo.ProxyUsername, + connectionInfo.ProxyPassword)))); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest.cs b/src/Renci.SshNet.Tests/Classes/SessionTest.cs index c94bfe56..29e88746 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest.cs @@ -1,363 +1,363 @@ -using System; -using System.Globalization; -using System.Net; -using System.Net.Sockets; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides functionality to connect and interact with SSH server. - /// - [TestClass] - public partial class SessionTest : TestBase - { - private Mock _serviceFactoryMock; - - protected override void OnInit() - { - base.OnInit(); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - } - - [TestMethod] - public void ConstructorShouldThrowArgumentNullExceptionWhenConnectionInfoIsNull() - { - ConnectionInfo connectionInfo = null; - var serviceFactory = new Mock(MockBehavior.Strict).Object; - - try - { - new Session(connectionInfo, serviceFactory); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("connectionInfo", ex.ParamName); - } - } - - [TestMethod] - public void ConstructorShouldThrowArgumentNullExceptionWhenServiceFactoryIsNull() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); - IServiceFactory serviceFactory = null; - - try - { - new Session(connectionInfo, serviceFactory); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("serviceFactory", ex.ParamName); - } - } - - [TestMethod] - public void ConnectShouldSkipLinesBeforeProtocolIdentificationString() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); - - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Send(Encoding.ASCII.GetBytes("SSH-666-SshStub\r\n")); - socket.Shutdown(SocketShutdown.Send); - }; - serverStub.Start(); - - using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server version '666' is not supported.", ex.Message); - - Assert.AreEqual("SSH-666-SshStub", connectionInfo.ServerVersion); - } - } - } - } - - [TestMethod] - public void ConnectShouldSupportProtocolIdentificationStringThatDoesNotEndWithCrlf() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); - - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Send(Encoding.ASCII.GetBytes("SSH-666-SshStub")); - socket.Shutdown(SocketShutdown.Send); - }; - serverStub.Start(); - - using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server version '666' is not supported.", ex.Message); - - Assert.AreEqual("SSH-666-SshStub", connectionInfo.ServerVersion); - } - } - } - } - - [TestMethod] - public void ConnectShouldThrowSshOperationExceptionWhenServerDoesNotRespondWithinConnectionTimeout() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - var timeout = TimeSpan.FromMilliseconds(500); - Socket clientSocket = null; - - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - clientSocket = socket; - }; - serverStub.Start(); - - using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromMilliseconds(500)), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshOperationTimeoutException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "Socket read operation has timed out after {0:F0} milliseconds.", timeout.TotalMilliseconds), ex.Message); - - Assert.IsNotNull(clientSocket); - Assert.IsTrue(clientSocket.Connected); - - // shut down socket - clientSocket.Shutdown(SocketShutdown.Send); - } - } - } - } - - [TestMethod] - public void ConnectShouldSshConnectionExceptionWhenServerResponseDoesNotContainProtocolIdentificationString() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - // response ends with CRLF - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Shutdown(SocketShutdown.Send); - }; - serverStub.Start(); - - using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); - } - } - } - - // response does not end with CRLF - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner")); - socket.Shutdown(SocketShutdown.Send); - }; - serverStub.Start(); - - using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); - } - } - } - - // last line is empty - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Shutdown(SocketShutdown.Send); - }; - serverStub.Start(); - - using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); - } - } - } - } - - [TestMethod] - public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() - { - var connectionInfo = new ConnectionInfo("invalid.", 40, "user", - new KeyboardInteractiveAuthenticationMethod("user")); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - try - { - session.Connect(); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); - } - } - - [TestMethod] - public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() - { - var connectionInfo = new ConnectionInfo("localhost", 40, "user", ProxyTypes.Http, "invalid.", 80, - "proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user")); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - try - { - session.Connect(); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); - } - } - - [TestMethod] - public void DisconnectShouldNotThrowExceptionWhenSocketIsNotConnected() - { - var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - try - { - session.Connect(); - Assert.Fail(); - } - catch (SocketException) - { - session.Disconnect(); - } - } - - [TestMethod] - public void DisconnectShouldNotThrowExceptionWhenConnectHasNotBeenInvoked() - { - var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - session.Disconnect(); - } - - [TestMethod] - public void DisposeShouldNotThrowExceptionWhenSocketIsNotConnected() - { - var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - try - { - session.Connect(); - Assert.Fail(); - } - catch (SocketException) - { - session.Dispose(); - } - } - - [TestMethod] - public void DisposeShouldNotThrowExceptionWhenConenectHasNotBeenInvoked() - { - var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - session.Disconnect(); - } - - private static ConnectionInfo CreateConnectionInfo(IPEndPoint serverEndPoint, TimeSpan timeout) - { - var connectionInfo = new ConnectionInfo( - serverEndPoint.Address.ToString(), - serverEndPoint.Port, - "eric", - new NoneAuthenticationMethod("eric")); - connectionInfo.Timeout = timeout; - return connectionInfo; - } - } +using System; +using System.Globalization; +using System.Net; +using System.Net.Sockets; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides functionality to connect and interact with SSH server. + /// + [TestClass] + public partial class SessionTest : TestBase + { + private Mock _serviceFactoryMock; + + protected override void OnInit() + { + base.OnInit(); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + } + + [TestMethod] + public void ConstructorShouldThrowArgumentNullExceptionWhenConnectionInfoIsNull() + { + ConnectionInfo connectionInfo = null; + var serviceFactory = new Mock(MockBehavior.Strict).Object; + + try + { + new Session(connectionInfo, serviceFactory); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("connectionInfo", ex.ParamName); + } + } + + [TestMethod] + public void ConstructorShouldThrowArgumentNullExceptionWhenServiceFactoryIsNull() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); + IServiceFactory serviceFactory = null; + + try + { + new Session(connectionInfo, serviceFactory); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("serviceFactory", ex.ParamName); + } + } + + [TestMethod] + public void ConnectShouldSkipLinesBeforeProtocolIdentificationString() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); + + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Send(Encoding.ASCII.GetBytes("SSH-666-SshStub\r\n")); + socket.Shutdown(SocketShutdown.Send); + }; + serverStub.Start(); + + using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server version '666' is not supported.", ex.Message); + + Assert.AreEqual("SSH-666-SshStub", connectionInfo.ServerVersion); + } + } + } + } + + [TestMethod] + public void ConnectShouldSupportProtocolIdentificationStringThatDoesNotEndWithCrlf() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); + + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Send(Encoding.ASCII.GetBytes("SSH-666-SshStub")); + socket.Shutdown(SocketShutdown.Send); + }; + serverStub.Start(); + + using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server version '666' is not supported.", ex.Message); + + Assert.AreEqual("SSH-666-SshStub", connectionInfo.ServerVersion); + } + } + } + } + + [TestMethod] + public void ConnectShouldThrowSshOperationExceptionWhenServerDoesNotRespondWithinConnectionTimeout() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + var timeout = TimeSpan.FromMilliseconds(500); + Socket clientSocket = null; + + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + clientSocket = socket; + }; + serverStub.Start(); + + using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromMilliseconds(500)), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshOperationTimeoutException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "Socket read operation has timed out after {0:F0} milliseconds.", timeout.TotalMilliseconds), ex.Message); + + Assert.IsNotNull(clientSocket); + Assert.IsTrue(clientSocket.Connected); + + // shut down socket + clientSocket.Shutdown(SocketShutdown.Send); + } + } + } + } + + [TestMethod] + public void ConnectShouldSshConnectionExceptionWhenServerResponseDoesNotContainProtocolIdentificationString() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + // response ends with CRLF + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Shutdown(SocketShutdown.Send); + }; + serverStub.Start(); + + using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); + } + } + } + + // response does not end with CRLF + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner")); + socket.Shutdown(SocketShutdown.Send); + }; + serverStub.Start(); + + using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); + } + } + } + + // last line is empty + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Shutdown(SocketShutdown.Send); + }; + serverStub.Start(); + + using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); + } + } + } + } + + [TestMethod] + public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() + { + var connectionInfo = new ConnectionInfo("invalid.", 40, "user", + new KeyboardInteractiveAuthenticationMethod("user")); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + try + { + session.Connect(); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); + } + } + + [TestMethod] + public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() + { + var connectionInfo = new ConnectionInfo("localhost", 40, "user", ProxyTypes.Http, "invalid.", 80, + "proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user")); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + try + { + session.Connect(); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); + } + } + + [TestMethod] + public void DisconnectShouldNotThrowExceptionWhenSocketIsNotConnected() + { + var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + try + { + session.Connect(); + Assert.Fail(); + } + catch (SocketException) + { + session.Disconnect(); + } + } + + [TestMethod] + public void DisconnectShouldNotThrowExceptionWhenConnectHasNotBeenInvoked() + { + var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + session.Disconnect(); + } + + [TestMethod] + public void DisposeShouldNotThrowExceptionWhenSocketIsNotConnected() + { + var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + try + { + session.Connect(); + Assert.Fail(); + } + catch (SocketException) + { + session.Dispose(); + } + } + + [TestMethod] + public void DisposeShouldNotThrowExceptionWhenConenectHasNotBeenInvoked() + { + var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + session.Disconnect(); + } + + private static ConnectionInfo CreateConnectionInfo(IPEndPoint serverEndPoint, TimeSpan timeout) + { + var connectionInfo = new ConnectionInfo( + serverEndPoint.Address.ToString(), + serverEndPoint.Port, + "eric", + new NoneAuthenticationMethod("eric")); + connectionInfo.Timeout = timeout; + return connectionInfo; + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs index b92c2f0e..829bac3d 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs @@ -1,169 +1,169 @@ -using System; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected : SessionTest_ConnectedBase - { - private IgnoreMessage _ignoreMessage; - - protected override void Arrange() - { - base.Arrange(); - - var data = new byte[10]; - Random.NextBytes(data); - _ignoreMessage = new IgnoreMessage(data); - } - - protected override void Act() - { - } - - [TestMethod] - public void ClientVersionIsRenciSshNet() - { - Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", Session.ClientVersion); - } - - [TestMethod] - public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() - { - Assert.AreSame(ConnectionInfo, Session.ConnectionInfo); - } - - [TestMethod] - public void IsConnectedShouldReturnTrue() - { - Assert.IsTrue(Session.IsConnected); - } - - [TestMethod] - public void SendMessageShouldSendPacketToServer() - { - ServerBytesReceivedRegister.Clear(); - - Session.SendMessage(_ignoreMessage); - - // give session time to process message - Thread.Sleep(100); - - Assert.AreEqual(1, ServerBytesReceivedRegister.Count); - } - - [TestMethod] - public void SessionIdShouldReturnExchangeHashCalculatedFromKeyExchangeInitMessage() - { - Assert.IsNotNull(Session.SessionId); - Assert.AreSame(SessionId, Session.SessionId); - } - - [TestMethod] - public void ServerVersionShouldNotReturnNull() - { - Assert.IsNotNull(Session.ServerVersion); - Assert.AreEqual("SSH-2.0-SshStub", Session.ServerVersion); - } - - [TestMethod] - public void WaitOnHandle_WaitHandle_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - - try - { - Session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - - [TestMethod] - public void WaitOnHandle_WaitHandleAndTimeout_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - var timeout = TimeSpan.FromMinutes(5); - - try - { - Session.WaitOnHandle(waitHandle, timeout); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - - [TestMethod] - public void ISession_ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() - { - var session = (ISession) Session; - Assert.AreSame(ConnectionInfo, session.ConnectionInfo); - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldNotBeSignaled() - { - var session = (ISession) Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsFalse(session.MessageListenerCompleted.WaitOne(0)); - } - - [TestMethod] - public void ISession_SendMessageShouldSendPacketToServer() - { - var session = (ISession) Session; - ServerBytesReceivedRegister.Clear(); - - session.SendMessage(_ignoreMessage); - - // give session time to process message - Thread.Sleep(100); - - Assert.AreEqual(1, ServerBytesReceivedRegister.Count); - } - - [TestMethod] - public void ISession_TrySendMessageShouldSendPacketToServerAndReturnTrue() - { - var session = (ISession) Session; - ServerBytesReceivedRegister.Clear(); - - var actual = session.TrySendMessage(new IgnoreMessage()); - - // give session time to process message - Thread.Sleep(100); - - Assert.IsTrue(actual); - Assert.AreEqual(1, ServerBytesReceivedRegister.Count); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - var session = (ISession) Session; - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - } -} +using System; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected : SessionTest_ConnectedBase + { + private IgnoreMessage _ignoreMessage; + + protected override void Arrange() + { + base.Arrange(); + + var data = new byte[10]; + Random.NextBytes(data); + _ignoreMessage = new IgnoreMessage(data); + } + + protected override void Act() + { + } + + [TestMethod] + public void ClientVersionIsRenciSshNet() + { + Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", Session.ClientVersion); + } + + [TestMethod] + public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() + { + Assert.AreSame(ConnectionInfo, Session.ConnectionInfo); + } + + [TestMethod] + public void IsConnectedShouldReturnTrue() + { + Assert.IsTrue(Session.IsConnected); + } + + [TestMethod] + public void SendMessageShouldSendPacketToServer() + { + ServerBytesReceivedRegister.Clear(); + + Session.SendMessage(_ignoreMessage); + + // give session time to process message + Thread.Sleep(100); + + Assert.AreEqual(1, ServerBytesReceivedRegister.Count); + } + + [TestMethod] + public void SessionIdShouldReturnExchangeHashCalculatedFromKeyExchangeInitMessage() + { + Assert.IsNotNull(Session.SessionId); + Assert.AreSame(SessionId, Session.SessionId); + } + + [TestMethod] + public void ServerVersionShouldNotReturnNull() + { + Assert.IsNotNull(Session.ServerVersion); + Assert.AreEqual("SSH-2.0-SshStub", Session.ServerVersion); + } + + [TestMethod] + public void WaitOnHandle_WaitHandle_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + + try + { + Session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + + [TestMethod] + public void WaitOnHandle_WaitHandleAndTimeout_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + var timeout = TimeSpan.FromMinutes(5); + + try + { + Session.WaitOnHandle(waitHandle, timeout); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + + [TestMethod] + public void ISession_ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() + { + var session = (ISession) Session; + Assert.AreSame(ConnectionInfo, session.ConnectionInfo); + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldNotBeSignaled() + { + var session = (ISession) Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsFalse(session.MessageListenerCompleted.WaitOne(0)); + } + + [TestMethod] + public void ISession_SendMessageShouldSendPacketToServer() + { + var session = (ISession) Session; + ServerBytesReceivedRegister.Clear(); + + session.SendMessage(_ignoreMessage); + + // give session time to process message + Thread.Sleep(100); + + Assert.AreEqual(1, ServerBytesReceivedRegister.Count); + } + + [TestMethod] + public void ISession_TrySendMessageShouldSendPacketToServerAndReturnTrue() + { + var session = (ISession) Session; + ServerBytesReceivedRegister.Clear(); + + var actual = session.TrySendMessage(new IgnoreMessage()); + + // give session time to process message + Thread.Sleep(100); + + Assert.IsTrue(actual); + Assert.AreEqual(1, ServerBytesReceivedRegister.Count); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + var session = (ISession) Session; + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs index 56b03d85..9584d0c0 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs @@ -1,192 +1,192 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using System.Net.Sockets; -using System.Security.Cryptography; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Compression; -using Renci.SshNet.Messages; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Security; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public abstract class SessionTest_ConnectedBase - { - private Mock _serviceFactoryMock; - private Mock _keyExchangeMock; - private Mock _clientAuthenticationMock; - private IPEndPoint _serverEndPoint; - private string _keyExchangeAlgorithm; - - protected Random Random { get; private set; } - protected byte[] SessionId { get; private set; } - protected ConnectionInfo ConnectionInfo { get; private set; } - protected IList DisconnectedRegister { get; private set; } - protected IList> DisconnectReceivedRegister { get; private set; } - protected IList ErrorOccurredRegister { get; private set; } - protected AsyncSocketListener ServerListener { get; private set; } - protected IList ServerBytesReceivedRegister { get; private set; } - protected Session Session { get; private set; } - protected Socket ServerSocket { get; private set; } - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void TearDown() - { - if (ServerListener != null) - { - ServerListener.Dispose(); - } - - if (Session != null) - { - Session.Dispose(); - } - } - - protected virtual void Arrange() - { - Random = new Random(); - - _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - ConnectionInfo = new ConnectionInfo( - _serverEndPoint.Address.ToString(), - _serverEndPoint.Port, - "user", - new PasswordAuthenticationMethod("user", "password")); - ConnectionInfo.Timeout = TimeSpan.FromSeconds(20); - _keyExchangeAlgorithm = Random.Next().ToString(CultureInfo.InvariantCulture); - SessionId = new byte[10]; - Random.NextBytes(SessionId); - DisconnectedRegister = new List(); - DisconnectReceivedRegister = new List>(); - ErrorOccurredRegister = new List(); - ServerBytesReceivedRegister = new List(); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _keyExchangeMock = new Mock(MockBehavior.Strict); - _clientAuthenticationMock = new Mock(MockBehavior.Strict); - - Session = new Session(ConnectionInfo, _serviceFactoryMock.Object); - Session.Disconnected += (sender, args) => DisconnectedRegister.Add(args); - Session.DisconnectReceived += (sender, args) => DisconnectReceivedRegister.Add(args); - Session.ErrorOccured += (sender, args) => ErrorOccurredRegister.Add(args); - Session.KeyExchangeInitReceived += (sender, args) => - { - var newKeysMessage = new NewKeysMessage(); - var newKeys = newKeysMessage.GetPacket(8, null); - ServerSocket.Send(newKeys, 4, newKeys.Length - 4, SocketFlags.None); - }; - - _serviceFactoryMock.Setup( - p => - p.CreateKeyExchange(ConnectionInfo.KeyExchangeAlgorithms, new[] {_keyExchangeAlgorithm})).Returns(_keyExchangeMock.Object); - _keyExchangeMock.Setup(p => p.Name).Returns(_keyExchangeAlgorithm); - _keyExchangeMock.Setup(p => p.Start(Session, It.IsAny())); - _keyExchangeMock.Setup(p => p.ExchangeHash).Returns(SessionId); - _keyExchangeMock.Setup(p => p.CreateServerCipher()).Returns((Cipher) null); - _keyExchangeMock.Setup(p => p.CreateClientCipher()).Returns((Cipher) null); - _keyExchangeMock.Setup(p => p.CreateServerHash()).Returns((HashAlgorithm) null); - _keyExchangeMock.Setup(p => p.CreateClientHash()).Returns((HashAlgorithm) null); - _keyExchangeMock.Setup(p => p.CreateCompressor()).Returns((Compressor) null); - _keyExchangeMock.Setup(p => p.CreateDecompressor()).Returns((Compressor) null); - _keyExchangeMock.Setup(p => p.Dispose()); - _serviceFactoryMock.Setup(p => p.CreateClientAuthentication()).Callback(ClientAuthentication_Callback).Returns(_clientAuthenticationMock.Object); - _clientAuthenticationMock.Setup(p => p.Authenticate(ConnectionInfo, Session)); - - ServerListener = new AsyncSocketListener(_serverEndPoint); - ServerListener.Connected += socket => - { - ServerSocket = socket; - - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Send(Encoding.ASCII.GetBytes("SSH-2.0-SshStub\r\n")); - }; - - var counter = 0; - - ServerListener.BytesReceived += (received, socket) => - { - ServerBytesReceivedRegister.Add(received); - - switch (counter++) - { - case 0: - var keyExchangeInitMessage = new KeyExchangeInitMessage - { - CompressionAlgorithmsClientToServer = new string[0], - CompressionAlgorithmsServerToClient = new string[0], - EncryptionAlgorithmsClientToServer = new string[0], - EncryptionAlgorithmsServerToClient = new string[0], - KeyExchangeAlgorithms = new[] {_keyExchangeAlgorithm}, - LanguagesClientToServer = new string[0], - LanguagesServerToClient = new string[0], - MacAlgorithmsClientToServer = new string[0], - MacAlgorithmsServerToClient = new string[0], - ServerHostKeyAlgorithms = new string[0] - }; - var keyExchangeInit = keyExchangeInitMessage.GetPacket(8, null); - ServerSocket.Send(keyExchangeInit, 4, keyExchangeInit.Length - 4, SocketFlags.None); - break; - case 1: - var serviceAcceptMessage = - ServiceAcceptMessageBuilder.Create(ServiceName.UserAuthentication) - .Build(); - ServerSocket.Send(serviceAcceptMessage, 0, serviceAcceptMessage.Length, SocketFlags.None); - break; - } - }; - ServerListener.Start(); - - Session.Connect(); - } - - protected virtual void ClientAuthentication_Callback() - { - } - - protected abstract void Act(); - - private class ServiceAcceptMessageBuilder - { - private readonly ServiceName _serviceName; - - private ServiceAcceptMessageBuilder(ServiceName serviceName) - { - _serviceName = serviceName; - } - - public static ServiceAcceptMessageBuilder Create(ServiceName serviceName) - { - return new ServiceAcceptMessageBuilder(serviceName); - } - - public byte[] Build() - { - var serviceName = _serviceName.ToArray(); - - var sshDataStream = new SshDataStream(4 + 1 + 1 + 4 + serviceName.Length); - sshDataStream.Write((uint)(sshDataStream.Capacity - 4)); // packet length - sshDataStream.WriteByte(0); // padding length - sshDataStream.WriteByte(ServiceAcceptMessage.MessageNumber); - sshDataStream.WriteBinary(serviceName); - return sshDataStream.ToArray(); - } - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using System.Net.Sockets; +using System.Security.Cryptography; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Compression; +using Renci.SshNet.Messages; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Security; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public abstract class SessionTest_ConnectedBase + { + private Mock _serviceFactoryMock; + private Mock _keyExchangeMock; + private Mock _clientAuthenticationMock; + private IPEndPoint _serverEndPoint; + private string _keyExchangeAlgorithm; + + protected Random Random { get; private set; } + protected byte[] SessionId { get; private set; } + protected ConnectionInfo ConnectionInfo { get; private set; } + protected IList DisconnectedRegister { get; private set; } + protected IList> DisconnectReceivedRegister { get; private set; } + protected IList ErrorOccurredRegister { get; private set; } + protected AsyncSocketListener ServerListener { get; private set; } + protected IList ServerBytesReceivedRegister { get; private set; } + protected Session Session { get; private set; } + protected Socket ServerSocket { get; private set; } + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void TearDown() + { + if (ServerListener != null) + { + ServerListener.Dispose(); + } + + if (Session != null) + { + Session.Dispose(); + } + } + + protected virtual void Arrange() + { + Random = new Random(); + + _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + ConnectionInfo = new ConnectionInfo( + _serverEndPoint.Address.ToString(), + _serverEndPoint.Port, + "user", + new PasswordAuthenticationMethod("user", "password")); + ConnectionInfo.Timeout = TimeSpan.FromSeconds(20); + _keyExchangeAlgorithm = Random.Next().ToString(CultureInfo.InvariantCulture); + SessionId = new byte[10]; + Random.NextBytes(SessionId); + DisconnectedRegister = new List(); + DisconnectReceivedRegister = new List>(); + ErrorOccurredRegister = new List(); + ServerBytesReceivedRegister = new List(); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _keyExchangeMock = new Mock(MockBehavior.Strict); + _clientAuthenticationMock = new Mock(MockBehavior.Strict); + + Session = new Session(ConnectionInfo, _serviceFactoryMock.Object); + Session.Disconnected += (sender, args) => DisconnectedRegister.Add(args); + Session.DisconnectReceived += (sender, args) => DisconnectReceivedRegister.Add(args); + Session.ErrorOccured += (sender, args) => ErrorOccurredRegister.Add(args); + Session.KeyExchangeInitReceived += (sender, args) => + { + var newKeysMessage = new NewKeysMessage(); + var newKeys = newKeysMessage.GetPacket(8, null); + ServerSocket.Send(newKeys, 4, newKeys.Length - 4, SocketFlags.None); + }; + + _serviceFactoryMock.Setup( + p => + p.CreateKeyExchange(ConnectionInfo.KeyExchangeAlgorithms, new[] {_keyExchangeAlgorithm})).Returns(_keyExchangeMock.Object); + _keyExchangeMock.Setup(p => p.Name).Returns(_keyExchangeAlgorithm); + _keyExchangeMock.Setup(p => p.Start(Session, It.IsAny())); + _keyExchangeMock.Setup(p => p.ExchangeHash).Returns(SessionId); + _keyExchangeMock.Setup(p => p.CreateServerCipher()).Returns((Cipher) null); + _keyExchangeMock.Setup(p => p.CreateClientCipher()).Returns((Cipher) null); + _keyExchangeMock.Setup(p => p.CreateServerHash()).Returns((HashAlgorithm) null); + _keyExchangeMock.Setup(p => p.CreateClientHash()).Returns((HashAlgorithm) null); + _keyExchangeMock.Setup(p => p.CreateCompressor()).Returns((Compressor) null); + _keyExchangeMock.Setup(p => p.CreateDecompressor()).Returns((Compressor) null); + _keyExchangeMock.Setup(p => p.Dispose()); + _serviceFactoryMock.Setup(p => p.CreateClientAuthentication()).Callback(ClientAuthentication_Callback).Returns(_clientAuthenticationMock.Object); + _clientAuthenticationMock.Setup(p => p.Authenticate(ConnectionInfo, Session)); + + ServerListener = new AsyncSocketListener(_serverEndPoint); + ServerListener.Connected += socket => + { + ServerSocket = socket; + + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Send(Encoding.ASCII.GetBytes("SSH-2.0-SshStub\r\n")); + }; + + var counter = 0; + + ServerListener.BytesReceived += (received, socket) => + { + ServerBytesReceivedRegister.Add(received); + + switch (counter++) + { + case 0: + var keyExchangeInitMessage = new KeyExchangeInitMessage + { + CompressionAlgorithmsClientToServer = new string[0], + CompressionAlgorithmsServerToClient = new string[0], + EncryptionAlgorithmsClientToServer = new string[0], + EncryptionAlgorithmsServerToClient = new string[0], + KeyExchangeAlgorithms = new[] {_keyExchangeAlgorithm}, + LanguagesClientToServer = new string[0], + LanguagesServerToClient = new string[0], + MacAlgorithmsClientToServer = new string[0], + MacAlgorithmsServerToClient = new string[0], + ServerHostKeyAlgorithms = new string[0] + }; + var keyExchangeInit = keyExchangeInitMessage.GetPacket(8, null); + ServerSocket.Send(keyExchangeInit, 4, keyExchangeInit.Length - 4, SocketFlags.None); + break; + case 1: + var serviceAcceptMessage = + ServiceAcceptMessageBuilder.Create(ServiceName.UserAuthentication) + .Build(); + ServerSocket.Send(serviceAcceptMessage, 0, serviceAcceptMessage.Length, SocketFlags.None); + break; + } + }; + ServerListener.Start(); + + Session.Connect(); + } + + protected virtual void ClientAuthentication_Callback() + { + } + + protected abstract void Act(); + + private class ServiceAcceptMessageBuilder + { + private readonly ServiceName _serviceName; + + private ServiceAcceptMessageBuilder(ServiceName serviceName) + { + _serviceName = serviceName; + } + + public static ServiceAcceptMessageBuilder Create(ServiceName serviceName) + { + return new ServiceAcceptMessageBuilder(serviceName); + } + + public byte[] Build() + { + var serviceName = _serviceName.ToArray(); + + var sshDataStream = new SshDataStream(4 + 1 + 1 + 4 + serviceName.Length); + sshDataStream.Write((uint)(sshDataStream.Capacity - 4)); // packet length + sshDataStream.WriteByte(0); // padding length + sshDataStream.WriteByte(ServiceAcceptMessage.MessageNumber); + sshDataStream.WriteBinary(serviceName); + return sshDataStream.ToArray(); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs index bd94eba1..6587a710 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs @@ -1,168 +1,168 @@ -using System.Diagnostics; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_ConnectionReset : SessionTest_ConnectedBase - { - protected override void Act() - { - ServerSocket.Close(); - - // give session some time to react to connection reset - Thread.Sleep(200); - } - - [TestMethodAttribute] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethodAttribute] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectReceivedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredIsRaisedOnce() - { - Assert.AreEqual(1, ErrorOccurredRegister.Count); - - var errorOccurred = ErrorOccurredRegister[0]; - Assert.IsNotNull(errorOccurred); - - var exception = errorOccurred.Exception; - Assert.IsNotNull(exception); - Assert.AreEqual(typeof(SshConnectionException), exception.GetType()); - - var connectionException = (SshConnectionException) exception; - Assert.AreEqual(DisconnectReason.ConnectionLost, connectionException.DisconnectReason); - - var innerException = exception.InnerException; - Assert.IsNotNull(innerException); - Assert.AreEqual(typeof(SocketException), innerException.GetType()); - - var socketException = (SocketException) innerException; - Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode); - - Assert.AreSame(innerException.Message, connectionException.Message); - } - - [TestMethodAttribute] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethodAttribute] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethodAttribute] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession) Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethodAttribute] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession) Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethodAttribute] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingConnectionReset() - { - var session = (ISession) Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.ConnectionLost, ex.DisconnectReason); - - var innerException = ex.InnerException; - Assert.IsNotNull(innerException); - Assert.AreEqual(typeof(SocketException), innerException.GetType()); - - var socketException = (SocketException)ex.InnerException; - Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode); - - Assert.AreSame(innerException.Message, ex.Message); - - } - } - } -} +using System.Diagnostics; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_ConnectionReset : SessionTest_ConnectedBase + { + protected override void Act() + { + ServerSocket.Close(); + + // give session some time to react to connection reset + Thread.Sleep(200); + } + + [TestMethodAttribute] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethodAttribute] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectReceivedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredIsRaisedOnce() + { + Assert.AreEqual(1, ErrorOccurredRegister.Count); + + var errorOccurred = ErrorOccurredRegister[0]; + Assert.IsNotNull(errorOccurred); + + var exception = errorOccurred.Exception; + Assert.IsNotNull(exception); + Assert.AreEqual(typeof(SshConnectionException), exception.GetType()); + + var connectionException = (SshConnectionException) exception; + Assert.AreEqual(DisconnectReason.ConnectionLost, connectionException.DisconnectReason); + + var innerException = exception.InnerException; + Assert.IsNotNull(innerException); + Assert.AreEqual(typeof(SocketException), innerException.GetType()); + + var socketException = (SocketException) innerException; + Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode); + + Assert.AreSame(innerException.Message, connectionException.Message); + } + + [TestMethodAttribute] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethodAttribute] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethodAttribute] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession) Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethodAttribute] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession) Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethodAttribute] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingConnectionReset() + { + var session = (ISession) Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.ConnectionLost, ex.DisconnectReason); + + var innerException = ex.InnerException; + Assert.IsNotNull(innerException); + Assert.AreEqual(typeof(SocketException), innerException.GetType()); + + var socketException = (SocketException)ex.InnerException; + Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode); + + Assert.AreSame(innerException.Message, ex.Message); + + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_Disconnect.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_Disconnect.cs index 99f676f7..cf2827cc 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_Disconnect.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_Disconnect.cs @@ -1,148 +1,148 @@ -using System.Diagnostics; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_Disconnect : SessionTest_ConnectedBase - { - protected override void Act() - { - Session.Disconnect(); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethod] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectReceivedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredIsNeverRaised() - { - Assert.AreEqual(0, ErrorOccurredRegister.Count); - } - - [TestMethod] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void ReceiveOnServerSocketShouldReturnZero() - { - var buffer = new byte[1]; - - var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); - - Assert.AreEqual(0, actual); - } - - [TestMethod] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession)Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession) Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingBadPacket() - { - var session = (ISession) Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } -} +using System.Diagnostics; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_Disconnect : SessionTest_ConnectedBase + { + protected override void Act() + { + Session.Disconnect(); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethod] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectReceivedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredIsNeverRaised() + { + Assert.AreEqual(0, ErrorOccurredRegister.Count); + } + + [TestMethod] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void ReceiveOnServerSocketShouldReturnZero() + { + var buffer = new byte[1]; + + var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); + + Assert.AreEqual(0, actual); + } + + [TestMethod] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession)Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession) Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingBadPacket() + { + var session = (ISession) Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs index 6b29f75f..b55f87c4 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs @@ -1,164 +1,164 @@ -using System.Diagnostics; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_ServerSendsBadPacket : SessionTest_ConnectedBase - { - protected override void Act() - { - var badPacket = new byte[] { 0x0a, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05 }; - ServerSocket.Send(badPacket, 0, badPacket.Length, SocketFlags.None); - - // give session some time to react to bad packet - Thread.Sleep(200); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethod] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectReceivedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredIsRaisedOnce() - { - Assert.AreEqual(1, ErrorOccurredRegister.Count); - - var errorOccurred = ErrorOccurredRegister[0]; - Assert.IsNotNull(errorOccurred); - - var exception = errorOccurred.Exception; - Assert.IsNotNull(exception); - Assert.AreEqual(typeof (SshConnectionException), exception.GetType()); - - var connectionException = (SshConnectionException) exception; - Assert.AreEqual(DisconnectReason.ProtocolError, connectionException.DisconnectReason); - Assert.IsNull(connectionException.InnerException); - Assert.AreEqual("Bad packet length: 168101125.", connectionException.Message); - } - - [TestMethod] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void ReceiveOnServerSocketShouldReturnZero() - { - var buffer = new byte[1]; - - var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); - - Assert.AreEqual(0, actual); - } - - [TestMethod] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession)Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession) Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingBadPacket() - { - var session = (ISession) Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.ProtocolError, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Bad packet length: 168101125.", ex.Message); - } - } - } -} +using System.Diagnostics; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_ServerSendsBadPacket : SessionTest_ConnectedBase + { + protected override void Act() + { + var badPacket = new byte[] { 0x0a, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05 }; + ServerSocket.Send(badPacket, 0, badPacket.Length, SocketFlags.None); + + // give session some time to react to bad packet + Thread.Sleep(200); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethod] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectReceivedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredIsRaisedOnce() + { + Assert.AreEqual(1, ErrorOccurredRegister.Count); + + var errorOccurred = ErrorOccurredRegister[0]; + Assert.IsNotNull(errorOccurred); + + var exception = errorOccurred.Exception; + Assert.IsNotNull(exception); + Assert.AreEqual(typeof (SshConnectionException), exception.GetType()); + + var connectionException = (SshConnectionException) exception; + Assert.AreEqual(DisconnectReason.ProtocolError, connectionException.DisconnectReason); + Assert.IsNull(connectionException.InnerException); + Assert.AreEqual("Bad packet length: 168101125.", connectionException.Message); + } + + [TestMethod] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void ReceiveOnServerSocketShouldReturnZero() + { + var buffer = new byte[1]; + + var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); + + Assert.AreEqual(0, actual); + } + + [TestMethod] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession)Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession) Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingBadPacket() + { + var session = (ISession) Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.ProtocolError, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Bad packet length: 168101125.", ex.Message); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessage.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessage.cs index 4a69acbd..c47b444e 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessage.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessage.cs @@ -1,168 +1,168 @@ -using System.Diagnostics; -using System.Globalization; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_ServerSendsDisconnectMessage : SessionTest_ConnectedBase - { - private DisconnectMessage _disconnectMessage; - - protected override void Arrange() - { - _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!"); - - base.Arrange(); - } - - protected override void Act() - { - var disconnect = _disconnectMessage.GetPacket(8, null); - ServerSocket.Send(disconnect, 4, disconnect.Length - 4, SocketFlags.None); - - // give session some time to process DisconnectMessage - Thread.Sleep(200); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethod] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsRaisedOnce() - { - Assert.AreEqual(1, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsRaisedOnce() - { - Assert.AreEqual(1, DisconnectReceivedRegister.Count); - - var disconnectMessage = DisconnectReceivedRegister[0].Message; - Assert.IsNotNull(disconnectMessage); - Assert.AreEqual(_disconnectMessage.Description, disconnectMessage.Description); - Assert.AreEqual("en", disconnectMessage.Language); - Assert.AreEqual(_disconnectMessage.ReasonCode, disconnectMessage.ReasonCode); - } - - [TestMethod] - public void ErrorOccurredIsNeverRaised() - { - Assert.AreEqual(0, ErrorOccurredRegister.Count); - } - - [TestMethod] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void ReceiveOnServerSocketShouldReturnZero() - { - var buffer = new byte[1]; - - var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); - - Assert.AreEqual(0, actual); - } - - [TestMethod] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession)Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession) Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingDisconnectReason() - { - var session = (ISession)Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.ServiceNotAvailable, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "The connection was closed by the server: {0} ({1}).", _disconnectMessage.Description, _disconnectMessage.ReasonCode), ex.Message); - } - } - } -} +using System.Diagnostics; +using System.Globalization; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_ServerSendsDisconnectMessage : SessionTest_ConnectedBase + { + private DisconnectMessage _disconnectMessage; + + protected override void Arrange() + { + _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!"); + + base.Arrange(); + } + + protected override void Act() + { + var disconnect = _disconnectMessage.GetPacket(8, null); + ServerSocket.Send(disconnect, 4, disconnect.Length - 4, SocketFlags.None); + + // give session some time to process DisconnectMessage + Thread.Sleep(200); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethod] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsRaisedOnce() + { + Assert.AreEqual(1, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsRaisedOnce() + { + Assert.AreEqual(1, DisconnectReceivedRegister.Count); + + var disconnectMessage = DisconnectReceivedRegister[0].Message; + Assert.IsNotNull(disconnectMessage); + Assert.AreEqual(_disconnectMessage.Description, disconnectMessage.Description); + Assert.AreEqual("en", disconnectMessage.Language); + Assert.AreEqual(_disconnectMessage.ReasonCode, disconnectMessage.ReasonCode); + } + + [TestMethod] + public void ErrorOccurredIsNeverRaised() + { + Assert.AreEqual(0, ErrorOccurredRegister.Count); + } + + [TestMethod] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void ReceiveOnServerSocketShouldReturnZero() + { + var buffer = new byte[1]; + + var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); + + Assert.AreEqual(0, actual); + } + + [TestMethod] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession)Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession) Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingDisconnectReason() + { + var session = (ISession)Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.ServiceNotAvailable, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "The connection was closed by the server: {0} ({1}).", _disconnectMessage.Description, _disconnectMessage.ReasonCode), ex.Message); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket.cs index b1e073c9..f6c9152f 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket.cs @@ -1,172 +1,172 @@ -using System.Diagnostics; -using System.Globalization; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket : SessionTest_ConnectedBase - { - private DisconnectMessage _disconnectMessage; - - protected override void Arrange() - { - _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!"); - - base.Arrange(); - } - - protected override void Act() - { - // server sends SSH_MSG_DISCONNECT - var disconnect = _disconnectMessage.GetPacket(8, null); - ServerSocket.Send(disconnect, 4, disconnect.Length - 4, SocketFlags.None); - - // server shuts down the socket - ServerSocket.Shutdown(SocketShutdown.Send); - - // give session some time to process DisconnectMessage and socket shutdown - Thread.Sleep(200); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethod] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsRaisedOnce() - { - Assert.AreEqual(1, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsRaisedOnce() - { - Assert.AreEqual(1, DisconnectReceivedRegister.Count); - - var disconnectMessage = DisconnectReceivedRegister[0].Message; - Assert.IsNotNull(disconnectMessage); - Assert.AreEqual(_disconnectMessage.Description, disconnectMessage.Description); - Assert.AreEqual("en", disconnectMessage.Language); - Assert.AreEqual(_disconnectMessage.ReasonCode, disconnectMessage.ReasonCode); - } - - [TestMethod] - public void ErrorOccurredIsNeverRaised() - { - Assert.AreEqual(0, ErrorOccurredRegister.Count); - } - - [TestMethod] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void ReceiveOnServerSocketShouldReturnZero() - { - var buffer = new byte[1]; - - var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); - - Assert.AreEqual(0, actual); - } - - [TestMethod] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession)Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession)Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingDisconnectReason() - { - var session = (ISession)Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.ServiceNotAvailable, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "The connection was closed by the server: {0} ({1}).", _disconnectMessage.Description, _disconnectMessage.ReasonCode), ex.Message); - } - } - } -} +using System.Diagnostics; +using System.Globalization; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket : SessionTest_ConnectedBase + { + private DisconnectMessage _disconnectMessage; + + protected override void Arrange() + { + _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!"); + + base.Arrange(); + } + + protected override void Act() + { + // server sends SSH_MSG_DISCONNECT + var disconnect = _disconnectMessage.GetPacket(8, null); + ServerSocket.Send(disconnect, 4, disconnect.Length - 4, SocketFlags.None); + + // server shuts down the socket + ServerSocket.Shutdown(SocketShutdown.Send); + + // give session some time to process DisconnectMessage and socket shutdown + Thread.Sleep(200); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethod] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsRaisedOnce() + { + Assert.AreEqual(1, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsRaisedOnce() + { + Assert.AreEqual(1, DisconnectReceivedRegister.Count); + + var disconnectMessage = DisconnectReceivedRegister[0].Message; + Assert.IsNotNull(disconnectMessage); + Assert.AreEqual(_disconnectMessage.Description, disconnectMessage.Description); + Assert.AreEqual("en", disconnectMessage.Language); + Assert.AreEqual(_disconnectMessage.ReasonCode, disconnectMessage.ReasonCode); + } + + [TestMethod] + public void ErrorOccurredIsNeverRaised() + { + Assert.AreEqual(0, ErrorOccurredRegister.Count); + } + + [TestMethod] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void ReceiveOnServerSocketShouldReturnZero() + { + var buffer = new byte[1]; + + var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); + + Assert.AreEqual(0, actual); + } + + [TestMethod] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession)Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession)Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingDisconnectReason() + { + var session = (ISession)Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.ServiceNotAvailable, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "The connection was closed by the server: {0} ({1}).", _disconnectMessage.Description, _disconnectMessage.ReasonCode), ex.Message); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs index a7a7867c..fd6755f4 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs @@ -1,161 +1,161 @@ -using System; -using System.Diagnostics; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_ServerShutsDownSocket : SessionTest_ConnectedBase - { - protected override void Act() - { - ServerSocket.Shutdown(SocketShutdown.Send); - - // give session some time to process socket shutdown - Thread.Sleep(200); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethod] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectReceivedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredIsRaisedOnce() - { - Assert.AreEqual(1, ErrorOccurredRegister.Count); - - var errorOccurred = ErrorOccurredRegister[0]; - Assert.IsNotNull(errorOccurred); - - var exception = errorOccurred.Exception; - Assert.IsNotNull(exception); - Assert.AreEqual(typeof(SshConnectionException), exception.GetType()); - - var connectionException = (SshConnectionException) exception; - Assert.AreEqual(DisconnectReason.ConnectionLost, connectionException.DisconnectReason); - Assert.IsNull(connectionException.InnerException); - Assert.AreEqual("An established connection was aborted by the server.", connectionException.Message); - } - - [TestMethod] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void ReceiveOnServerSocketShouldReturnZero() - { - var buffer = new byte[1]; - - var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); - - Assert.AreEqual(0, actual); - } - - [TestMethod] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession)Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession)Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingAbortedConnection() - { - var session = (ISession)Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("An established connection was aborted by the server.", ex.Message); - } - } - } -} +using System; +using System.Diagnostics; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_ServerShutsDownSocket : SessionTest_ConnectedBase + { + protected override void Act() + { + ServerSocket.Shutdown(SocketShutdown.Send); + + // give session some time to process socket shutdown + Thread.Sleep(200); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethod] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectReceivedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredIsRaisedOnce() + { + Assert.AreEqual(1, ErrorOccurredRegister.Count); + + var errorOccurred = ErrorOccurredRegister[0]; + Assert.IsNotNull(errorOccurred); + + var exception = errorOccurred.Exception; + Assert.IsNotNull(exception); + Assert.AreEqual(typeof(SshConnectionException), exception.GetType()); + + var connectionException = (SshConnectionException) exception; + Assert.AreEqual(DisconnectReason.ConnectionLost, connectionException.DisconnectReason); + Assert.IsNull(connectionException.InnerException); + Assert.AreEqual("An established connection was aborted by the server.", connectionException.Message); + } + + [TestMethod] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void ReceiveOnServerSocketShouldReturnZero() + { + var buffer = new byte[1]; + + var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); + + Assert.AreEqual(0, actual); + } + + [TestMethod] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession)Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession)Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingAbortedConnection() + { + var session = (ISession)Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("An established connection was aborted by the server.", ex.Message); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs index 44cbd7d6..4638b698 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs @@ -1,191 +1,191 @@ -using System; -using System.Net; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_NotConnected - { - private ConnectionInfo _connectionInfo; - private IServiceFactory _serviceFactory; - private Session _session; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - _connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); - _serviceFactory = new Mock(MockBehavior.Strict).Object; - } - - protected void Act() - { - _session = new Session(_connectionInfo, _serviceFactory); - } - - [TestMethod] - public void ClientVersionIsRenciSshNet() - { - Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", _session.ClientVersion); - } - - [TestMethod] - public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() - { - Assert.AreSame(_connectionInfo, _session.ConnectionInfo); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(_session.IsConnected); - } - - [TestMethod] - public void SendMessageShouldThrowShhConnectionException() - { - try - { - _session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void SessionIdShouldReturnNull() - { - Assert.IsNull(_session.SessionId); - } - - [TestMethod] - public void ServerVersionShouldReturnNull() - { - Assert.IsNull(_session.ServerVersion); - } - - [TestMethod] - public void WaitOnHandle_WaitHandle_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - - try - { - _session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - - [TestMethod] - public void WaitOnHandle_WaitHandleAndTimeout_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - var timeout = TimeSpan.FromMinutes(5); - - try - { - _session.WaitOnHandle(waitHandle, timeout); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - - [TestMethod] - public void ISession_ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() - { - var session = (ISession)_session; - Assert.AreSame(_connectionInfo, session.ConnectionInfo); - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession) _session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne(0)); - } - - [TestMethod] - public void ISession_SendMessageShouldThrowShhConnectionException() - { - var session = (ISession)_session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession)_session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - var session = (ISession)_session; - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - - private static ConnectionInfo CreateConnectionInfo(IPEndPoint serverEndPoint, TimeSpan timeout) - { - var connectionInfo = new ConnectionInfo( - serverEndPoint.Address.ToString(), - serverEndPoint.Port, - "eric", - new NoneAuthenticationMethod("eric")); - connectionInfo.Timeout = timeout; - return connectionInfo; - } - } -} +using System; +using System.Net; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_NotConnected + { + private ConnectionInfo _connectionInfo; + private IServiceFactory _serviceFactory; + private Session _session; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + _connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); + _serviceFactory = new Mock(MockBehavior.Strict).Object; + } + + protected void Act() + { + _session = new Session(_connectionInfo, _serviceFactory); + } + + [TestMethod] + public void ClientVersionIsRenciSshNet() + { + Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", _session.ClientVersion); + } + + [TestMethod] + public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() + { + Assert.AreSame(_connectionInfo, _session.ConnectionInfo); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(_session.IsConnected); + } + + [TestMethod] + public void SendMessageShouldThrowShhConnectionException() + { + try + { + _session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void SessionIdShouldReturnNull() + { + Assert.IsNull(_session.SessionId); + } + + [TestMethod] + public void ServerVersionShouldReturnNull() + { + Assert.IsNull(_session.ServerVersion); + } + + [TestMethod] + public void WaitOnHandle_WaitHandle_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + + try + { + _session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + + [TestMethod] + public void WaitOnHandle_WaitHandleAndTimeout_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + var timeout = TimeSpan.FromMinutes(5); + + try + { + _session.WaitOnHandle(waitHandle, timeout); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + + [TestMethod] + public void ISession_ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() + { + var session = (ISession)_session; + Assert.AreSame(_connectionInfo, session.ConnectionInfo); + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession) _session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne(0)); + } + + [TestMethod] + public void ISession_SendMessageShouldThrowShhConnectionException() + { + var session = (ISession)_session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession)_session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + var session = (ISession)_session; + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + + private static ConnectionInfo CreateConnectionInfo(IPEndPoint serverEndPoint, TimeSpan timeout) + { + var connectionInfo = new ConnectionInfo( + serverEndPoint.Address.ToString(), + serverEndPoint.Port, + "eric", + new NoneAuthenticationMethod("eric")); + connectionInfo.Timeout = timeout; + return connectionInfo; + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_SocketConnected_BadPacketAndDispose.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_SocketConnected_BadPacketAndDispose.cs index 985e5087..a13de281 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_SocketConnected_BadPacketAndDispose.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_SocketConnected_BadPacketAndDispose.cs @@ -1,95 +1,95 @@ -using System; -using System.Net; -using System.Net.Sockets; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_SocketConnected_BadPacketAndDispose - { - private Mock _serviceFactoryMock; - private ConnectionInfo _connectionInfo; - private Session _session; - private AsyncSocketListener _serverListener; - private IPEndPoint _serverEndPoint; - private Socket _serverSocket; - private SshConnectionException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void TearDown() - { - if (_serverListener != null) - { - _serverListener.Dispose(); - } - } - - protected void Arrange() - { - _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - _connectionInfo = new ConnectionInfo( - _serverEndPoint.Address.ToString(), - _serverEndPoint.Port, - "user", - new PasswordAuthenticationMethod("user", "password")); - _connectionInfo.Timeout = TimeSpan.FromMilliseconds(200); - _actualException = null; - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - - _serverListener = new AsyncSocketListener(_serverEndPoint); - _serverListener.Connected += (socket) => - { - _serverSocket = socket; - - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Send(Encoding.ASCII.GetBytes("SSH-2.0-SshStub\r\n")); - }; - _serverListener.BytesReceived += (received, socket) => - { - var badPacket = new byte[] {0x0a, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05}; - _serverSocket.Send(badPacket, 0, badPacket.Length, SocketFlags.None); - _serverSocket.Shutdown(SocketShutdown.Send); - }; - _serverListener.Start(); - } - - protected virtual void Act() - { - try - { - using (_session = new Session(_connectionInfo, _serviceFactoryMock.Object)) - { - _session.Connect(); - } - } - catch (SshConnectionException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void ConnectShouldThrowSshConnectionException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual(DisconnectReason.ProtocolError, _actualException.DisconnectReason); - Assert.AreEqual("Bad packet length: 168101125.", _actualException.Message); - } - } -} +using System; +using System.Net; +using System.Net.Sockets; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_SocketConnected_BadPacketAndDispose + { + private Mock _serviceFactoryMock; + private ConnectionInfo _connectionInfo; + private Session _session; + private AsyncSocketListener _serverListener; + private IPEndPoint _serverEndPoint; + private Socket _serverSocket; + private SshConnectionException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void TearDown() + { + if (_serverListener != null) + { + _serverListener.Dispose(); + } + } + + protected void Arrange() + { + _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + _connectionInfo = new ConnectionInfo( + _serverEndPoint.Address.ToString(), + _serverEndPoint.Port, + "user", + new PasswordAuthenticationMethod("user", "password")); + _connectionInfo.Timeout = TimeSpan.FromMilliseconds(200); + _actualException = null; + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + + _serverListener = new AsyncSocketListener(_serverEndPoint); + _serverListener.Connected += (socket) => + { + _serverSocket = socket; + + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Send(Encoding.ASCII.GetBytes("SSH-2.0-SshStub\r\n")); + }; + _serverListener.BytesReceived += (received, socket) => + { + var badPacket = new byte[] {0x0a, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05}; + _serverSocket.Send(badPacket, 0, badPacket.Length, SocketFlags.None); + _serverSocket.Shutdown(SocketShutdown.Send); + }; + _serverListener.Start(); + } + + protected virtual void Act() + { + try + { + using (_session = new Session(_connectionInfo, _serviceFactoryMock.Object)) + { + _session.Connect(); + } + } + catch (SshConnectionException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void ConnectShouldThrowSshConnectionException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual(DisconnectReason.ProtocolError, _actualException.DisconnectReason); + Assert.AreEqual("Bad packet length: 168101125.", _actualException.Message); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs index ba139e9d..bad627f2 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs @@ -1,123 +1,123 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests -{ - [TestClass] - public class FStatVfsRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private string _name; - private byte[] _nameBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - - _name = "fstatvfs@openssh.com"; - _nameBytes = Encoding.UTF8.GetBytes(_name); - } - - [TestMethod] - public void Constructor() - { - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_name, request.Name); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - IList extendedReplyActionInvocations = new List(); - - Action extendedAction = extendedReplyActionInvocations.Add; - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, extendedReplyActionInvocations.Count); - } - - [TestMethod] - public void Complete_SftpExtendedReplyResponse() - { - IList statusActionInvocations = new List(); - IList extendedReplyActionInvocations = new List(); - - Action extendedAction = extendedReplyActionInvocations.Add; - Action statusAction = statusActionInvocations.Add; - var extendedReplyResponse = new SftpExtendedReplyResponse(_protocolVersion); - - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction); - - request.Complete(extendedReplyResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, extendedReplyActionInvocations.Count); - Assert.AreSame(extendedReplyResponse, extendedReplyActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Name length - expectedBytesLength += _nameBytes.Length; // Name - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); - - var actualNameBytes = new byte[_nameBytes.Length]; - sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); - Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests +{ + [TestClass] + public class FStatVfsRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private string _name; + private byte[] _nameBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + + _name = "fstatvfs@openssh.com"; + _nameBytes = Encoding.UTF8.GetBytes(_name); + } + + [TestMethod] + public void Constructor() + { + var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_name, request.Name); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + IList extendedReplyActionInvocations = new List(); + + Action extendedAction = extendedReplyActionInvocations.Add; + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, extendedReplyActionInvocations.Count); + } + + [TestMethod] + public void Complete_SftpExtendedReplyResponse() + { + IList statusActionInvocations = new List(); + IList extendedReplyActionInvocations = new List(); + + Action extendedAction = extendedReplyActionInvocations.Add; + Action statusAction = statusActionInvocations.Add; + var extendedReplyResponse = new SftpExtendedReplyResponse(_protocolVersion); + + var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction); + + request.Complete(extendedReplyResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, extendedReplyActionInvocations.Count); + Assert.AreSame(extendedReplyResponse, extendedReplyActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Name length + expectedBytesLength += _nameBytes.Length; // Name + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); + + var actualNameBytes = new byte[_nameBytes.Length]; + sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); + Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs index 8282f52d..787f9904 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs @@ -1,116 +1,116 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests -{ - [TestClass] - public class HardLinkRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private string _name; - private string _oldPath; - private byte[] _oldPathBytes; - private string _newPath; - private byte[] _newPathBytes; - private byte[] _nameBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); - _oldPathBytes = Encoding.UTF8.GetBytes(_oldPath); - _newPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newPathBytes = Encoding.UTF8.GetBytes(_newPath); - - _name = "hardlink@openssh.com"; - _nameBytes = Encoding.UTF8.GetBytes(_name); - } - - [TestMethod] - public void Constructor() - { - var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); - - Assert.AreEqual(_name, request.Name); - Assert.AreEqual(_newPath, request.NewPath); - Assert.AreEqual(_oldPath, request.OldPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Name length - expectedBytesLength += _nameBytes.Length; // Name - expectedBytesLength += 4; // OldPath length - expectedBytesLength += _oldPathBytes.Length; // OldPath - expectedBytesLength += 4; // NewPath length - expectedBytesLength += _newPathBytes.Length; // NewPath - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); - - var actualNameBytes = new byte[_nameBytes.Length]; - sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); - Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); - - Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); - - var actualOldPath = new byte[_oldPathBytes.Length]; - sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); - Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); - - Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); - - var actualNewPath = new byte[_newPathBytes.Length]; - sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); - Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests +{ + [TestClass] + public class HardLinkRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private string _name; + private string _oldPath; + private byte[] _oldPathBytes; + private string _newPath; + private byte[] _newPathBytes; + private byte[] _nameBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); + _oldPathBytes = Encoding.UTF8.GetBytes(_oldPath); + _newPath = random.Next().ToString(CultureInfo.InvariantCulture); + _newPathBytes = Encoding.UTF8.GetBytes(_newPath); + + _name = "hardlink@openssh.com"; + _nameBytes = Encoding.UTF8.GetBytes(_name); + } + + [TestMethod] + public void Constructor() + { + var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); + + Assert.AreEqual(_name, request.Name); + Assert.AreEqual(_newPath, request.NewPath); + Assert.AreEqual(_oldPath, request.OldPath); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Name length + expectedBytesLength += _nameBytes.Length; // Name + expectedBytesLength += 4; // OldPath length + expectedBytesLength += _oldPathBytes.Length; // OldPath + expectedBytesLength += 4; // NewPath length + expectedBytesLength += _newPathBytes.Length; // NewPath + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); + + var actualNameBytes = new byte[_nameBytes.Length]; + sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); + Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); + + Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); + + var actualOldPath = new byte[_oldPathBytes.Length]; + sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); + Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); + + Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); + + var actualNewPath = new byte[_newPathBytes.Length]; + sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); + Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/PosixRenameRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/PosixRenameRequestTest.cs index c9edf3bd..60cc1d03 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/PosixRenameRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/PosixRenameRequestTest.cs @@ -1,120 +1,120 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests -{ - [TestClass] - public class PosixRenameRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private string _name; - private string _oldPath; - private byte[] _oldPathBytes; - private string _newPath; - private byte[] _newPathBytes; - private byte[] _nameBytes; - private Encoding _encoding; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _encoding = Encoding.Unicode; - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); - _oldPathBytes = _encoding.GetBytes(_oldPath); - _newPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newPathBytes = _encoding.GetBytes(_newPath); - - _name = "posix-rename@openssh.com"; - _nameBytes = Encoding.UTF8.GetBytes(_name); - } - - [TestMethod] - public void Constructor() - { - var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_name, request.Name); - Assert.AreEqual(_newPath, request.NewPath); - Assert.AreEqual(_oldPath, request.OldPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Name length - expectedBytesLength += _nameBytes.Length; // Name - expectedBytesLength += 4; // OldPath length - expectedBytesLength += _oldPathBytes.Length; // OldPath - expectedBytesLength += 4; // NewPath length - expectedBytesLength += _newPathBytes.Length; // NewPath - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); - - var actualNameBytes = new byte[_nameBytes.Length]; - sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); - Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); - - Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); - - var actualOldPath = new byte[_oldPathBytes.Length]; - sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); - Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); - - Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); - - var actualNewPath = new byte[_newPathBytes.Length]; - sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); - Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests +{ + [TestClass] + public class PosixRenameRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private string _name; + private string _oldPath; + private byte[] _oldPathBytes; + private string _newPath; + private byte[] _newPathBytes; + private byte[] _nameBytes; + private Encoding _encoding; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _encoding = Encoding.Unicode; + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); + _oldPathBytes = _encoding.GetBytes(_oldPath); + _newPath = random.Next().ToString(CultureInfo.InvariantCulture); + _newPathBytes = _encoding.GetBytes(_newPath); + + _name = "posix-rename@openssh.com"; + _nameBytes = Encoding.UTF8.GetBytes(_name); + } + + [TestMethod] + public void Constructor() + { + var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_name, request.Name); + Assert.AreEqual(_newPath, request.NewPath); + Assert.AreEqual(_oldPath, request.OldPath); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Name length + expectedBytesLength += _nameBytes.Length; // Name + expectedBytesLength += 4; // OldPath length + expectedBytesLength += _oldPathBytes.Length; // OldPath + expectedBytesLength += 4; // NewPath length + expectedBytesLength += _newPathBytes.Length; // NewPath + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); + + var actualNameBytes = new byte[_nameBytes.Length]; + sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); + Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); + + Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); + + var actualOldPath = new byte[_oldPathBytes.Length]; + sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); + Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); + + Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); + + var actualNewPath = new byte[_newPathBytes.Length]; + sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); + Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/StatVfsRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/StatVfsRequestTest.cs index 5dd1e9a8..89d315f3 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/StatVfsRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/StatVfsRequestTest.cs @@ -1,129 +1,129 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests -{ - [TestClass] - public class StatVfsRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private string _name; - private string _path; - private byte[] _pathBytes; - private byte[] _nameBytes; - private Encoding _encoding; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _encoding = Encoding.Unicode; - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - - _name = "statvfs@openssh.com"; - _nameBytes = Encoding.UTF8.GetBytes(_name); - } - - [TestMethod] - public void Constructor() - { - var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_name, request.Name); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - IList extendedReplyActionInvocations = new List(); - - Action extendedAction = extendedReplyActionInvocations.Add; - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, extendedAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, extendedReplyActionInvocations.Count); - } - - [TestMethod] - public void Complete_SftpExtendedReplyResponse() - { - IList statusActionInvocations = new List(); - IList extendedReplyActionInvocations = new List(); - - Action extendedAction = extendedReplyActionInvocations.Add; - Action statusAction = statusActionInvocations.Add; - var extendedReplyResponse = new SftpExtendedReplyResponse(_protocolVersion); - - var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, extendedAction, statusAction); - - request.Complete(extendedReplyResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, extendedReplyActionInvocations.Count); - Assert.AreSame(extendedReplyResponse, extendedReplyActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Name length - expectedBytesLength += _nameBytes.Length; // Name - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); - - var actualNameBytes = new byte[_nameBytes.Length]; - sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); - Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests +{ + [TestClass] + public class StatVfsRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private string _name; + private string _path; + private byte[] _pathBytes; + private byte[] _nameBytes; + private Encoding _encoding; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _encoding = Encoding.Unicode; + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + + _name = "statvfs@openssh.com"; + _nameBytes = Encoding.UTF8.GetBytes(_name); + } + + [TestMethod] + public void Constructor() + { + var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_name, request.Name); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + IList extendedReplyActionInvocations = new List(); + + Action extendedAction = extendedReplyActionInvocations.Add; + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, extendedAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, extendedReplyActionInvocations.Count); + } + + [TestMethod] + public void Complete_SftpExtendedReplyResponse() + { + IList statusActionInvocations = new List(); + IList extendedReplyActionInvocations = new List(); + + Action extendedAction = extendedReplyActionInvocations.Add; + Action statusAction = statusActionInvocations.Add; + var extendedReplyResponse = new SftpExtendedReplyResponse(_protocolVersion); + + var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, extendedAction, statusAction); + + request.Complete(extendedReplyResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, extendedReplyActionInvocations.Count); + Assert.AreSame(extendedReplyResponse, extendedReplyActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Name length + expectedBytesLength += _nameBytes.Length; // Name + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); + + var actualNameBytes = new byte[_nameBytes.Length]; + sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); + Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs index a62472ff..22100993 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs @@ -1,102 +1,102 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpBlockRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private ulong _offset; - private ulong _length; - private uint _lockMask; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _offset = (ulong) random.Next(0, int.MaxValue); - _length = (ulong) random.Next(0, int.MaxValue); - _lockMask = (uint) random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_length, request.Length); - Assert.AreEqual(_lockMask, request.LockMask); - Assert.AreEqual(_offset, request.Offset); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Block, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += 8; // Offset - expectedBytesLength += 8; // Length - expectedBytesLength += 4; // LockMask - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Block, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); - Assert.AreEqual(_length, sshDataStream.ReadUInt64()); - Assert.AreEqual(_lockMask, sshDataStream.ReadUInt32()); - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpBlockRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private ulong _offset; + private ulong _length; + private uint _lockMask; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + _offset = (ulong) random.Next(0, int.MaxValue); + _length = (ulong) random.Next(0, int.MaxValue); + _lockMask = (uint) random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_length, request.Length); + Assert.AreEqual(_lockMask, request.LockMask); + Assert.AreEqual(_offset, request.Offset); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Block, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + expectedBytesLength += 8; // Offset + expectedBytesLength += 8; // Length + expectedBytesLength += 4; // LockMask + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Block, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); + Assert.AreEqual(_length, sshDataStream.ReadUInt64()); + Assert.AreEqual(_lockMask, sshDataStream.ReadUInt32()); + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpCloseRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpCloseRequestTest.cs index 8fe79c6f..3959af33 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpCloseRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpCloseRequestTest.cs @@ -1,87 +1,87 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpCloseRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Close, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Close, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpCloseRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Close, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Close, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFSetStatRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFSetStatRequestTest.cs index 01b81331..a91797ed 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFSetStatRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFSetStatRequestTest.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpFSetStatRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private SftpFileAttributes _attributes; - private byte[] _attributesBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _attributes = SftpFileAttributes.Empty; - _attributesBytes = _attributes.GetBytes(); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.FSetStat, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += _attributesBytes.Length; // Attributes - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.FSetStat, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - var actualAttributes = new byte[_attributesBytes.Length]; - sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); - Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpFSetStatRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private SftpFileAttributes _attributes; + private byte[] _attributesBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + _attributes = SftpFileAttributes.Empty; + _attributesBytes = _attributes.GetBytes(); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.FSetStat, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + expectedBytesLength += _attributesBytes.Length; // Attributes + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.FSetStat, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + var actualAttributes = new byte[_attributesBytes.Length]; + sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); + Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFStatRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFStatRequestTest.cs index 5ff1dd04..03cf64a9 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFStatRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFStatRequestTest.cs @@ -1,109 +1,109 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpFStatRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, null, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.FStat, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpAttrsResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var attrsResponse = new SftpAttrsResponse(_protocolVersion); - - var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, attrsAction, statusAction); - - request.Complete(attrsResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, attrsActionInvocations.Count); - Assert.AreSame(attrsResponse, attrsActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, attrsAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, attrsActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.FStat, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpFStatRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, null, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.FStat, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpAttrsResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var attrsResponse = new SftpAttrsResponse(_protocolVersion); + + var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, attrsAction, statusAction); + + request.Complete(attrsResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, attrsActionInvocations.Count); + Assert.AreSame(attrsResponse, attrsActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, attrsAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, attrsActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.FStat, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpInitRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpInitRequestTest.cs index 704c6982..4f039b1f 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpInitRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpInitRequestTest.cs @@ -1,10 +1,10 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpInitRequestTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpInitRequestTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLStatRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLStatRequestTest.cs index 878b18a2..08313b05 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLStatRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLStatRequestTest.cs @@ -1,115 +1,115 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpLStatRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _encoding = Encoding.Unicode; - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.LStat, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpAttrsResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var attrsResponse = new SftpAttrsResponse(_protocolVersion); - - var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); - - request.Complete(attrsResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, attrsActionInvocations.Count); - Assert.AreSame(attrsResponse, attrsActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, attrsActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Pah length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.LStat, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpLStatRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _encoding = Encoding.Unicode; + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.LStat, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpAttrsResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var attrsResponse = new SftpAttrsResponse(_protocolVersion); + + var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); + + request.Complete(attrsResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, attrsActionInvocations.Count); + Assert.AreSame(attrsResponse, attrsActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, attrsActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Pah length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.LStat, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs index 77b94645..eba2f249 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs @@ -1,110 +1,110 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpLinkRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private string _newLinkPath; - private byte[] _newLinkPathBytes; - private string _existingPath; - private byte[] _existingPathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _newLinkPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newLinkPathBytes = Encoding.UTF8.GetBytes(_newLinkPath); - _existingPath = random.Next().ToString(CultureInfo.InvariantCulture); - _existingPathBytes = Encoding.UTF8.GetBytes(_existingPath); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, null); - - Assert.AreEqual(_existingPath, request.ExistingPath); - Assert.IsTrue(request.IsSymLink); - Assert.AreEqual(_newLinkPath, request.NewLinkPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Link, request.SftpMessageType); - - request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, false, null); - - Assert.IsFalse(request.IsSymLink); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // NewLinkPath length - expectedBytesLength += _newLinkPathBytes.Length; // NewLinkPath - expectedBytesLength += 4; // ExistingPath length - expectedBytesLength += _existingPathBytes.Length; // ExistingPath - expectedBytesLength += 1; // IsSymLink - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Link, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _newLinkPathBytes.Length, sshDataStream.ReadUInt32()); - var actualNewLinkPath = new byte[_newLinkPathBytes.Length]; - sshDataStream.Read(actualNewLinkPath, 0, actualNewLinkPath.Length); - Assert.IsTrue(_newLinkPathBytes.SequenceEqual(actualNewLinkPath)); - - Assert.AreEqual((uint) _existingPathBytes.Length, sshDataStream.ReadUInt32()); - var actualExistingPath = new byte[_existingPathBytes.Length]; - sshDataStream.Read(actualExistingPath, 0, actualExistingPath.Length); - Assert.IsTrue(_existingPathBytes.SequenceEqual(actualExistingPath)); - - Assert.AreEqual(1, sshDataStream.ReadByte()); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpLinkRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private string _newLinkPath; + private byte[] _newLinkPathBytes; + private string _existingPath; + private byte[] _existingPathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _newLinkPath = random.Next().ToString(CultureInfo.InvariantCulture); + _newLinkPathBytes = Encoding.UTF8.GetBytes(_newLinkPath); + _existingPath = random.Next().ToString(CultureInfo.InvariantCulture); + _existingPathBytes = Encoding.UTF8.GetBytes(_existingPath); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, null); + + Assert.AreEqual(_existingPath, request.ExistingPath); + Assert.IsTrue(request.IsSymLink); + Assert.AreEqual(_newLinkPath, request.NewLinkPath); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Link, request.SftpMessageType); + + request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, false, null); + + Assert.IsFalse(request.IsSymLink); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // NewLinkPath length + expectedBytesLength += _newLinkPathBytes.Length; // NewLinkPath + expectedBytesLength += 4; // ExistingPath length + expectedBytesLength += _existingPathBytes.Length; // ExistingPath + expectedBytesLength += 1; // IsSymLink + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Link, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _newLinkPathBytes.Length, sshDataStream.ReadUInt32()); + var actualNewLinkPath = new byte[_newLinkPathBytes.Length]; + sshDataStream.Read(actualNewLinkPath, 0, actualNewLinkPath.Length); + Assert.IsTrue(_newLinkPathBytes.SequenceEqual(actualNewLinkPath)); + + Assert.AreEqual((uint) _existingPathBytes.Length, sshDataStream.ReadUInt32()); + var actualExistingPath = new byte[_existingPathBytes.Length]; + sshDataStream.Read(actualExistingPath, 0, actualExistingPath.Length); + Assert.IsTrue(_existingPathBytes.SequenceEqual(actualExistingPath)); + + Assert.AreEqual(1, sshDataStream.ReadByte()); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpMkDirRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpMkDirRequestTest.cs index e3bed2fb..d8a3a9eb 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpMkDirRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpMkDirRequestTest.cs @@ -1,102 +1,102 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpMkDirRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - private SftpFileAttributes _attributes; - private byte[] _attributesBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - _attributes = SftpFileAttributes.Empty; - _attributesBytes = _attributes.GetBytes(); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.MkDir, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - expectedBytesLength += _attributesBytes.Length; // Attributes - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.MkDir, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - var actualAttributes = new byte[_attributesBytes.Length]; - sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); - Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpMkDirRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + private SftpFileAttributes _attributes; + private byte[] _attributesBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + _attributes = SftpFileAttributes.Empty; + _attributesBytes = _attributes.GetBytes(); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.MkDir, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + expectedBytesLength += _attributesBytes.Length; // Attributes + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.MkDir, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + var actualAttributes = new byte[_attributesBytes.Length]; + sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); + Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenRequestTest.cs index 5a4a1c70..9a82ae8e 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenRequestTest.cs @@ -1,143 +1,143 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpOpenRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _filename; - private byte[] _filenameBytes; - private Flags _flags; - private SftpFileAttributes _attributes; - private byte[] _attributesBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _filename = random.Next().ToString(CultureInfo.InvariantCulture); - _filenameBytes = _encoding.GetBytes(_filename); - _flags = Flags.Read; - _attributes = SftpFileAttributes.Empty; - _attributesBytes = _attributes.GetBytes(); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpOpenRequest(_protocolVersion, _requestId, _filename, _encoding, _flags, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_filename, request.Filename); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Open, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpHandleResponse() - { - var statusActionInvocations = new List(); - var handleActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action handleAction = handleActionInvocations.Add; - var handleResponse = new SftpHandleResponse(_protocolVersion); - - var request = new SftpOpenRequest( - _protocolVersion, - _requestId, - _filename, - _encoding, - _flags, - handleAction, - statusAction); - - request.Complete(handleResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, handleActionInvocations.Count); - Assert.AreSame(handleResponse, handleActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var handleActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action handleAction = handleActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpOpenRequest( - _protocolVersion, - _requestId, - _filename, - _encoding, - _flags, - handleAction, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, handleActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpOpenRequest(_protocolVersion, _requestId, _filename, _encoding, _flags, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Filename length - expectedBytesLength += _filenameBytes.Length; // Filename - expectedBytesLength += 4; // Flags - expectedBytesLength += _attributesBytes.Length; // Attributes - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Open, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _filenameBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_filenameBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_filenameBytes.SequenceEqual(actualPath)); - - Assert.AreEqual((uint) _flags, sshDataStream.ReadUInt32()); - - var actualAttributes = new byte[_attributesBytes.Length]; - sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); - Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpOpenRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _filename; + private byte[] _filenameBytes; + private Flags _flags; + private SftpFileAttributes _attributes; + private byte[] _attributesBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _filename = random.Next().ToString(CultureInfo.InvariantCulture); + _filenameBytes = _encoding.GetBytes(_filename); + _flags = Flags.Read; + _attributes = SftpFileAttributes.Empty; + _attributesBytes = _attributes.GetBytes(); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpOpenRequest(_protocolVersion, _requestId, _filename, _encoding, _flags, null, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_filename, request.Filename); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Open, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpHandleResponse() + { + var statusActionInvocations = new List(); + var handleActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action handleAction = handleActionInvocations.Add; + var handleResponse = new SftpHandleResponse(_protocolVersion); + + var request = new SftpOpenRequest( + _protocolVersion, + _requestId, + _filename, + _encoding, + _flags, + handleAction, + statusAction); + + request.Complete(handleResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, handleActionInvocations.Count); + Assert.AreSame(handleResponse, handleActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var handleActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action handleAction = handleActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpOpenRequest( + _protocolVersion, + _requestId, + _filename, + _encoding, + _flags, + handleAction, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, handleActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpOpenRequest(_protocolVersion, _requestId, _filename, _encoding, _flags, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Filename length + expectedBytesLength += _filenameBytes.Length; // Filename + expectedBytesLength += 4; // Flags + expectedBytesLength += _attributesBytes.Length; // Attributes + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Open, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _filenameBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_filenameBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_filenameBytes.SequenceEqual(actualPath)); + + Assert.AreEqual((uint) _flags, sshDataStream.ReadUInt32()); + + var actualAttributes = new byte[_attributesBytes.Length]; + sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); + Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadDirRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadDirRequestTest.cs index 020c4f7c..01b21ed1 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadDirRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadDirRequestTest.cs @@ -1,110 +1,110 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpReadDirRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, null, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.ReadDir, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpAttrsResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); - - var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, nameAction, statusAction); - - request.Complete(nameResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, nameActionInvocations.Count); - Assert.AreSame(nameResponse, nameActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, nameAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, nameActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.ReadDir, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpReadDirRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, null, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.ReadDir, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpAttrsResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); + + var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, nameAction, statusAction); + + request.Complete(nameResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, nameActionInvocations.Count); + Assert.AreSame(nameResponse, nameActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, nameAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, nameActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.ReadDir, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs index 3f03f766..04dccf7b 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs @@ -1,128 +1,128 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpReadLinkRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpReadLinkRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.ReadLink, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpNameResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); - - var request = new SftpReadLinkRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - request.Complete(nameResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, nameActionInvocations.Count); - Assert.AreSame(nameResponse, nameActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpReadLinkRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, nameActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpReadLinkRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.ReadLink, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } - +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpReadLinkRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpReadLinkRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.ReadLink, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpNameResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); + + var request = new SftpReadLinkRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + nameAction, + statusAction); + + request.Complete(nameResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, nameActionInvocations.Count); + Assert.AreSame(nameResponse, nameActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpReadLinkRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + nameAction, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, nameActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpReadLinkRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.ReadLink, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } + } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadRequestTest.cs index 36e3ad6a..6d4dc882 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadRequestTest.cs @@ -1,134 +1,134 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpReadRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private ulong _offset; - private uint _length; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _offset = (ulong) random.Next(0, int.MaxValue); - _length = (uint) random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpReadRequest(_protocolVersion, _requestId, _handle, _offset, _length, null, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_length, request.Length); - Assert.AreEqual(_offset, request.Offset); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Read, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpDataResponse() - { - var statusActionInvocations = new List(); - var dataActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action dataAction = dataActionInvocations.Add; - var dataResponse = new SftpDataResponse(_protocolVersion); - - var request = new SftpReadRequest( - _protocolVersion, - _requestId, - _handle, - _offset, - _length, - dataAction, - statusAction); - - request.Complete(dataResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, dataActionInvocations.Count); - Assert.AreSame(dataResponse, dataActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var dataActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action dataAction = dataActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpReadRequest( - _protocolVersion, - _requestId, - _handle, - _offset, - _length, - dataAction, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, dataActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpReadRequest(_protocolVersion, _requestId, _handle, _offset, _length, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += 8; // Offset - expectedBytesLength += 4; // Length - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Read, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); - Assert.AreEqual(_length, sshDataStream.ReadUInt32()); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpReadRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private ulong _offset; + private uint _length; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + _offset = (ulong) random.Next(0, int.MaxValue); + _length = (uint) random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpReadRequest(_protocolVersion, _requestId, _handle, _offset, _length, null, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_length, request.Length); + Assert.AreEqual(_offset, request.Offset); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Read, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpDataResponse() + { + var statusActionInvocations = new List(); + var dataActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action dataAction = dataActionInvocations.Add; + var dataResponse = new SftpDataResponse(_protocolVersion); + + var request = new SftpReadRequest( + _protocolVersion, + _requestId, + _handle, + _offset, + _length, + dataAction, + statusAction); + + request.Complete(dataResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, dataActionInvocations.Count); + Assert.AreSame(dataResponse, dataActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var dataActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action dataAction = dataActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpReadRequest( + _protocolVersion, + _requestId, + _handle, + _offset, + _length, + dataAction, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, dataActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpReadRequest(_protocolVersion, _requestId, _handle, _offset, _length, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + expectedBytesLength += 8; // Offset + expectedBytesLength += 4; // Length + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Read, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); + Assert.AreEqual(_length, sshDataStream.ReadUInt32()); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRealPathRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRealPathRequestTest.cs index fc3cb13a..1ee8653c 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRealPathRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRealPathRequestTest.cs @@ -1,143 +1,143 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpRealPathRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - - var request = new SftpRealPathRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.RealPath, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpNameResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); - - var request = new SftpRealPathRequest(_protocolVersion, _requestId, _path, _encoding, nameAction, statusAction); - - request.Complete(nameResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, nameActionInvocations.Count); - Assert.AreSame(nameResponse, nameActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpRealPathRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, nameActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var request = new SftpRealPathRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.RealPath, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpRealPathRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + } + + [TestMethod] + public void Constructor() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + + var request = new SftpRealPathRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + nameAction, + statusAction); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.RealPath, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpNameResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); + + var request = new SftpRealPathRequest(_protocolVersion, _requestId, _path, _encoding, nameAction, statusAction); + + request.Complete(nameResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, nameActionInvocations.Count); + Assert.AreSame(nameResponse, nameActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpRealPathRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + nameAction, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, nameActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var request = new SftpRealPathRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + nameAction, + statusAction); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.RealPath, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRemoveRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRemoveRequestTest.cs index 9db8db2b..b0910c56 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRemoveRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRemoveRequestTest.cs @@ -1,93 +1,93 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpRemoveRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _filename; - private byte[] _filenameBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _filename = random.Next().ToString(CultureInfo.InvariantCulture); - _filenameBytes = _encoding.GetBytes(_filename); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_filename, request.Filename); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Remove, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Filename length - expectedBytesLength += _filenameBytes.Length; // Filename - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Remove, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _filenameBytes.Length, sshDataStream.ReadUInt32()); - var actualFilename = new byte[_filenameBytes.Length]; - sshDataStream.Read(actualFilename, 0, actualFilename.Length); - Assert.IsTrue(_filenameBytes.SequenceEqual(actualFilename)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpRemoveRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _filename; + private byte[] _filenameBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _filename = random.Next().ToString(CultureInfo.InvariantCulture); + _filenameBytes = _encoding.GetBytes(_filename); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_filename, request.Filename); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Remove, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Filename length + expectedBytesLength += _filenameBytes.Length; // Filename + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Remove, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _filenameBytes.Length, sshDataStream.ReadUInt32()); + var actualFilename = new byte[_filenameBytes.Length]; + sshDataStream.Read(actualFilename, 0, actualFilename.Length); + Assert.IsTrue(_filenameBytes.SequenceEqual(actualFilename)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRenameRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRenameRequestTest.cs index ce4e235f..0225e505 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRenameRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRenameRequestTest.cs @@ -1,105 +1,105 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpRenameRequestTest : TestBase - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _oldPath; - private byte[] _oldPathBytes; - private string _newPath; - private byte[] _newPathBytes; - - protected override void OnInit() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); - _oldPathBytes = _encoding.GetBytes(_oldPath); - _newPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newPathBytes = _encoding.GetBytes(_newPath); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_newPath, request.NewPath); - Assert.AreEqual(_oldPath, request.OldPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Rename, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // OldPath length - expectedBytesLength += _oldPathBytes.Length; // OldPath - expectedBytesLength += 4; // NewPath length - expectedBytesLength += _newPathBytes.Length; // NewPath - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Rename, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); - var actualOldPath = new byte[_oldPathBytes.Length]; - sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); - Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); - - Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); - var actualNewPath = new byte[_newPathBytes.Length]; - sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); - Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpRenameRequestTest : TestBase + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _oldPath; + private byte[] _oldPathBytes; + private string _newPath; + private byte[] _newPathBytes; + + protected override void OnInit() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); + _oldPathBytes = _encoding.GetBytes(_oldPath); + _newPath = random.Next().ToString(CultureInfo.InvariantCulture); + _newPathBytes = _encoding.GetBytes(_newPath); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_newPath, request.NewPath); + Assert.AreEqual(_oldPath, request.OldPath); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Rename, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // OldPath length + expectedBytesLength += _oldPathBytes.Length; // OldPath + expectedBytesLength += 4; // NewPath length + expectedBytesLength += _newPathBytes.Length; // NewPath + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Rename, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); + var actualOldPath = new byte[_oldPathBytes.Length]; + sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); + Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); + + Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); + var actualNewPath = new byte[_newPathBytes.Length]; + sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); + Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRmDirRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRmDirRequestTest.cs index 8cfbdda9..bd7f12c3 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRmDirRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRmDirRequestTest.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpRmDirRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.RmDir, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.RmDir, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpRmDirRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.RmDir, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.RmDir, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSetStatRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSetStatRequestTest.cs index eb6694cf..7c1bb454 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSetStatRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSetStatRequestTest.cs @@ -1,107 +1,107 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpSetStatRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - private SftpFileAttributes _attributes; - private byte[] _attributesBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - _attributes = SftpFileAttributes.Empty; - _attributesBytes = _attributes.GetBytes(); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpSetStatRequest(_protocolVersion, _requestId, _path, _encoding, _attributes, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.SetStat, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpSetStatRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - _attributes, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpSetStatRequest(_protocolVersion, _requestId, _path, _encoding, _attributes, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - expectedBytesLength += _attributesBytes.Length; // Attributes - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.SetStat, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - var actualAttributes = new byte[_attributesBytes.Length]; - sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); - Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpSetStatRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + private SftpFileAttributes _attributes; + private byte[] _attributesBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + _attributes = SftpFileAttributes.Empty; + _attributesBytes = _attributes.GetBytes(); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpSetStatRequest(_protocolVersion, _requestId, _path, _encoding, _attributes, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.SetStat, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpSetStatRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + _attributes, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpSetStatRequest(_protocolVersion, _requestId, _path, _encoding, _attributes, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + expectedBytesLength += _attributesBytes.Length; // Attributes + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.SetStat, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + var actualAttributes = new byte[_attributesBytes.Length]; + sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); + Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpStatRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpStatRequestTest.cs index e0870493..8f6e9a31 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpStatRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpStatRequestTest.cs @@ -1,113 +1,113 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpStatRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Stat, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpAttrsResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var attrsResponse = new SftpAttrsResponse(_protocolVersion); - - var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); - - request.Complete(attrsResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, attrsActionInvocations.Count); - Assert.AreSame(attrsResponse, attrsActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreEqual(0, attrsActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Stat, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpStatRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Stat, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpAttrsResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var attrsResponse = new SftpAttrsResponse(_protocolVersion); + + var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); + + request.Complete(attrsResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, attrsActionInvocations.Count); + Assert.AreSame(attrsResponse, attrsActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreEqual(0, attrsActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Stat, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSymLinkRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSymLinkRequestTest.cs index 8bc97087..8b9a6e6c 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSymLinkRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSymLinkRequestTest.cs @@ -1,123 +1,123 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpSymLinkRequestTest : TestBase - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _newLinkPath; - private byte[] _newLinkPathBytes; - private string _existingPath; - private byte[] _existingPathBytes; - - protected override void OnInit() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _newLinkPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newLinkPathBytes = _encoding.GetBytes(_newLinkPath); - _existingPath = random.Next().ToString(CultureInfo.InvariantCulture); - _existingPathBytes = _encoding.GetBytes(_existingPath); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpSymLinkRequest( - _protocolVersion, - _requestId, - _newLinkPath, - _existingPath, - _encoding, - null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_existingPath, request.ExistingPath); - Assert.AreEqual(_newLinkPath, request.NewLinkPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.SymLink, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpSymLinkRequest( - _protocolVersion, - _requestId, - _newLinkPath, - _existingPath, - _encoding, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpSymLinkRequest( - _protocolVersion, - _requestId, - _newLinkPath, - _existingPath, - _encoding, - null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // NewLinkPath length - expectedBytesLength += _newLinkPathBytes.Length; // NewLinkPath - expectedBytesLength += 4; // ExistingPath length - expectedBytesLength += _existingPathBytes.Length; // ExistingPath - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.SymLink, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _newLinkPathBytes.Length, sshDataStream.ReadUInt32()); - var actualNewLinkPath = new byte[_newLinkPathBytes.Length]; - sshDataStream.Read(actualNewLinkPath, 0, actualNewLinkPath.Length); - Assert.IsTrue(_newLinkPathBytes.SequenceEqual(actualNewLinkPath)); - - Assert.AreEqual((uint) _existingPathBytes.Length, sshDataStream.ReadUInt32()); - var actualExistingPath = new byte[_existingPathBytes.Length]; - sshDataStream.Read(actualExistingPath, 0, actualExistingPath.Length); - Assert.IsTrue(_existingPathBytes.SequenceEqual(actualExistingPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpSymLinkRequestTest : TestBase + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _newLinkPath; + private byte[] _newLinkPathBytes; + private string _existingPath; + private byte[] _existingPathBytes; + + protected override void OnInit() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _newLinkPath = random.Next().ToString(CultureInfo.InvariantCulture); + _newLinkPathBytes = _encoding.GetBytes(_newLinkPath); + _existingPath = random.Next().ToString(CultureInfo.InvariantCulture); + _existingPathBytes = _encoding.GetBytes(_existingPath); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpSymLinkRequest( + _protocolVersion, + _requestId, + _newLinkPath, + _existingPath, + _encoding, + null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_existingPath, request.ExistingPath); + Assert.AreEqual(_newLinkPath, request.NewLinkPath); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.SymLink, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpSymLinkRequest( + _protocolVersion, + _requestId, + _newLinkPath, + _existingPath, + _encoding, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpSymLinkRequest( + _protocolVersion, + _requestId, + _newLinkPath, + _existingPath, + _encoding, + null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // NewLinkPath length + expectedBytesLength += _newLinkPathBytes.Length; // NewLinkPath + expectedBytesLength += 4; // ExistingPath length + expectedBytesLength += _existingPathBytes.Length; // ExistingPath + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.SymLink, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _newLinkPathBytes.Length, sshDataStream.ReadUInt32()); + var actualNewLinkPath = new byte[_newLinkPathBytes.Length]; + sshDataStream.Read(actualNewLinkPath, 0, actualNewLinkPath.Length); + Assert.IsTrue(_newLinkPathBytes.SequenceEqual(actualNewLinkPath)); + + Assert.AreEqual((uint) _existingPathBytes.Length, sshDataStream.ReadUInt32()); + var actualExistingPath = new byte[_existingPathBytes.Length]; + sshDataStream.Read(actualExistingPath, 0, actualExistingPath.Length); + Assert.IsTrue(_existingPathBytes.SequenceEqual(actualExistingPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs index 6cbe4aa6..40ea7c3d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpUnblockRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private ulong _offset; - private ulong _length; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _offset = (ulong) random.Next(0, int.MaxValue); - _length = (ulong) random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Unblock, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += 8; // Offset - expectedBytesLength += 8; // Length - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Unblock, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); - Assert.AreEqual(_length, sshDataStream.ReadUInt64()); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpUnblockRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private ulong _offset; + private ulong _length; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + _offset = (ulong) random.Next(0, int.MaxValue); + _length = (ulong) random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Unblock, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + expectedBytesLength += 8; // Offset + expectedBytesLength += 8; // Length + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Unblock, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); + Assert.AreEqual(_length, sshDataStream.ReadUInt64()); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpWriteRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpWriteRequestTest.cs index 096355c0..68531c9b 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpWriteRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpWriteRequestTest.cs @@ -1,112 +1,112 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpWriteRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private ulong _offset; - private byte[] _data; - private int _length; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _offset = (ulong) random.Next(0, int.MaxValue); - _data = new byte[random.Next(5, 10)]; - random.NextBytes(_data); - _length = random.Next(1, 4); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _offset, _data, _length, null); - - Assert.AreSame(_data, request.Data); - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_length, request.Length); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Write, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpWriteRequest( - _protocolVersion, - _requestId, - _handle, - _offset, - _data, - _length, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _offset, _data, _length, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += 8; // Offset - expectedBytesLength += 4; // Data length - expectedBytesLength += _length; // Data - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Write, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); - - Assert.AreEqual((uint) _length, sshDataStream.ReadUInt32()); - var actualData = new byte[_length]; - sshDataStream.Read(actualData, 0, actualData.Length); - Assert.IsTrue(_data.Take(_length).SequenceEqual(actualData)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpWriteRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private ulong _offset; + private byte[] _data; + private int _length; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + _offset = (ulong) random.Next(0, int.MaxValue); + _data = new byte[random.Next(5, 10)]; + random.NextBytes(_data); + _length = random.Next(1, 4); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _offset, _data, _length, null); + + Assert.AreSame(_data, request.Data); + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_length, request.Length); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Write, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpWriteRequest( + _protocolVersion, + _requestId, + _handle, + _offset, + _data, + _length, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _offset, _data, _length, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + expectedBytesLength += 8; // Offset + expectedBytesLength += 4; // Data length + expectedBytesLength += _length; // Data + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Write, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); + + Assert.AreEqual((uint) _length, sshDataStream.ReadUInt32()); + var actualData = new byte[_length]; + sshDataStream.Read(actualData, 0, actualData.Length); + Assert.IsTrue(_data.Take(_length).SequenceEqual(actualData)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/ExtendedReplies/StatVfsReplyInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/ExtendedReplies/StatVfsReplyInfoTest.cs index 5788e683..14711feb 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/ExtendedReplies/StatVfsReplyInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/ExtendedReplies/StatVfsReplyInfoTest.cs @@ -1,90 +1,90 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class StatVfsReplyInfoTest - { - private Random _random; - private uint _responseId; - private ulong _bsize; - private ulong _frsize; - private ulong _blocks; - private ulong _bfree; - private ulong _bavail; - private ulong _files; - private ulong _ffree; - private ulong _favail; - private ulong _sid; - private ulong _namemax; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _responseId = (uint) _random.Next(0, int.MaxValue); - _bsize = (ulong) _random.Next(0, int.MaxValue); - _frsize = (ulong)_random.Next(0, int.MaxValue); - _blocks = (ulong)_random.Next(0, int.MaxValue); - _bfree = (ulong)_random.Next(0, int.MaxValue); - _bavail = (ulong)_random.Next(0, int.MaxValue); - _files = (ulong)_random.Next(0, int.MaxValue); - _ffree = (ulong)_random.Next(0, int.MaxValue); - _favail = (ulong)_random.Next(0, int.MaxValue); - _sid = (ulong)_random.Next(0, int.MaxValue); - _namemax = (ulong)_random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var target = new StatVfsReplyInfo(); - - Assert.IsNull(target.Information); - } - - [TestMethod] - public void Load() - { - var target = new StatVfsReplyInfo(); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); - sshDataStream.Write((uint) (sshDataStream.Capacity - 4)); - sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); - sshDataStream.Write(_responseId); - sshDataStream.Write(_bsize); - sshDataStream.Write(_frsize); - sshDataStream.Write(_blocks); - sshDataStream.Write(_bfree); - sshDataStream.Write(_bavail); - sshDataStream.Write(_files); - sshDataStream.Write(_ffree); - sshDataStream.Write(_favail); - sshDataStream.Write(_sid); - sshDataStream.Write((ulong) 0x1); - sshDataStream.Write(_namemax); - - target.Load(sshDataStream.ToArray()); - - Assert.IsNotNull(target.Information); - - var information = target.Information; - Assert.AreEqual(_bavail, information.AvailableBlocks); - Assert.AreEqual(_favail, information.AvailableNodes); - Assert.AreEqual(_frsize, information.BlockSize); - Assert.AreEqual(_bsize, information.FileSystemBlockSize); - Assert.AreEqual(_bfree, information.FreeBlocks); - Assert.AreEqual(_ffree, information.FreeNodes); - Assert.IsTrue(information.IsReadOnly); - Assert.AreEqual(_namemax, information.MaxNameLenght); - Assert.AreEqual(_sid, information.Sid); - Assert.IsTrue(information.SupportsSetUid); - Assert.AreEqual(_blocks, information.TotalBlocks); - Assert.AreEqual(_files, information.TotalNodes); - } - } +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class StatVfsReplyInfoTest + { + private Random _random; + private uint _responseId; + private ulong _bsize; + private ulong _frsize; + private ulong _blocks; + private ulong _bfree; + private ulong _bavail; + private ulong _files; + private ulong _ffree; + private ulong _favail; + private ulong _sid; + private ulong _namemax; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _responseId = (uint) _random.Next(0, int.MaxValue); + _bsize = (ulong) _random.Next(0, int.MaxValue); + _frsize = (ulong)_random.Next(0, int.MaxValue); + _blocks = (ulong)_random.Next(0, int.MaxValue); + _bfree = (ulong)_random.Next(0, int.MaxValue); + _bavail = (ulong)_random.Next(0, int.MaxValue); + _files = (ulong)_random.Next(0, int.MaxValue); + _ffree = (ulong)_random.Next(0, int.MaxValue); + _favail = (ulong)_random.Next(0, int.MaxValue); + _sid = (ulong)_random.Next(0, int.MaxValue); + _namemax = (ulong)_random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var target = new StatVfsReplyInfo(); + + Assert.IsNull(target.Information); + } + + [TestMethod] + public void Load() + { + var target = new StatVfsReplyInfo(); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); + sshDataStream.Write((uint) (sshDataStream.Capacity - 4)); + sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); + sshDataStream.Write(_responseId); + sshDataStream.Write(_bsize); + sshDataStream.Write(_frsize); + sshDataStream.Write(_blocks); + sshDataStream.Write(_bfree); + sshDataStream.Write(_bavail); + sshDataStream.Write(_files); + sshDataStream.Write(_ffree); + sshDataStream.Write(_favail); + sshDataStream.Write(_sid); + sshDataStream.Write((ulong) 0x1); + sshDataStream.Write(_namemax); + + target.Load(sshDataStream.ToArray()); + + Assert.IsNotNull(target.Information); + + var information = target.Information; + Assert.AreEqual(_bavail, information.AvailableBlocks); + Assert.AreEqual(_favail, information.AvailableNodes); + Assert.AreEqual(_frsize, information.BlockSize); + Assert.AreEqual(_bsize, information.FileSystemBlockSize); + Assert.AreEqual(_bfree, information.FreeBlocks); + Assert.AreEqual(_ffree, information.FreeNodes); + Assert.IsTrue(information.IsReadOnly); + Assert.AreEqual(_namemax, information.MaxNameLenght); + Assert.AreEqual(_sid, information.Sid); + Assert.IsTrue(information.SupportsSetUid); + Assert.AreEqual(_blocks, information.TotalBlocks); + Assert.AreEqual(_files, information.TotalNodes); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpAttrsResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpAttrsResponseTest.cs index 2ce13986..3e8840ef 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpAttrsResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpAttrsResponseTest.cs @@ -1,73 +1,73 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpAttrsResponseTest - { - private Random _random; - private uint _protocolVersion; - private uint _responseId; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _protocolVersion = (uint) _random.Next(0, int.MaxValue); - _responseId = (uint)_random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var target = new SftpAttrsResponse(_protocolVersion); - - Assert.IsNull(target.Attributes); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual((uint) 0, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType); - } - - [TestMethod] - public void Load() - { - var target = new SftpAttrsResponse(_protocolVersion); - var attributes = CreateSftpFileAttributes(); - var attributesBytes = attributes.GetBytes(); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + attributesBytes.Length); - sshDataStream.Position = 4; // skip 4 bytes for SSH packet length - sshDataStream.WriteByte((byte) SftpMessageTypes.Attrs); - sshDataStream.Write(_responseId); - sshDataStream.Write(attributesBytes, 0, attributesBytes.Length); - - target.Load(sshDataStream.ToArray()); - - Assert.IsNotNull(target.Attributes); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual(_responseId, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType); - - // check attributes in detail - Assert.AreEqual(attributes.GroupId, target.Attributes.GroupId); - Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime); - Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime); - Assert.AreEqual(attributes.UserId, target.Attributes.UserId); - } - - private SftpFileAttributes CreateSftpFileAttributes() - { - var attributes = SftpFileAttributes.Empty; - attributes.GroupId = _random.Next(); - attributes.LastAccessTime = new DateTime(2014, 8, 23, 17, 43, 50, DateTimeKind.Local); - attributes.LastWriteTime = new DateTime(2013, 7, 22, 16, 40, 42, DateTimeKind.Local); - attributes.UserId = _random.Next(); - return attributes; - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpAttrsResponseTest + { + private Random _random; + private uint _protocolVersion; + private uint _responseId; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _protocolVersion = (uint) _random.Next(0, int.MaxValue); + _responseId = (uint)_random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var target = new SftpAttrsResponse(_protocolVersion); + + Assert.IsNull(target.Attributes); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual((uint) 0, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType); + } + + [TestMethod] + public void Load() + { + var target = new SftpAttrsResponse(_protocolVersion); + var attributes = CreateSftpFileAttributes(); + var attributesBytes = attributes.GetBytes(); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + attributesBytes.Length); + sshDataStream.Position = 4; // skip 4 bytes for SSH packet length + sshDataStream.WriteByte((byte) SftpMessageTypes.Attrs); + sshDataStream.Write(_responseId); + sshDataStream.Write(attributesBytes, 0, attributesBytes.Length); + + target.Load(sshDataStream.ToArray()); + + Assert.IsNotNull(target.Attributes); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual(_responseId, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType); + + // check attributes in detail + Assert.AreEqual(attributes.GroupId, target.Attributes.GroupId); + Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime); + Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime); + Assert.AreEqual(attributes.UserId, target.Attributes.UserId); + } + + private SftpFileAttributes CreateSftpFileAttributes() + { + var attributes = SftpFileAttributes.Empty; + attributes.GroupId = _random.Next(); + attributes.LastAccessTime = new DateTime(2014, 8, 23, 17, 43, 50, DateTimeKind.Local); + attributes.LastWriteTime = new DateTime(2013, 7, 22, 16, 40, 42, DateTimeKind.Local); + attributes.UserId = _random.Next(); + return attributes; + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpDataResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpDataResponseTest.cs index 39bde628..33952f14 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpDataResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpDataResponseTest.cs @@ -1,60 +1,60 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpDataResponseTest - { - private Random _random; - private uint _protocolVersion; - private uint _responseId; - private byte[] _data; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _protocolVersion = (uint) _random.Next(0, int.MaxValue); - _responseId = (uint) _random.Next(0, int.MaxValue); - _data = new byte[_random.Next(10, 100)]; - _random.NextBytes(_data); - } - - [TestMethod] - public void Constructor() - { - var target = new SftpDataResponse(_protocolVersion); - - Assert.IsNull(target.Data); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual((uint) 0, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Data, target.SftpMessageType); - } - - [TestMethod] - public void Load() - { - var target = new SftpDataResponse(_protocolVersion); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + _data.Length); - sshDataStream.Position = 4; // skip 4 bytes for SSH packet length - sshDataStream.WriteByte((byte)SftpMessageTypes.Attrs); - sshDataStream.Write(_responseId); - sshDataStream.Write((uint) _data.Length); - sshDataStream.Write(_data, 0, _data.Length); - - target.Load(sshDataStream.ToArray()); - - Assert.IsNotNull(target.Data); - Assert.IsTrue(target.Data.SequenceEqual(_data)); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual(_responseId, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Data, target.SftpMessageType); - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpDataResponseTest + { + private Random _random; + private uint _protocolVersion; + private uint _responseId; + private byte[] _data; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _protocolVersion = (uint) _random.Next(0, int.MaxValue); + _responseId = (uint) _random.Next(0, int.MaxValue); + _data = new byte[_random.Next(10, 100)]; + _random.NextBytes(_data); + } + + [TestMethod] + public void Constructor() + { + var target = new SftpDataResponse(_protocolVersion); + + Assert.IsNull(target.Data); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual((uint) 0, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Data, target.SftpMessageType); + } + + [TestMethod] + public void Load() + { + var target = new SftpDataResponse(_protocolVersion); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + _data.Length); + sshDataStream.Position = 4; // skip 4 bytes for SSH packet length + sshDataStream.WriteByte((byte)SftpMessageTypes.Attrs); + sshDataStream.Write(_responseId); + sshDataStream.Write((uint) _data.Length); + sshDataStream.Write(_data, 0, _data.Length); + + target.Load(sshDataStream.ToArray()); + + Assert.IsNotNull(target.Data); + Assert.IsTrue(target.Data.SequenceEqual(_data)); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual(_responseId, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Data, target.SftpMessageType); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpExtendedReplyResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpExtendedReplyResponseTest.cs index cb77f19d..751e4b13 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpExtendedReplyResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpExtendedReplyResponseTest.cs @@ -1,103 +1,103 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpExtendedReplyResponseTest - { - private Random _random; - private uint _protocolVersion; - private uint _responseId; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _protocolVersion = (uint) _random.Next(0, int.MaxValue); - _responseId = (uint) _random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var target = new SftpExtendedReplyResponse(_protocolVersion); - - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual((uint) 0, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.ExtendedReply, target.SftpMessageType); - } - - [TestMethod] - public void Load() - { - var target = new SftpExtendedReplyResponse(_protocolVersion); - - var sshDataStream = new SshDataStream(4 + 1 + 4); - sshDataStream.Position = 4; // skip 4 bytes for SSH packet length - sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); - sshDataStream.Write(_responseId); - - target.Load(sshDataStream.ToArray()); - - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual(_responseId, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.ExtendedReply, target.SftpMessageType); - } - - [TestMethod] - public void GetReply_StatVfsReplyInfo() - { - var bsize = (ulong) _random.Next(0, int.MaxValue); - var frsize = (ulong) _random.Next(0, int.MaxValue); - var blocks = (ulong) _random.Next(0, int.MaxValue); - var bfree = (ulong) _random.Next(0, int.MaxValue); - var bavail = (ulong) _random.Next(0, int.MaxValue); - var files = (ulong) _random.Next(0, int.MaxValue); - var ffree = (ulong) _random.Next(0, int.MaxValue); - var favail = (ulong) _random.Next(0, int.MaxValue); - var sid = (ulong) _random.Next(0, int.MaxValue); - var namemax = (ulong) _random.Next(0, int.MaxValue); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); - sshDataStream.Position = 4; // skip 4 bytes for SSH packet length - sshDataStream.WriteByte((byte) SftpMessageTypes.Attrs); - sshDataStream.Write(_responseId); - sshDataStream.Write(bsize); - sshDataStream.Write(frsize); - sshDataStream.Write(blocks); - sshDataStream.Write(bfree); - sshDataStream.Write(bavail); - sshDataStream.Write(files); - sshDataStream.Write(ffree); - sshDataStream.Write(favail); - sshDataStream.Write(sid); - sshDataStream.Write((ulong) 0x2); - sshDataStream.Write(namemax); - - var target = new SftpExtendedReplyResponse(_protocolVersion); - target.Load(sshDataStream.ToArray()); - - var reply = target.GetReply(); - Assert.IsNotNull(reply); - - var information = reply.Information; - Assert.IsNotNull(information); - Assert.AreEqual(bavail, information.AvailableBlocks); - Assert.AreEqual(favail, information.AvailableNodes); - Assert.AreEqual(frsize, information.BlockSize); - Assert.AreEqual(bsize, information.FileSystemBlockSize); - Assert.AreEqual(bfree, information.FreeBlocks); - Assert.AreEqual(ffree, information.FreeNodes); - Assert.IsFalse(information.IsReadOnly); - Assert.AreEqual(namemax, information.MaxNameLenght); - Assert.AreEqual(sid, information.Sid); - Assert.IsFalse(information.SupportsSetUid); - Assert.AreEqual(blocks, information.TotalBlocks); - Assert.AreEqual(files, information.TotalNodes); - } - } +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpExtendedReplyResponseTest + { + private Random _random; + private uint _protocolVersion; + private uint _responseId; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _protocolVersion = (uint) _random.Next(0, int.MaxValue); + _responseId = (uint) _random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var target = new SftpExtendedReplyResponse(_protocolVersion); + + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual((uint) 0, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.ExtendedReply, target.SftpMessageType); + } + + [TestMethod] + public void Load() + { + var target = new SftpExtendedReplyResponse(_protocolVersion); + + var sshDataStream = new SshDataStream(4 + 1 + 4); + sshDataStream.Position = 4; // skip 4 bytes for SSH packet length + sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); + sshDataStream.Write(_responseId); + + target.Load(sshDataStream.ToArray()); + + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual(_responseId, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.ExtendedReply, target.SftpMessageType); + } + + [TestMethod] + public void GetReply_StatVfsReplyInfo() + { + var bsize = (ulong) _random.Next(0, int.MaxValue); + var frsize = (ulong) _random.Next(0, int.MaxValue); + var blocks = (ulong) _random.Next(0, int.MaxValue); + var bfree = (ulong) _random.Next(0, int.MaxValue); + var bavail = (ulong) _random.Next(0, int.MaxValue); + var files = (ulong) _random.Next(0, int.MaxValue); + var ffree = (ulong) _random.Next(0, int.MaxValue); + var favail = (ulong) _random.Next(0, int.MaxValue); + var sid = (ulong) _random.Next(0, int.MaxValue); + var namemax = (ulong) _random.Next(0, int.MaxValue); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); + sshDataStream.Position = 4; // skip 4 bytes for SSH packet length + sshDataStream.WriteByte((byte) SftpMessageTypes.Attrs); + sshDataStream.Write(_responseId); + sshDataStream.Write(bsize); + sshDataStream.Write(frsize); + sshDataStream.Write(blocks); + sshDataStream.Write(bfree); + sshDataStream.Write(bavail); + sshDataStream.Write(files); + sshDataStream.Write(ffree); + sshDataStream.Write(favail); + sshDataStream.Write(sid); + sshDataStream.Write((ulong) 0x2); + sshDataStream.Write(namemax); + + var target = new SftpExtendedReplyResponse(_protocolVersion); + target.Load(sshDataStream.ToArray()); + + var reply = target.GetReply(); + Assert.IsNotNull(reply); + + var information = reply.Information; + Assert.IsNotNull(information); + Assert.AreEqual(bavail, information.AvailableBlocks); + Assert.AreEqual(favail, information.AvailableNodes); + Assert.AreEqual(frsize, information.BlockSize); + Assert.AreEqual(bsize, information.FileSystemBlockSize); + Assert.AreEqual(bfree, information.FreeBlocks); + Assert.AreEqual(ffree, information.FreeNodes); + Assert.IsFalse(information.IsReadOnly); + Assert.AreEqual(namemax, information.MaxNameLenght); + Assert.AreEqual(sid, information.Sid); + Assert.IsFalse(information.SupportsSetUid); + Assert.AreEqual(blocks, information.TotalBlocks); + Assert.AreEqual(files, information.TotalNodes); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpHandleResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpHandleResponseTest.cs index 36000ded..e7b509cb 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpHandleResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpHandleResponseTest.cs @@ -1,60 +1,60 @@ - using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpHandleResponseTest - { - private Random _random; - private uint _protocolVersion; - private uint _responseId; - private byte[] _handle; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _protocolVersion = (uint) _random.Next(0, int.MaxValue); - _responseId = (uint) _random.Next(0, int.MaxValue); - _handle = new byte[_random.Next(1, 10)]; - _random.NextBytes(_handle); - } - - [TestMethod] - public void Constructor() - { - var target = new SftpHandleResponse(_protocolVersion); - - Assert.IsNull(target.Handle); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual((uint) 0, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Handle, target.SftpMessageType); - } - - [TestMethod] - public void Load() - { - var target = new SftpHandleResponse(_protocolVersion); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + _handle.Length); - sshDataStream.Position = 4; // skip 4 bytes for SSH packet length - sshDataStream.WriteByte((byte) SftpMessageTypes.Handle); - sshDataStream.Write(_responseId); - sshDataStream.Write((uint) _handle.Length); - sshDataStream.Write(_handle, 0, _handle.Length); - - target.Load(sshDataStream.ToArray()); - - Assert.IsNotNull(target.Handle); - Assert.IsTrue(target.Handle.SequenceEqual(_handle)); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual(_responseId, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Handle, target.SftpMessageType); - } - } -} + using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpHandleResponseTest + { + private Random _random; + private uint _protocolVersion; + private uint _responseId; + private byte[] _handle; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _protocolVersion = (uint) _random.Next(0, int.MaxValue); + _responseId = (uint) _random.Next(0, int.MaxValue); + _handle = new byte[_random.Next(1, 10)]; + _random.NextBytes(_handle); + } + + [TestMethod] + public void Constructor() + { + var target = new SftpHandleResponse(_protocolVersion); + + Assert.IsNull(target.Handle); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual((uint) 0, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Handle, target.SftpMessageType); + } + + [TestMethod] + public void Load() + { + var target = new SftpHandleResponse(_protocolVersion); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + _handle.Length); + sshDataStream.Position = 4; // skip 4 bytes for SSH packet length + sshDataStream.WriteByte((byte) SftpMessageTypes.Handle); + sshDataStream.Write(_responseId); + sshDataStream.Write((uint) _handle.Length); + sshDataStream.Write(_handle, 0, _handle.Length); + + target.Load(sshDataStream.ToArray()); + + Assert.IsNotNull(target.Handle); + Assert.IsTrue(target.Handle.SequenceEqual(_handle)); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual(_responseId, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Handle, target.SftpMessageType); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpNameResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpNameResponseTest.cs index 164580f3..2265e3f5 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpNameResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpNameResponseTest.cs @@ -1,10 +1,10 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpNameResponseTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpNameResponseTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpStatusResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpStatusResponseTest.cs index 8552e562..ca46720d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpStatusResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpStatusResponseTest.cs @@ -1,10 +1,10 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpStatusResponseTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpStatusResponseTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpVersionResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpVersionResponseTest.cs index 7e8150de..4cabe306 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpVersionResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpVersionResponseTest.cs @@ -1,10 +1,10 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpVersionResponseTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpVersionResponseTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpDownloadAsyncResultTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpDownloadAsyncResultTest.cs index 76d27d25..eb978638 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpDownloadAsyncResultTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpDownloadAsyncResultTest.cs @@ -1,27 +1,27 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Sftp; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - /// - ///This is a test class for SftpDownloadAsyncResultTest and is intended - ///to contain all SftpDownloadAsyncResultTest Unit Tests - /// - [TestClass()] - public class SftpDownloadAsyncResultTest : TestBase - { - /// - ///A test for SftpDownloadAsyncResult Constructor - /// - [TestMethod()] - public void SftpDownloadAsyncResultConstructorTest() - { - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - SftpDownloadAsyncResult target = new SftpDownloadAsyncResult(asyncCallback, state); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Sftp; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + /// + ///This is a test class for SftpDownloadAsyncResultTest and is intended + ///to contain all SftpDownloadAsyncResultTest Unit Tests + /// + [TestClass()] + public class SftpDownloadAsyncResultTest : TestBase + { + /// + ///A test for SftpDownloadAsyncResult Constructor + /// + [TestMethod()] + public void SftpDownloadAsyncResultConstructorTest() + { + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + SftpDownloadAsyncResult target = new SftpDownloadAsyncResult(asyncCallback, state); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileAttributesTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileAttributesTest.cs index 350b9243..5d2b7944 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileAttributesTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileAttributesTest.cs @@ -1,237 +1,237 @@ -using Renci.SshNet.Sftp; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests -{ - /// - ///This is a test class for SftpFileAttributesTest and is intended - ///to contain all SftpFileAttributesTest Unit Tests - /// - [TestClass()] - public class SftpFileAttributesTest : TestBase - { - /// - ///A test for SetPermissions - /// - [TestMethod()] - public void SetPermissionsTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - short mode = 0; // TODO: Initialize to an appropriate value - target.SetPermissions(mode); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for GroupCanExecute - /// - [TestMethod()] - public void GroupCanExecuteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.GroupCanExecute = expected; - actual = target.GroupCanExecute; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GroupCanRead - /// - [TestMethod()] - public void GroupCanReadTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.GroupCanRead = expected; - actual = target.GroupCanRead; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GroupCanWrite - /// - [TestMethod()] - public void GroupCanWriteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.GroupCanWrite = expected; - actual = target.GroupCanWrite; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GroupId - /// - [TestMethod()] - public void GroupIdTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - target.GroupId = expected; - actual = target.GroupId; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for LastAccessTime - /// - [TestMethod()] - public void LastAccessTimeTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - target.LastAccessTime = expected; - actual = target.LastAccessTime; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for LastWriteTime - /// - [TestMethod()] - public void LastWriteTimeTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - target.LastWriteTime = expected; - actual = target.LastWriteTime; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OthersCanExecute - /// - [TestMethod()] - public void OthersCanExecuteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OthersCanExecute = expected; - actual = target.OthersCanExecute; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OthersCanRead - /// - [TestMethod()] - public void OthersCanReadTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OthersCanRead = expected; - actual = target.OthersCanRead; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OthersCanWrite - /// - [TestMethod()] - public void OthersCanWriteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OthersCanWrite = expected; - actual = target.OthersCanWrite; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OwnerCanExecute - /// - [TestMethod()] - public void OwnerCanExecuteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OwnerCanExecute = expected; - actual = target.OwnerCanExecute; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OwnerCanRead - /// - [TestMethod()] - public void OwnerCanReadTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OwnerCanRead = expected; - actual = target.OwnerCanRead; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OwnerCanWrite - /// - [TestMethod()] - public void OwnerCanWriteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OwnerCanWrite = expected; - actual = target.OwnerCanWrite; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Size - /// - [TestMethod()] - public void SizeTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - long expected = 0; // TODO: Initialize to an appropriate value - long actual; - target.Size = expected; - actual = target.Size; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for UserId - /// - [TestMethod()] - public void UserIdTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - target.UserId = expected; - actual = target.UserId; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Sftp; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests +{ + /// + ///This is a test class for SftpFileAttributesTest and is intended + ///to contain all SftpFileAttributesTest Unit Tests + /// + [TestClass()] + public class SftpFileAttributesTest : TestBase + { + /// + ///A test for SetPermissions + /// + [TestMethod()] + public void SetPermissionsTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + short mode = 0; // TODO: Initialize to an appropriate value + target.SetPermissions(mode); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for GroupCanExecute + /// + [TestMethod()] + public void GroupCanExecuteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.GroupCanExecute = expected; + actual = target.GroupCanExecute; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GroupCanRead + /// + [TestMethod()] + public void GroupCanReadTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.GroupCanRead = expected; + actual = target.GroupCanRead; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GroupCanWrite + /// + [TestMethod()] + public void GroupCanWriteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.GroupCanWrite = expected; + actual = target.GroupCanWrite; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GroupId + /// + [TestMethod()] + public void GroupIdTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + target.GroupId = expected; + actual = target.GroupId; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for LastAccessTime + /// + [TestMethod()] + public void LastAccessTimeTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + target.LastAccessTime = expected; + actual = target.LastAccessTime; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for LastWriteTime + /// + [TestMethod()] + public void LastWriteTimeTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + target.LastWriteTime = expected; + actual = target.LastWriteTime; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OthersCanExecute + /// + [TestMethod()] + public void OthersCanExecuteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OthersCanExecute = expected; + actual = target.OthersCanExecute; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OthersCanRead + /// + [TestMethod()] + public void OthersCanReadTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OthersCanRead = expected; + actual = target.OthersCanRead; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OthersCanWrite + /// + [TestMethod()] + public void OthersCanWriteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OthersCanWrite = expected; + actual = target.OthersCanWrite; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OwnerCanExecute + /// + [TestMethod()] + public void OwnerCanExecuteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OwnerCanExecute = expected; + actual = target.OwnerCanExecute; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OwnerCanRead + /// + [TestMethod()] + public void OwnerCanReadTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OwnerCanRead = expected; + actual = target.OwnerCanRead; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OwnerCanWrite + /// + [TestMethod()] + public void OwnerCanWriteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OwnerCanWrite = expected; + actual = target.OwnerCanWrite; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Size + /// + [TestMethod()] + public void SizeTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + long expected = 0; // TODO: Initialize to an appropriate value + long actual; + target.Size = expected; + actual = target.Size; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for UserId + /// + [TestMethod()] + public void UserIdTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + target.UserId = expected; + actual = target.UserId; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs index 15342bd9..f11cd8f6 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Closed_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(0, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Closed_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(0, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs index 6310f333..296728d4 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(0, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(0, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs index 5176fb8f..f988edff 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Closed_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(0, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Closed_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(0, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs index eb267701..5d69b468 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Disposed_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Disposed_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs index 44478b27..a6e8fe31 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs index f5d3e5ae..448b373b 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Disposed_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Disposed_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead.cs index 30c97c04..d1c0747d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnTrue() - { - Assert.IsTrue(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnTrue() + { + Assert.IsTrue(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite.cs index c396b9a2..041a20bc 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnTrue() - { - Assert.IsTrue(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnTrue() + { + Assert.IsTrue(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite.cs index ae17eab8..8fc229d4 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs index c46bfa76..424b2e4d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Closed_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Closed_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs index 4d6ce5de..9d94a222 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs index 1a6b1c72..9952030f 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Closed_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Closed_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs index cbb5a6a5..540dc1f2 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Disposed_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Disposed_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs index 95ebe14f..2554d22c 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs index 7141961a..d02389bc 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead.cs index 7dc8a8d0..c95b9280 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CaWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CaWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite.cs index be20911e..4501f40d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnTrue() - { - Assert.IsTrue(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnTrue() + { + Assert.IsTrue(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite.cs index 48e5d2f0..4049d527 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnTrue() - { - Assert.IsTrue(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnTrue() + { + Assert.IsTrue(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Closed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Closed.cs index 81d7c2d8..08949600 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Closed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Closed.cs @@ -1,79 +1,79 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Close_Closed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _sftpFileStream.Close(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Close_Closed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _sftpFileStream.Close(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Disposed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Disposed.cs index b9d55b3c..0257b1ba 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Disposed.cs @@ -1,79 +1,79 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Close_Disposed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _sftpFileStream.Close(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Close_Disposed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _sftpFileStream.Close(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionNotOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionNotOpen.cs index 1bdcf1e5..97b590b1 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionNotOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionNotOpen.cs @@ -1,76 +1,76 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Close_SessionNotOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(false); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - } - - protected void Act() - { - _sftpFileStream.Close(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Close_SessionNotOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(false); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + } + + protected void Act() + { + _sftpFileStream.Close(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionOpen.cs index 3836a0c1..fb220b58 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionOpen.cs @@ -1,78 +1,78 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Close_SessionOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); - } - - protected void Act() - { - _sftpFileStream.Close(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Close_SessionOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); + } + + protected void Act() + { + _sftpFileStream.Close(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Closed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Closed.cs index dce77334..af2683e5 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Closed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Closed.cs @@ -1,79 +1,79 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Dispose_Closed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _sftpFileStream.Dispose(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Dispose_Closed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _sftpFileStream.Dispose(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Disposed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Disposed.cs index 0ea2cba6..9fda20d8 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Disposed.cs @@ -1,79 +1,79 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Dispose_Disposed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _sftpFileStream.Dispose(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Dispose_Disposed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _sftpFileStream.Dispose(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionNotOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionNotOpen.cs index 1d4371f6..0436f056 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionNotOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionNotOpen.cs @@ -1,78 +1,78 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Dispose_SessionNotOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(false); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - } - - protected void Act() - { - _sftpFileStream.Dispose(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Dispose_SessionNotOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(false); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + } + + protected void Act() + { + _sftpFileStream.Dispose(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionOpen.cs index ff4fa576..1a08ffb9 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionOpen.cs @@ -1,78 +1,78 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Dispose_SessionOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); - } - - protected void Act() - { - _sftpFileStream.Dispose(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Dispose_SessionOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); + } + + protected void Act() + { + _sftpFileStream.Dispose(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Finalize_SessionOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Finalize_SessionOpen.cs index 8a3718d5..32db6393 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Finalize_SessionOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Finalize_SessionOpen.cs @@ -1,80 +1,80 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Finalize_SessionOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); - _sftpFileStream = null; - } - - protected void Act() - { - GC.Collect(); - GC.WaitForPendingFinalizers(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Never); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Finalize_SessionOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); + _sftpFileStream = null; + } + + protected void Act() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Never); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Closed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Closed.cs index 3889185a..fbd84b0b 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Closed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Closed.cs @@ -1,90 +1,90 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_Closed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - try - { - _sftpFileStream.SetLength(5); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SetLengthShouldHaveThrownObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual( - string.Format( - "Cannot access a disposed object.{0}Object name: '{1}'.", - Environment.NewLine, - _actualException.ObjectName), - _actualException.Message); - Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_Closed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + try + { + _sftpFileStream.SetLength(5); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SetLengthShouldHaveThrownObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual( + string.Format( + "Cannot access a disposed object.{0}Object name: '{1}'.", + Environment.NewLine, + _actualException.ObjectName), + _actualException.Message); + Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Disposed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Disposed.cs index 712147fa..ce521f71 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Disposed.cs @@ -1,90 +1,90 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_Disposed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - try - { - _sftpFileStream.SetLength(5); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SetLengthShouldHaveThrownObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual( - string.Format( - "Cannot access a disposed object.{0}Object name: '{1}'.", - Environment.NewLine, - _actualException.ObjectName), - _actualException.Message); - Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_Disposed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + try + { + _sftpFileStream.SetLength(5); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SetLengthShouldHaveThrownObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual( + string.Format( + "Cannot access a disposed object.{0}Object name: '{1}'.", + Environment.NewLine, + _actualException.ObjectName), + _actualException.Message); + Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionNotOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionNotOpen.cs index 84f86844..bab89847 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionNotOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionNotOpen.cs @@ -1,96 +1,96 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_SessionNotOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private MockSequence _sequence; - private long _length; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - _length = random.Next(); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.IsOpen) - .Returns(false); - - _sftpFileStream = new SftpFileStream( - _sftpSessionMock.Object, - _path, - FileMode.Create, - FileAccess.Read, - (int)_bufferSize); - } - - protected void Act() - { - try - { - _sftpFileStream.SetLength(_length); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SetLengthShouldHaveThrownObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual( - string.Format( - "Cannot access a closed SFTP session.{0}Object name: '{1}'.", - Environment.NewLine, - _actualException.ObjectName), - _actualException.Message); - Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); - } - - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_SessionNotOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private MockSequence _sequence; + private long _length; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + _length = random.Next(); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.IsOpen) + .Returns(false); + + _sftpFileStream = new SftpFileStream( + _sftpSessionMock.Object, + _path, + FileMode.Create, + FileAccess.Read, + (int)_bufferSize); + } + + protected void Act() + { + try + { + _sftpFileStream.SetLength(_length); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SetLengthShouldHaveThrownObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual( + string.Format( + "Cannot access a closed SFTP session.{0}Object name: '{1}'.", + Environment.NewLine, + _actualException.ObjectName), + _actualException.Message); + Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); + } + + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs index bbb0acfa..f2fa6bcd 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs @@ -1,89 +1,89 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccess - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private MockSequence _sequence; - private long _length; - private NotSupportedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - _length = random.Next(); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.IsOpen) - .Returns(true); - - _sftpFileStream = new SftpFileStream( - _sftpSessionMock.Object, - _path, - FileMode.Create, - FileAccess.Read, - (int) _bufferSize); - } - - protected void Act() - { - try - { - _sftpFileStream.SetLength(_length); - Assert.Fail(); - } - catch (NotSupportedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SetLengthShouldHaveThrownNotSupportedException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual("Write not supported.", _actualException.Message); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccess + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private MockSequence _sequence; + private long _length; + private NotSupportedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + _length = random.Next(); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.IsOpen) + .Returns(true); + + _sftpFileStream = new SftpFileStream( + _sftpSessionMock.Object, + _path, + FileMode.Create, + FileAccess.Read, + (int) _bufferSize); + } + + protected void Act() + { + try + { + _sftpFileStream.SetLength(_length); + Assert.Fail(); + } + catch (NotSupportedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SetLengthShouldHaveThrownNotSupportedException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual("Write not supported.", _actualException.Message); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs index 5ce4198a..dbfad31d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs @@ -1,99 +1,99 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private MockSequence _sequence; - private long _length; - private long _lengthPassedToRequestFSetStat; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - _length = random.Next(); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestFSetStat(_handle, _fileAttributes)) - .Callback((bytes, attributes) => _lengthPassedToRequestFSetStat = attributes.Size); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - } - - protected void Act() - { - _sftpFileStream.SetLength(_length); - } - - [TestMethod] - public void PositionShouldReturnOriginalPosition() - { - _sftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.AreEqual(0, _sftpFileStream.Position); - - _sftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - - [TestMethod] - public void RequestFSetStatOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestFSetStat(_handle, _fileAttributes), Times.Once); - } - - [TestMethod] - public void SizeOfSftpFileAttributesShouldBeModifiedToNewLengthBeforePassedToRequestFSetStat() - { - Assert.AreEqual(_length, _lengthPassedToRequestFSetStat); - } - - [TestMethod] - public void SizeOfSftpFileAttributesShouldBeEqualToNewLength() - { - Assert.AreEqual(_length, _fileAttributes.Size); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private MockSequence _sequence; + private long _length; + private long _lengthPassedToRequestFSetStat; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + _length = random.Next(); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestFSetStat(_handle, _fileAttributes)) + .Callback((bytes, attributes) => _lengthPassedToRequestFSetStat = attributes.Size); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + } + + protected void Act() + { + _sftpFileStream.SetLength(_length); + } + + [TestMethod] + public void PositionShouldReturnOriginalPosition() + { + _sftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.AreEqual(0, _sftpFileStream.Position); + + _sftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + + [TestMethod] + public void RequestFSetStatOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestFSetStat(_handle, _fileAttributes), Times.Once); + } + + [TestMethod] + public void SizeOfSftpFileAttributesShouldBeModifiedToNewLengthBeforePassedToRequestFSetStat() + { + Assert.AreEqual(_length, _lengthPassedToRequestFSetStat); + } + + [TestMethod] + public void SizeOfSftpFileAttributesShouldBeEqualToNewLength() + { + Assert.AreEqual(_length, _fileAttributes.Size); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs index 3329f183..477ec749 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs @@ -1,99 +1,99 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private MockSequence _sequence; - private long _length; - private long _lengthPassedToRequestFSetStat; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - _length = random.Next(); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestFSetStat(_handle, _fileAttributes)) - .Callback((bytes, attributes) => _lengthPassedToRequestFSetStat = attributes.Size); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - } - - protected void Act() - { - _sftpFileStream.SetLength(_length); - } - - [TestMethod] - public void PositionShouldReturnOriginalPosition() - { - _sftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.AreEqual(0, _sftpFileStream.Position); - - _sftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - - [TestMethod] - public void RequestFSetStatOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestFSetStat(_handle, _fileAttributes), Times.Once); - } - - [TestMethod] - public void SizeOfSftpFileAttributesShouldBeModifiedToNewLengthBeforePassedToRequestFSetStat() - { - Assert.AreEqual(_length, _lengthPassedToRequestFSetStat); - } - - [TestMethod] - public void SizeOfSftpFileAttributesShouldBeEqualToNewLength() - { - Assert.AreEqual(_length, _fileAttributes.Size); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private MockSequence _sequence; + private long _length; + private long _lengthPassedToRequestFSetStat; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + _length = random.Next(); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestFSetStat(_handle, _fileAttributes)) + .Callback((bytes, attributes) => _lengthPassedToRequestFSetStat = attributes.Size); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + } + + protected void Act() + { + _sftpFileStream.SetLength(_length); + } + + [TestMethod] + public void PositionShouldReturnOriginalPosition() + { + _sftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.AreEqual(0, _sftpFileStream.Position); + + _sftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + + [TestMethod] + public void RequestFSetStatOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestFSetStat(_handle, _fileAttributes), Times.Once); + } + + [TestMethod] + public void SizeOfSftpFileAttributesShouldBeModifiedToNewLengthBeforePassedToRequestFSetStat() + { + Assert.AreEqual(_length, _lengthPassedToRequestFSetStat); + } + + [TestMethod] + public void SizeOfSftpFileAttributesShouldBeEqualToNewLength() + { + Assert.AreEqual(_length, _fileAttributes.Size); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileSystemInformationTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileSystemInformationTest.cs index 6c5342a1..778302fc 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileSystemInformationTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileSystemInformationTest.cs @@ -1,60 +1,60 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Sftp; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - /// - ///This is a test class for SftpFileSytemInformationTest and is intended - ///to contain all SftpFileSytemInformationTest Unit Tests - /// - [TestClass()] - public class SftpFileSystemInformationTest : TestBase - { - /// - ///A test for IsReadOnly - /// - [TestMethod()] - public void IsReadOnlyTest() - { - ulong bsize = 0; // TODO: Initialize to an appropriate value - ulong frsize = 0; // TODO: Initialize to an appropriate value - ulong blocks = 0; // TODO: Initialize to an appropriate value - ulong bfree = 0; // TODO: Initialize to an appropriate value - ulong bavail = 0; // TODO: Initialize to an appropriate value - ulong files = 0; // TODO: Initialize to an appropriate value - ulong ffree = 0; // TODO: Initialize to an appropriate value - ulong favail = 0; // TODO: Initialize to an appropriate value - ulong sid = 0; // TODO: Initialize to an appropriate value - ulong flag = 0; // TODO: Initialize to an appropriate value - ulong namemax = 0; // TODO: Initialize to an appropriate value - SftpFileSytemInformation target = new SftpFileSytemInformation(bsize, frsize, blocks, bfree, bavail, files, ffree, favail, sid, flag, namemax); // TODO: Initialize to an appropriate value - bool actual; - actual = target.IsReadOnly; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for SupportsSetUid - /// - [TestMethod()] - public void SupportsSetUidTest() - { - ulong bsize = 0; // TODO: Initialize to an appropriate value - ulong frsize = 0; // TODO: Initialize to an appropriate value - ulong blocks = 0; // TODO: Initialize to an appropriate value - ulong bfree = 0; // TODO: Initialize to an appropriate value - ulong bavail = 0; // TODO: Initialize to an appropriate value - ulong files = 0; // TODO: Initialize to an appropriate value - ulong ffree = 0; // TODO: Initialize to an appropriate value - ulong favail = 0; // TODO: Initialize to an appropriate value - ulong sid = 0; // TODO: Initialize to an appropriate value - ulong flag = 0; // TODO: Initialize to an appropriate value - ulong namemax = 0; // TODO: Initialize to an appropriate value - SftpFileSytemInformation target = new SftpFileSytemInformation(bsize, frsize, blocks, bfree, bavail, files, ffree, favail, sid, flag, namemax); // TODO: Initialize to an appropriate value - bool actual; - actual = target.SupportsSetUid; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Sftp; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + /// + ///This is a test class for SftpFileSytemInformationTest and is intended + ///to contain all SftpFileSytemInformationTest Unit Tests + /// + [TestClass()] + public class SftpFileSystemInformationTest : TestBase + { + /// + ///A test for IsReadOnly + /// + [TestMethod()] + public void IsReadOnlyTest() + { + ulong bsize = 0; // TODO: Initialize to an appropriate value + ulong frsize = 0; // TODO: Initialize to an appropriate value + ulong blocks = 0; // TODO: Initialize to an appropriate value + ulong bfree = 0; // TODO: Initialize to an appropriate value + ulong bavail = 0; // TODO: Initialize to an appropriate value + ulong files = 0; // TODO: Initialize to an appropriate value + ulong ffree = 0; // TODO: Initialize to an appropriate value + ulong favail = 0; // TODO: Initialize to an appropriate value + ulong sid = 0; // TODO: Initialize to an appropriate value + ulong flag = 0; // TODO: Initialize to an appropriate value + ulong namemax = 0; // TODO: Initialize to an appropriate value + SftpFileSytemInformation target = new SftpFileSytemInformation(bsize, frsize, blocks, bfree, bavail, files, ffree, favail, sid, flag, namemax); // TODO: Initialize to an appropriate value + bool actual; + actual = target.IsReadOnly; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for SupportsSetUid + /// + [TestMethod()] + public void SupportsSetUidTest() + { + ulong bsize = 0; // TODO: Initialize to an appropriate value + ulong frsize = 0; // TODO: Initialize to an appropriate value + ulong blocks = 0; // TODO: Initialize to an appropriate value + ulong bfree = 0; // TODO: Initialize to an appropriate value + ulong bavail = 0; // TODO: Initialize to an appropriate value + ulong files = 0; // TODO: Initialize to an appropriate value + ulong ffree = 0; // TODO: Initialize to an appropriate value + ulong favail = 0; // TODO: Initialize to an appropriate value + ulong sid = 0; // TODO: Initialize to an appropriate value + ulong flag = 0; // TODO: Initialize to an appropriate value + ulong namemax = 0; // TODO: Initialize to an appropriate value + SftpFileSytemInformation target = new SftpFileSytemInformation(bsize, frsize, blocks, bfree, bavail, files, ffree, favail, sid, flag, namemax); // TODO: Initialize to an appropriate value + bool actual; + actual = target.SupportsSetUid; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpListDirectoryAsyncResultTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpListDirectoryAsyncResultTest.cs index 4718f88d..aa20db90 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpListDirectoryAsyncResultTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpListDirectoryAsyncResultTest.cs @@ -1,27 +1,27 @@ -using Renci.SshNet.Sftp; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests -{ - /// - ///This is a test class for SftpListDirectoryAsyncResultTest and is intended - ///to contain all SftpListDirectoryAsyncResultTest Unit Tests - /// - [TestClass()] - public class SftpListDirectoryAsyncResultTest : TestBase - { - /// - ///A test for SftpListDirectoryAsyncResult Constructor - /// - [TestMethod()] - public void SftpListDirectoryAsyncResultConstructorTest() - { - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - SftpListDirectoryAsyncResult target = new SftpListDirectoryAsyncResult(asyncCallback, state); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Sftp; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests +{ + /// + ///This is a test class for SftpListDirectoryAsyncResultTest and is intended + ///to contain all SftpListDirectoryAsyncResultTest Unit Tests + /// + [TestClass()] + public class SftpListDirectoryAsyncResultTest : TestBase + { + /// + ///A test for SftpListDirectoryAsyncResult Constructor + /// + [TestMethod()] + public void SftpListDirectoryAsyncResultConstructorTest() + { + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + SftpListDirectoryAsyncResult target = new SftpListDirectoryAsyncResult(asyncCallback, state); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestRead.cs index 7b500df6..57f1d586 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestRead.cs @@ -1,140 +1,140 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpSessionTest_Connected_RequestRead - { - private Mock _sessionMock; - private Mock _channelSessionMock; - private SftpSession _sftpSession; - private TimeSpan _operationTimeout; - private byte[] _actual; - private byte[] _expected; - private Encoding _encoding; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - - _operationTimeout = TimeSpan.FromMilliseconds(random.Next(100, 500)); - _expected = new byte[random.Next(30, 50)]; - _encoding = Encoding.UTF8; - random.NextBytes(_expected); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); - _channelSessionMock.InSequence(sequence).Setup(p => p.Open()); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest("sftp")).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - // generate response for SftpInitRequest - var versionInfoResponse = SftpVersionResponseBuilder.Create(3) - .Build(); - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, versionInfoResponse)); - }); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - var sftpNameResponse = CreateSftpNameResponse(1, _encoding, "ABC"); - - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, sftpNameResponse)); - } - ); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - var sftpDataResponse = CreateSftpDataResponse(2, _expected); - - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, sftpDataResponse.Take(0, 20))); - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, sftpDataResponse.Take(20, sftpDataResponse.Length - 20))); - } - ); - - _sftpSession = new SftpSession(_sessionMock.Object, _operationTimeout, _encoding); - _sftpSession.Connect(); - } - - protected void Act() - { - _actual = _sftpSession.RequestRead(new byte[0], 0, 200); - } - - [TestMethod] - public void ReturnedValueShouldBeDataOfSftpDataResponse() - { - Assert.IsNotNull(_actual); - Assert.IsTrue(_expected.SequenceEqual(_actual)); - } - - private static byte[] CreateSftpDataResponse(uint responseId, byte[] data) - { - var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + data.Length + 1); - sshDataStream.Write((uint) sshDataStream.Capacity - 4); - sshDataStream.WriteByte((byte) SftpMessageTypes.Data); - sshDataStream.Write(responseId); - sshDataStream.Write((uint) data.Length); - sshDataStream.Write(data, 0, data.Length); - sshDataStream.WriteByte(1); // EOF - return sshDataStream.ToArray(); - } - - private static byte[] CreateSftpNameResponse(uint responseId, Encoding encoding, params string[] names) - { - var namesAndAttributes = new List(); - foreach (var name in names) - { - var nameBytes = encoding.GetBytes(name); - var attributesBytes = SftpFileAttributes.Empty.GetBytes(); - - namesAndAttributes.AddRange((((uint) nameBytes.Length).GetBytes())); // filename length - namesAndAttributes.AddRange(nameBytes); // filename - namesAndAttributes.AddRange(((uint) 0).GetBytes()); // longname length - namesAndAttributes.AddRange(attributesBytes); // attributes - } - - var namesAndAttributesBytes = namesAndAttributes.ToArray(); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + namesAndAttributesBytes.Length); - sshDataStream.Write((uint) sshDataStream.Capacity - 4); - sshDataStream.WriteByte((byte) SftpMessageTypes.Name); - sshDataStream.Write(responseId); - sshDataStream.Write((uint) names.Length); - sshDataStream.Write(namesAndAttributesBytes, 0, namesAndAttributesBytes.Length); - return sshDataStream.ToArray(); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpSessionTest_Connected_RequestRead + { + private Mock _sessionMock; + private Mock _channelSessionMock; + private SftpSession _sftpSession; + private TimeSpan _operationTimeout; + private byte[] _actual; + private byte[] _expected; + private Encoding _encoding; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + + _operationTimeout = TimeSpan.FromMilliseconds(random.Next(100, 500)); + _expected = new byte[random.Next(30, 50)]; + _encoding = Encoding.UTF8; + random.NextBytes(_expected); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); + _channelSessionMock.InSequence(sequence).Setup(p => p.Open()); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest("sftp")).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + // generate response for SftpInitRequest + var versionInfoResponse = SftpVersionResponseBuilder.Create(3) + .Build(); + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, versionInfoResponse)); + }); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + var sftpNameResponse = CreateSftpNameResponse(1, _encoding, "ABC"); + + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, sftpNameResponse)); + } + ); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + var sftpDataResponse = CreateSftpDataResponse(2, _expected); + + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, sftpDataResponse.Take(0, 20))); + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, sftpDataResponse.Take(20, sftpDataResponse.Length - 20))); + } + ); + + _sftpSession = new SftpSession(_sessionMock.Object, _operationTimeout, _encoding); + _sftpSession.Connect(); + } + + protected void Act() + { + _actual = _sftpSession.RequestRead(new byte[0], 0, 200); + } + + [TestMethod] + public void ReturnedValueShouldBeDataOfSftpDataResponse() + { + Assert.IsNotNull(_actual); + Assert.IsTrue(_expected.SequenceEqual(_actual)); + } + + private static byte[] CreateSftpDataResponse(uint responseId, byte[] data) + { + var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + data.Length + 1); + sshDataStream.Write((uint) sshDataStream.Capacity - 4); + sshDataStream.WriteByte((byte) SftpMessageTypes.Data); + sshDataStream.Write(responseId); + sshDataStream.Write((uint) data.Length); + sshDataStream.Write(data, 0, data.Length); + sshDataStream.WriteByte(1); // EOF + return sshDataStream.ToArray(); + } + + private static byte[] CreateSftpNameResponse(uint responseId, Encoding encoding, params string[] names) + { + var namesAndAttributes = new List(); + foreach (var name in names) + { + var nameBytes = encoding.GetBytes(name); + var attributesBytes = SftpFileAttributes.Empty.GetBytes(); + + namesAndAttributes.AddRange((((uint) nameBytes.Length).GetBytes())); // filename length + namesAndAttributes.AddRange(nameBytes); // filename + namesAndAttributes.AddRange(((uint) 0).GetBytes()); // longname length + namesAndAttributes.AddRange(attributesBytes); // attributes + } + + var namesAndAttributesBytes = namesAndAttributes.ToArray(); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + namesAndAttributesBytes.Length); + sshDataStream.Write((uint) sshDataStream.Capacity - 4); + sshDataStream.WriteByte((byte) SftpMessageTypes.Name); + sshDataStream.Write(responseId); + sshDataStream.Write((uint) names.Length); + sshDataStream.Write(namesAndAttributesBytes, 0, namesAndAttributesBytes.Length); + return sshDataStream.ToArray(); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestStatVfs.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestStatVfs.cs index b3188d3b..1fbc2a45 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestStatVfs.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestStatVfs.cs @@ -1,257 +1,257 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpSessionTest_Connected_RequestStatVfs - { - private Mock _sessionMock; - private Mock _channelSessionMock; - private SftpSession _sftpSession; - private TimeSpan _operationTimeout; - private SftpFileSytemInformation _actual; - private Encoding _encoding; - - private ulong _bAvail; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - - _operationTimeout = TimeSpan.FromMilliseconds(random.Next(100, 500)); - _encoding = Encoding.UTF8; - - _bAvail = (ulong) random.Next(0, int.MaxValue); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); - _channelSessionMock.InSequence(sequence).Setup(p => p.Open()); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest("sftp")).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - // generate response for SftpInitRequest - var versionInfoResponse = SftpVersionResponseBuilder.Create(3) - .AddExtension("statvfs@openssh.com", "") - .Build(); - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, versionInfoResponse)); - }); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - var sftpNameResponse = CreateSftpNameResponse(1, _encoding, "ABC"); - - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, sftpNameResponse)); - } - ); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - var statVfsReplyBuilder = StatVfsReplyBuilder.Create(2); - statVfsReplyBuilder.WithBAvail(_bAvail); - var statVfsReply = statVfsReplyBuilder.Build(); - - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, statVfsReply)); - } - ); - - _sftpSession = new SftpSession(_sessionMock.Object, _operationTimeout, _encoding); - _sftpSession.Connect(); - } - - protected void Act() - { - _actual = _sftpSession.RequestStatVfs("path"); - } - - [TestMethod] - public void ReturnedValueShouldNotBeNull() - { - Assert.IsNotNull(_actual); - } - - [TestMethod] - public void AvailableBlocksInReturnedValueShouldMatchValueInSftpResponse() - { - Assert.AreEqual(_bAvail, _actual.AvailableBlocks); - } - - private static byte[] CreateSftpNameResponse(uint responseId, Encoding encoding, params string[] names) - { - var namesAndAttributes = new List(); - foreach (var name in names) - { - var nameBytes = encoding.GetBytes(name); - var attributesBytes = SftpFileAttributes.Empty.GetBytes(); - - namesAndAttributes.AddRange((((uint) nameBytes.Length).GetBytes())); // filename length - namesAndAttributes.AddRange(nameBytes); // filename - namesAndAttributes.AddRange(((uint) 0).GetBytes()); // longname length - namesAndAttributes.AddRange(attributesBytes); // attributes - } - - var namesAndAttributesBytes = namesAndAttributes.ToArray(); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + namesAndAttributesBytes.Length); - sshDataStream.Write((uint) sshDataStream.Capacity - 4); - sshDataStream.WriteByte((byte) SftpMessageTypes.Name); - sshDataStream.Write(responseId); - sshDataStream.Write((uint) names.Length); - sshDataStream.Write(namesAndAttributesBytes, 0, namesAndAttributesBytes.Length); - return sshDataStream.ToArray(); - } - - public class StatVfsReplyBuilder - { - private readonly uint _responseId; - private ulong _bsize; - private ulong _frsize; - private ulong _blocks; - private ulong _bfree; - private ulong _bavail; - private ulong _files; - private ulong _ffree; - private ulong _favail; - private ulong _sid; - private ulong _flag; - private ulong _namemax; - - private StatVfsReplyBuilder(uint responseId) - { - _responseId = responseId; - } - - public static StatVfsReplyBuilder Create(uint responseId) - { - return new StatVfsReplyBuilder(responseId); - } - - public StatVfsReplyBuilder WithBSize(ulong bsize) - { - _bsize = bsize; - return this; - } - - public StatVfsReplyBuilder WithFrSize(ulong frsize) - { - _frsize = frsize; - return this; - } - - public StatVfsReplyBuilder WithBlocks(ulong blocks) - { - _blocks = blocks; - return this; - } - - public StatVfsReplyBuilder WithBFree(ulong bfree) - { - _bfree = bfree; - return this; - } - - public StatVfsReplyBuilder WithBAvail(ulong bavail) - { - _bavail = bavail; - return this; - } - - public StatVfsReplyBuilder WithFiles(ulong files) - { - _files = files; - return this; - } - - public StatVfsReplyBuilder WithFFree(ulong ffree) - { - _ffree = ffree; - return this; - } - - public StatVfsReplyBuilder WithFAvail(ulong favail) - { - _favail = favail; - return this; - } - - public StatVfsReplyBuilder WithSid(ulong sid) - { - _sid = sid; - return this; - } - - public StatVfsReplyBuilder WithIsReadOnly(bool isReadOnly) - { - if (isReadOnly) - _flag &= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_RDONLY; - else - _flag |= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_RDONLY; - - return this; - } - - public StatVfsReplyBuilder WithSupportsSetUid(bool supportsSetUid) - { - if (supportsSetUid) - _flag |= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_NOSUID; - else - _flag &= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_NOSUID; - - return this; - } - - public StatVfsReplyBuilder WithNameMax(ulong nameMax) - { - _namemax = nameMax; - return this; - } - - public byte[] Build() - { - var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); - sshDataStream.Write((uint) sshDataStream.Capacity - 4); - sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); - sshDataStream.Write(_responseId); - sshDataStream.Write(_bsize); - sshDataStream.Write(_frsize); - sshDataStream.Write(_blocks); - sshDataStream.Write(_bfree); - sshDataStream.Write(_bavail); - sshDataStream.Write(_files); - sshDataStream.Write(_ffree); - sshDataStream.Write(_favail); - sshDataStream.Write(_sid); - sshDataStream.Write(_flag); - sshDataStream.Write(_namemax); - return sshDataStream.ToArray(); - } - } - } +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpSessionTest_Connected_RequestStatVfs + { + private Mock _sessionMock; + private Mock _channelSessionMock; + private SftpSession _sftpSession; + private TimeSpan _operationTimeout; + private SftpFileSytemInformation _actual; + private Encoding _encoding; + + private ulong _bAvail; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + + _operationTimeout = TimeSpan.FromMilliseconds(random.Next(100, 500)); + _encoding = Encoding.UTF8; + + _bAvail = (ulong) random.Next(0, int.MaxValue); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); + _channelSessionMock.InSequence(sequence).Setup(p => p.Open()); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest("sftp")).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + // generate response for SftpInitRequest + var versionInfoResponse = SftpVersionResponseBuilder.Create(3) + .AddExtension("statvfs@openssh.com", "") + .Build(); + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, versionInfoResponse)); + }); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + var sftpNameResponse = CreateSftpNameResponse(1, _encoding, "ABC"); + + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, sftpNameResponse)); + } + ); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + var statVfsReplyBuilder = StatVfsReplyBuilder.Create(2); + statVfsReplyBuilder.WithBAvail(_bAvail); + var statVfsReply = statVfsReplyBuilder.Build(); + + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, statVfsReply)); + } + ); + + _sftpSession = new SftpSession(_sessionMock.Object, _operationTimeout, _encoding); + _sftpSession.Connect(); + } + + protected void Act() + { + _actual = _sftpSession.RequestStatVfs("path"); + } + + [TestMethod] + public void ReturnedValueShouldNotBeNull() + { + Assert.IsNotNull(_actual); + } + + [TestMethod] + public void AvailableBlocksInReturnedValueShouldMatchValueInSftpResponse() + { + Assert.AreEqual(_bAvail, _actual.AvailableBlocks); + } + + private static byte[] CreateSftpNameResponse(uint responseId, Encoding encoding, params string[] names) + { + var namesAndAttributes = new List(); + foreach (var name in names) + { + var nameBytes = encoding.GetBytes(name); + var attributesBytes = SftpFileAttributes.Empty.GetBytes(); + + namesAndAttributes.AddRange((((uint) nameBytes.Length).GetBytes())); // filename length + namesAndAttributes.AddRange(nameBytes); // filename + namesAndAttributes.AddRange(((uint) 0).GetBytes()); // longname length + namesAndAttributes.AddRange(attributesBytes); // attributes + } + + var namesAndAttributesBytes = namesAndAttributes.ToArray(); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + namesAndAttributesBytes.Length); + sshDataStream.Write((uint) sshDataStream.Capacity - 4); + sshDataStream.WriteByte((byte) SftpMessageTypes.Name); + sshDataStream.Write(responseId); + sshDataStream.Write((uint) names.Length); + sshDataStream.Write(namesAndAttributesBytes, 0, namesAndAttributesBytes.Length); + return sshDataStream.ToArray(); + } + + public class StatVfsReplyBuilder + { + private readonly uint _responseId; + private ulong _bsize; + private ulong _frsize; + private ulong _blocks; + private ulong _bfree; + private ulong _bavail; + private ulong _files; + private ulong _ffree; + private ulong _favail; + private ulong _sid; + private ulong _flag; + private ulong _namemax; + + private StatVfsReplyBuilder(uint responseId) + { + _responseId = responseId; + } + + public static StatVfsReplyBuilder Create(uint responseId) + { + return new StatVfsReplyBuilder(responseId); + } + + public StatVfsReplyBuilder WithBSize(ulong bsize) + { + _bsize = bsize; + return this; + } + + public StatVfsReplyBuilder WithFrSize(ulong frsize) + { + _frsize = frsize; + return this; + } + + public StatVfsReplyBuilder WithBlocks(ulong blocks) + { + _blocks = blocks; + return this; + } + + public StatVfsReplyBuilder WithBFree(ulong bfree) + { + _bfree = bfree; + return this; + } + + public StatVfsReplyBuilder WithBAvail(ulong bavail) + { + _bavail = bavail; + return this; + } + + public StatVfsReplyBuilder WithFiles(ulong files) + { + _files = files; + return this; + } + + public StatVfsReplyBuilder WithFFree(ulong ffree) + { + _ffree = ffree; + return this; + } + + public StatVfsReplyBuilder WithFAvail(ulong favail) + { + _favail = favail; + return this; + } + + public StatVfsReplyBuilder WithSid(ulong sid) + { + _sid = sid; + return this; + } + + public StatVfsReplyBuilder WithIsReadOnly(bool isReadOnly) + { + if (isReadOnly) + _flag &= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_RDONLY; + else + _flag |= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_RDONLY; + + return this; + } + + public StatVfsReplyBuilder WithSupportsSetUid(bool supportsSetUid) + { + if (supportsSetUid) + _flag |= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_NOSUID; + else + _flag &= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_NOSUID; + + return this; + } + + public StatVfsReplyBuilder WithNameMax(ulong nameMax) + { + _namemax = nameMax; + return this; + } + + public byte[] Build() + { + var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); + sshDataStream.Write((uint) sshDataStream.Capacity - 4); + sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); + sshDataStream.Write(_responseId); + sshDataStream.Write(_bsize); + sshDataStream.Write(_frsize); + sshDataStream.Write(_blocks); + sshDataStream.Write(_bfree); + sshDataStream.Write(_bavail); + sshDataStream.Write(_files); + sshDataStream.Write(_ffree); + sshDataStream.Write(_favail); + sshDataStream.Write(_sid); + sshDataStream.Write(_flag); + sshDataStream.Write(_namemax); + return sshDataStream.ToArray(); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSynchronizeDirectoriesAsyncResultTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSynchronizeDirectoriesAsyncResultTest.cs index 3f84f706..2a98c973 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSynchronizeDirectoriesAsyncResultTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSynchronizeDirectoriesAsyncResultTest.cs @@ -1,27 +1,27 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Sftp; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - /// - ///This is a test class for SftpSynchronizeDirectoriesAsyncResultTest and is intended - ///to contain all SftpSynchronizeDirectoriesAsyncResultTest Unit Tests - /// - [TestClass()] - public class SftpSynchronizeDirectoriesAsyncResultTest : TestBase - { - /// - ///A test for SftpSynchronizeDirectoriesAsyncResult Constructor - /// - [TestMethod()] - public void SftpSynchronizeDirectoriesAsyncResultConstructorTest() - { - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - SftpSynchronizeDirectoriesAsyncResult target = new SftpSynchronizeDirectoriesAsyncResult(asyncCallback, state); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Sftp; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + /// + ///This is a test class for SftpSynchronizeDirectoriesAsyncResultTest and is intended + ///to contain all SftpSynchronizeDirectoriesAsyncResultTest Unit Tests + /// + [TestClass()] + public class SftpSynchronizeDirectoriesAsyncResultTest : TestBase + { + /// + ///A test for SftpSynchronizeDirectoriesAsyncResult Constructor + /// + [TestMethod()] + public void SftpSynchronizeDirectoriesAsyncResultConstructorTest() + { + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + SftpSynchronizeDirectoriesAsyncResult target = new SftpSynchronizeDirectoriesAsyncResult(asyncCallback, state); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpUploadAsyncResultTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpUploadAsyncResultTest.cs index 81244c45..0194bca8 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpUploadAsyncResultTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpUploadAsyncResultTest.cs @@ -1,27 +1,27 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Sftp; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - /// - ///This is a test class for SftpUploadAsyncResultTest and is intended - ///to contain all SftpUploadAsyncResultTest Unit Tests - /// - [TestClass()] - public class SftpUploadAsyncResultTest : TestBase - { - /// - ///A test for SftpUploadAsyncResult Constructor - /// - [TestMethod()] - public void SftpUploadAsyncResultConstructorTest() - { - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - SftpUploadAsyncResult target = new SftpUploadAsyncResult(asyncCallback, state); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Sftp; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + /// + ///This is a test class for SftpUploadAsyncResultTest and is intended + ///to contain all SftpUploadAsyncResultTest Unit Tests + /// + [TestClass()] + public class SftpUploadAsyncResultTest : TestBase + { + /// + ///A test for SftpUploadAsyncResult Constructor + /// + [TestMethod()] + public void SftpUploadAsyncResultConstructorTest() + { + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + SftpUploadAsyncResult target = new SftpUploadAsyncResult(asyncCallback, state); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpVersionResponseBuilder.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpVersionResponseBuilder.cs index a8ef51d3..e5e1f670 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpVersionResponseBuilder.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpVersionResponseBuilder.cs @@ -1,53 +1,53 @@ -using System.Collections.Generic; -using System.Text; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - public class SftpVersionResponseBuilder - { - private readonly uint _version; - private readonly IDictionary _extensions; - - private SftpVersionResponseBuilder(uint version) - { - _version = version; - _extensions = new Dictionary(); - } - - public static SftpVersionResponseBuilder Create(uint version) - { - return new SftpVersionResponseBuilder(version); - } - - public SftpVersionResponseBuilder AddExtension(string name, string data) - { - _extensions.Add(name, data); - return this; - } - - public byte[] Build() - { - var extensions = BuildExtensions(); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + extensions.Length); - sshDataStream.Write((uint)sshDataStream.Capacity - 4); - sshDataStream.WriteByte((byte)SftpMessageTypes.Version); - sshDataStream.Write(_version); - sshDataStream.Write(extensions, 0, extensions.Length); - return sshDataStream.ToArray(); - } - - private byte[] BuildExtensions() - { - var sshDataStream = new SshDataStream(0); - foreach (var extensionPair in _extensions) - { - sshDataStream.Write(extensionPair.Key, Encoding.ASCII); - sshDataStream.Write(extensionPair.Value, Encoding.ASCII); - } - return sshDataStream.ToArray(); - } - } -} +using System.Collections.Generic; +using System.Text; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + public class SftpVersionResponseBuilder + { + private readonly uint _version; + private readonly IDictionary _extensions; + + private SftpVersionResponseBuilder(uint version) + { + _version = version; + _extensions = new Dictionary(); + } + + public static SftpVersionResponseBuilder Create(uint version) + { + return new SftpVersionResponseBuilder(version); + } + + public SftpVersionResponseBuilder AddExtension(string name, string data) + { + _extensions.Add(name, data); + return this; + } + + public byte[] Build() + { + var extensions = BuildExtensions(); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + extensions.Length); + sshDataStream.Write((uint)sshDataStream.Capacity - 4); + sshDataStream.WriteByte((byte)SftpMessageTypes.Version); + sshDataStream.Write(_version); + sshDataStream.Write(extensions, 0, extensions.Length); + return sshDataStream.ToArray(); + } + + private byte[] BuildExtensions() + { + var sshDataStream = new SshDataStream(0); + foreach (var extensionPair in _extensions) + { + sshDataStream.Write(extensionPair.Key, Encoding.ASCII); + sshDataStream.Write(extensionPair.Value, Encoding.ASCII); + } + return sshDataStream.ToArray(); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs index 2187639b..9ae69f6e 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs @@ -1,45 +1,45 @@ -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SftpClientTest_Connect - { - [TestMethod] - public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() - { - var connectionInfo = new ConnectionInfo("invalid.", 40, "user", - new KeyboardInteractiveAuthenticationMethod("user")); - var sftpClient = new SftpClient(connectionInfo); - - try - { - sftpClient.Connect(); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(ex.ErrorCode, (int) SocketError.HostNotFound); - } - } - - [TestMethod] - public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() - { - var connectionInfo = new ConnectionInfo("localhost", 40, "user", ProxyTypes.Http, "invalid.", 80, - "proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user")); - var sftpClient = new SftpClient(connectionInfo); - - try - { - sftpClient.Connect(); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); - } - } - } -} +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SftpClientTest_Connect + { + [TestMethod] + public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() + { + var connectionInfo = new ConnectionInfo("invalid.", 40, "user", + new KeyboardInteractiveAuthenticationMethod("user")); + var sftpClient = new SftpClient(connectionInfo); + + try + { + sftpClient.Connect(); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(ex.ErrorCode, (int) SocketError.HostNotFound); + } + } + + [TestMethod] + public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() + { + var connectionInfo = new ConnectionInfo("localhost", 40, "user", ProxyTypes.Http, "invalid.", 80, + "proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user")); + var sftpClient = new SftpClient(connectionInfo); + + try + { + sftpClient.Connect(); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs index 4714d705..5a9446f5 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs @@ -1,25 +1,25 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH. - /// - public partial class SftpClientTest : TestBase - { - [TestMethod] - [TestCategory("Sftp")] - [Description("Test passing null to DeleteFile.")] - [ExpectedException(typeof(ArgumentException))] - public void Test_Sftp_DeleteFile_Null() - { - using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - sftp.DeleteFile(null); - } - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH. + /// + public partial class SftpClientTest : TestBase + { + [TestMethod] + [TestCategory("Sftp")] + [Description("Test passing null to DeleteFile.")] + [ExpectedException(typeof(ArgumentException))] + public void Test_Sftp_DeleteFile_Null() + { + using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + sftp.DeleteFile(null); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest.cs index d779a5c6..6f4ec964 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest.cs @@ -1,1272 +1,1272 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Sftp; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; -using System.Collections.Generic; -using System.IO; -using System.Security.Cryptography; -using System.Text; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH. - /// - [TestClass] - public partial class SftpClientTest : TestBase - { - /// - ///A test for SftpClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SftpClientConstructorTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(host, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SftpClientConstructorTest1() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(host, port, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SftpClientConstructorTest2() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(host, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SftpClientConstructorTest3() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(host, port, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SftpClientConstructorTest4() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ChangePermissions - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ChangePermissionsTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - short mode = 0; // TODO: Initialize to an appropriate value - target.ChangePermissions(path, mode); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for ChangeDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ChangeDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - target.ChangeDirectory(path); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for BeginUploadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginUploadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - Action uploadCallback = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginUploadFile(input, path, asyncCallback, state, uploadCallback); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for BeginUploadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginUploadFileTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - bool canOverride = false; // TODO: Initialize to an appropriate value - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - Action uploadCallback = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginUploadFile(input, path, canOverride, asyncCallback, state, uploadCallback); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for BeginSynchronizeDirectories - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginSynchronizeDirectoriesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string sourcePath = string.Empty; // TODO: Initialize to an appropriate value - string destinationPath = string.Empty; // TODO: Initialize to an appropriate value - string searchPattern = string.Empty; // TODO: Initialize to an appropriate value - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginSynchronizeDirectories(sourcePath, destinationPath, searchPattern, asyncCallback, state); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for BeginListDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginListDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - Action listCallback = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginListDirectory(path, asyncCallback, state, listCallback); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for BeginDownloadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginDownloadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - Action downloadCallback = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginDownloadFile(path, output, asyncCallback, state, downloadCallback); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for AppendText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - StreamWriter expected = null; // TODO: Initialize to an appropriate value - StreamWriter actual; - actual = target.AppendText(path, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for AppendText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendTextTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - StreamWriter expected = null; // TODO: Initialize to an appropriate value - StreamWriter actual; - actual = target.AppendText(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for AppendAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendAllTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string contents = string.Empty; // TODO: Initialize to an appropriate value - target.AppendAllText(path, contents); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for AppendAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendAllTextTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string contents = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - target.AppendAllText(path, contents, encoding); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for AppendAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendAllLinesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable contents = null; // TODO: Initialize to an appropriate value - target.AppendAllLines(path, contents); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for AppendAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendAllLinesTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable contents = null; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - target.AppendAllLines(path, contents, encoding); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for CreateText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - StreamWriter expected = null; // TODO: Initialize to an appropriate value - StreamWriter actual; - actual = target.CreateText(path, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateTextTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - StreamWriter expected = null; // TODO: Initialize to an appropriate value - StreamWriter actual; - actual = target.CreateText(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - target.CreateDirectory(path); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Create - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.Create(path, bufferSize); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Create - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.Create(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EndSynchronizeDirectories - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EndSynchronizeDirectoriesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.EndSynchronizeDirectories(asyncResult); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EndListDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EndListDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.EndListDirectory(asyncResult); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EndDownloadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EndDownloadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value - target.EndDownloadFile(asyncResult); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for DownloadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DownloadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Action downloadCallback = null; // TODO: Initialize to an appropriate value - target.DownloadFile(path, output, downloadCallback); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for DeleteFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DeleteFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - target.DeleteFile(path); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for DeleteDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DeleteDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - target.DeleteDirectory(path); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Delete - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DeleteTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - target.Delete(path); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for GetLastAccessTimeUtc - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetLastAccessTimeUtcTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - actual = target.GetLastAccessTimeUtc(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GetLastAccessTime - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetLastAccessTimeTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - actual = target.GetLastAccessTime(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GetAttributes - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetAttributesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileAttributes expected = null; // TODO: Initialize to an appropriate value - SftpFileAttributes actual; - actual = target.GetAttributes(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Get - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFile expected = null; // TODO: Initialize to an appropriate value - SftpFile actual; - actual = target.Get(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Exists - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ExistsTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.Exists(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EndUploadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EndUploadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value - target.EndUploadFile(asyncResult); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for GetLastWriteTimeUtc - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetLastWriteTimeUtcTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - actual = target.GetLastWriteTimeUtc(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GetLastWriteTime - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetLastWriteTimeTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - actual = target.GetLastWriteTime(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GetStatus - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetStatusTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileSytemInformation expected = null; // TODO: Initialize to an appropriate value - SftpFileSytemInformation actual; - actual = target.GetStatus(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ListDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ListDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Action listCallback = null; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.ListDirectory(path, listCallback); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Open - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OpenTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - FileMode mode = new FileMode(); // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.Open(path, mode); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Open - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OpenTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - FileMode mode = new FileMode(); // TODO: Initialize to an appropriate value - FileAccess access = new FileAccess(); // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.Open(path, mode, access); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OpenRead - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OpenReadTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.OpenRead(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OpenText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OpenTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - StreamReader expected = null; // TODO: Initialize to an appropriate value - StreamReader actual; - actual = target.OpenText(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OpenWrite - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OpenWriteTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.OpenWrite(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadAllBytes - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadAllBytesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.ReadAllBytes(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadAllLinesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - actual = target.ReadAllLines(path, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadAllLinesTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - actual = target.ReadAllLines(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadAllTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - string expected = string.Empty; // TODO: Initialize to an appropriate value - string actual; - actual = target.ReadAllText(path, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadAllTextTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string expected = string.Empty; // TODO: Initialize to an appropriate value - string actual; - actual = target.ReadAllText(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadLinesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.ReadLines(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadLinesTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.ReadLines(path, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for RenameFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RenameFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string oldPath = string.Empty; // TODO: Initialize to an appropriate value - string newPath = string.Empty; // TODO: Initialize to an appropriate value - target.RenameFile(oldPath, newPath); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for RenameFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RenameFileTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string oldPath = string.Empty; // TODO: Initialize to an appropriate value - string newPath = string.Empty; // TODO: Initialize to an appropriate value - bool isPosix = false; // TODO: Initialize to an appropriate value - target.RenameFile(oldPath, newPath, isPosix); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SetAttributes - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SetAttributesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileAttributes fileAttributes = null; // TODO: Initialize to an appropriate value - target.SetAttributes(path, fileAttributes); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SetLastAccessTime - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SetLastAccessTimeTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime lastAccessTime = new DateTime(); // TODO: Initialize to an appropriate value - target.SetLastAccessTime(path, lastAccessTime); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SetLastAccessTimeUtc - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SetLastAccessTimeUtcTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime lastAccessTimeUtc = new DateTime(); // TODO: Initialize to an appropriate value - target.SetLastAccessTimeUtc(path, lastAccessTimeUtc); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SetLastWriteTime - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SetLastWriteTimeTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime lastWriteTime = new DateTime(); // TODO: Initialize to an appropriate value - target.SetLastWriteTime(path, lastWriteTime); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SetLastWriteTimeUtc - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SetLastWriteTimeUtcTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime lastWriteTimeUtc = new DateTime(); // TODO: Initialize to an appropriate value - target.SetLastWriteTimeUtc(path, lastWriteTimeUtc); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SymbolicLink - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SymbolicLinkTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string linkPath = string.Empty; // TODO: Initialize to an appropriate value - target.SymbolicLink(path, linkPath); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SynchronizeDirectories - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SynchronizeDirectoriesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string sourcePath = string.Empty; // TODO: Initialize to an appropriate value - string destinationPath = string.Empty; // TODO: Initialize to an appropriate value - string searchPattern = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.SynchronizeDirectories(sourcePath, destinationPath, searchPattern); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for UploadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void UploadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Action uploadCallback = null; // TODO: Initialize to an appropriate value - target.UploadFile(input, path, uploadCallback); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for UploadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void UploadFileTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - bool canOverride = false; // TODO: Initialize to an appropriate value - Action uploadCallback = null; // TODO: Initialize to an appropriate value - target.UploadFile(input, path, canOverride, uploadCallback); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllBytes - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllBytesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - byte[] bytes = null; // TODO: Initialize to an appropriate value - target.WriteAllBytes(path, bytes); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllLinesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable contents = null; // TODO: Initialize to an appropriate value - target.WriteAllLines(path, contents); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllLinesTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string[] contents = null; // TODO: Initialize to an appropriate value - target.WriteAllLines(path, contents); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllLinesTest2() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable contents = null; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - target.WriteAllLines(path, contents, encoding); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllLinesTest3() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string[] contents = null; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - target.WriteAllLines(path, contents, encoding); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string contents = string.Empty; // TODO: Initialize to an appropriate value - target.WriteAllText(path, contents); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllTextTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string contents = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - target.WriteAllText(path, contents, encoding); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for BufferSize - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BufferSizeTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - uint expected = 0; // TODO: Initialize to an appropriate value - uint actual; - target.BufferSize = expected; - actual = target.BufferSize; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OperationTimeout - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OperationTimeoutTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - TimeSpan expected = new TimeSpan(); // TODO: Initialize to an appropriate value - TimeSpan actual; - target.OperationTimeout = expected; - actual = target.OperationTimeout; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for WorkingDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WorkingDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string actual; - actual = target.WorkingDirectory; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - protected static string CalculateMD5(string fileName) - { - using (FileStream file = new FileStream(fileName, FileMode.Open)) - { - MD5 md5 = new MD5CryptoServiceProvider(); - byte[] retVal = md5.ComputeHash(file); - file.Close(); - - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < retVal.Length; i++) - { - sb.Append(retVal[i].ToString("x2")); - } - return sb.ToString(); - } - } - - private static void RemoveAllFiles() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - client.RunCommand("rm -rf *"); - client.Disconnect(); - } - } - - /// - /// Helper class to help with upload and download testing - /// - private class TestInfo - { - public string RemoteFileName { get; set; } - - public string UploadedFileName { get; set; } - - public string DownloadedFileName { get; set; } - - //public ulong UploadedBytes { get; set; } - - //public ulong DownloadedBytes { get; set; } - - public FileStream UploadedFile { get; set; } - - public FileStream DownloadedFile { get; set; } - - public string UploadedHash { get; set; } - - public string DownloadedHash { get; set; } - - public SftpUploadAsyncResult UploadResult { get; set; } - - public SftpDownloadAsyncResult DownloadResult { get; set; } - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Sftp; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; +using System.Collections.Generic; +using System.IO; +using System.Security.Cryptography; +using System.Text; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH. + /// + [TestClass] + public partial class SftpClientTest : TestBase + { + /// + ///A test for SftpClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SftpClientConstructorTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(host, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SftpClientConstructorTest1() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(host, port, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SftpClientConstructorTest2() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(host, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SftpClientConstructorTest3() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(host, port, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SftpClientConstructorTest4() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ChangePermissions + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ChangePermissionsTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + short mode = 0; // TODO: Initialize to an appropriate value + target.ChangePermissions(path, mode); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for ChangeDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ChangeDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + target.ChangeDirectory(path); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for BeginUploadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginUploadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + Action uploadCallback = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginUploadFile(input, path, asyncCallback, state, uploadCallback); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for BeginUploadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginUploadFileTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + bool canOverride = false; // TODO: Initialize to an appropriate value + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + Action uploadCallback = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginUploadFile(input, path, canOverride, asyncCallback, state, uploadCallback); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for BeginSynchronizeDirectories + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginSynchronizeDirectoriesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string sourcePath = string.Empty; // TODO: Initialize to an appropriate value + string destinationPath = string.Empty; // TODO: Initialize to an appropriate value + string searchPattern = string.Empty; // TODO: Initialize to an appropriate value + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginSynchronizeDirectories(sourcePath, destinationPath, searchPattern, asyncCallback, state); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for BeginListDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginListDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + Action listCallback = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginListDirectory(path, asyncCallback, state, listCallback); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for BeginDownloadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginDownloadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + Action downloadCallback = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginDownloadFile(path, output, asyncCallback, state, downloadCallback); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for AppendText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + StreamWriter expected = null; // TODO: Initialize to an appropriate value + StreamWriter actual; + actual = target.AppendText(path, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for AppendText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendTextTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + StreamWriter expected = null; // TODO: Initialize to an appropriate value + StreamWriter actual; + actual = target.AppendText(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for AppendAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendAllTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string contents = string.Empty; // TODO: Initialize to an appropriate value + target.AppendAllText(path, contents); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for AppendAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendAllTextTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string contents = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + target.AppendAllText(path, contents, encoding); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for AppendAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendAllLinesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable contents = null; // TODO: Initialize to an appropriate value + target.AppendAllLines(path, contents); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for AppendAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendAllLinesTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable contents = null; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + target.AppendAllLines(path, contents, encoding); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for CreateText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + StreamWriter expected = null; // TODO: Initialize to an appropriate value + StreamWriter actual; + actual = target.CreateText(path, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateTextTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + StreamWriter expected = null; // TODO: Initialize to an appropriate value + StreamWriter actual; + actual = target.CreateText(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + target.CreateDirectory(path); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Create + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.Create(path, bufferSize); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Create + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.Create(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EndSynchronizeDirectories + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EndSynchronizeDirectoriesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.EndSynchronizeDirectories(asyncResult); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EndListDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EndListDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.EndListDirectory(asyncResult); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EndDownloadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EndDownloadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value + target.EndDownloadFile(asyncResult); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for DownloadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DownloadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Action downloadCallback = null; // TODO: Initialize to an appropriate value + target.DownloadFile(path, output, downloadCallback); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for DeleteFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DeleteFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + target.DeleteFile(path); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for DeleteDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DeleteDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + target.DeleteDirectory(path); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Delete + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DeleteTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + target.Delete(path); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for GetLastAccessTimeUtc + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetLastAccessTimeUtcTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + actual = target.GetLastAccessTimeUtc(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GetLastAccessTime + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetLastAccessTimeTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + actual = target.GetLastAccessTime(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GetAttributes + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetAttributesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileAttributes expected = null; // TODO: Initialize to an appropriate value + SftpFileAttributes actual; + actual = target.GetAttributes(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Get + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFile expected = null; // TODO: Initialize to an appropriate value + SftpFile actual; + actual = target.Get(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Exists + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ExistsTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.Exists(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EndUploadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EndUploadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value + target.EndUploadFile(asyncResult); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for GetLastWriteTimeUtc + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetLastWriteTimeUtcTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + actual = target.GetLastWriteTimeUtc(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GetLastWriteTime + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetLastWriteTimeTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + actual = target.GetLastWriteTime(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GetStatus + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetStatusTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileSytemInformation expected = null; // TODO: Initialize to an appropriate value + SftpFileSytemInformation actual; + actual = target.GetStatus(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ListDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ListDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Action listCallback = null; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.ListDirectory(path, listCallback); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Open + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OpenTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + FileMode mode = new FileMode(); // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.Open(path, mode); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Open + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OpenTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + FileMode mode = new FileMode(); // TODO: Initialize to an appropriate value + FileAccess access = new FileAccess(); // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.Open(path, mode, access); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OpenRead + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OpenReadTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.OpenRead(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OpenText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OpenTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + StreamReader expected = null; // TODO: Initialize to an appropriate value + StreamReader actual; + actual = target.OpenText(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OpenWrite + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OpenWriteTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.OpenWrite(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadAllBytes + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadAllBytesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.ReadAllBytes(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadAllLinesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + actual = target.ReadAllLines(path, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadAllLinesTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + actual = target.ReadAllLines(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadAllTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + string expected = string.Empty; // TODO: Initialize to an appropriate value + string actual; + actual = target.ReadAllText(path, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadAllTextTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string expected = string.Empty; // TODO: Initialize to an appropriate value + string actual; + actual = target.ReadAllText(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadLinesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.ReadLines(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadLinesTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.ReadLines(path, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for RenameFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RenameFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string oldPath = string.Empty; // TODO: Initialize to an appropriate value + string newPath = string.Empty; // TODO: Initialize to an appropriate value + target.RenameFile(oldPath, newPath); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for RenameFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RenameFileTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string oldPath = string.Empty; // TODO: Initialize to an appropriate value + string newPath = string.Empty; // TODO: Initialize to an appropriate value + bool isPosix = false; // TODO: Initialize to an appropriate value + target.RenameFile(oldPath, newPath, isPosix); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SetAttributes + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SetAttributesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileAttributes fileAttributes = null; // TODO: Initialize to an appropriate value + target.SetAttributes(path, fileAttributes); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SetLastAccessTime + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SetLastAccessTimeTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime lastAccessTime = new DateTime(); // TODO: Initialize to an appropriate value + target.SetLastAccessTime(path, lastAccessTime); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SetLastAccessTimeUtc + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SetLastAccessTimeUtcTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime lastAccessTimeUtc = new DateTime(); // TODO: Initialize to an appropriate value + target.SetLastAccessTimeUtc(path, lastAccessTimeUtc); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SetLastWriteTime + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SetLastWriteTimeTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime lastWriteTime = new DateTime(); // TODO: Initialize to an appropriate value + target.SetLastWriteTime(path, lastWriteTime); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SetLastWriteTimeUtc + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SetLastWriteTimeUtcTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime lastWriteTimeUtc = new DateTime(); // TODO: Initialize to an appropriate value + target.SetLastWriteTimeUtc(path, lastWriteTimeUtc); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SymbolicLink + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SymbolicLinkTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string linkPath = string.Empty; // TODO: Initialize to an appropriate value + target.SymbolicLink(path, linkPath); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SynchronizeDirectories + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SynchronizeDirectoriesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string sourcePath = string.Empty; // TODO: Initialize to an appropriate value + string destinationPath = string.Empty; // TODO: Initialize to an appropriate value + string searchPattern = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.SynchronizeDirectories(sourcePath, destinationPath, searchPattern); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for UploadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void UploadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Action uploadCallback = null; // TODO: Initialize to an appropriate value + target.UploadFile(input, path, uploadCallback); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for UploadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void UploadFileTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + bool canOverride = false; // TODO: Initialize to an appropriate value + Action uploadCallback = null; // TODO: Initialize to an appropriate value + target.UploadFile(input, path, canOverride, uploadCallback); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllBytes + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllBytesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + byte[] bytes = null; // TODO: Initialize to an appropriate value + target.WriteAllBytes(path, bytes); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllLinesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable contents = null; // TODO: Initialize to an appropriate value + target.WriteAllLines(path, contents); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllLinesTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string[] contents = null; // TODO: Initialize to an appropriate value + target.WriteAllLines(path, contents); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllLinesTest2() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable contents = null; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + target.WriteAllLines(path, contents, encoding); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllLinesTest3() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string[] contents = null; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + target.WriteAllLines(path, contents, encoding); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string contents = string.Empty; // TODO: Initialize to an appropriate value + target.WriteAllText(path, contents); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllTextTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string contents = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + target.WriteAllText(path, contents, encoding); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for BufferSize + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BufferSizeTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + uint expected = 0; // TODO: Initialize to an appropriate value + uint actual; + target.BufferSize = expected; + actual = target.BufferSize; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OperationTimeout + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OperationTimeoutTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + TimeSpan expected = new TimeSpan(); // TODO: Initialize to an appropriate value + TimeSpan actual; + target.OperationTimeout = expected; + actual = target.OperationTimeout; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for WorkingDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WorkingDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string actual; + actual = target.WorkingDirectory; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + protected static string CalculateMD5(string fileName) + { + using (FileStream file = new FileStream(fileName, FileMode.Open)) + { + MD5 md5 = new MD5CryptoServiceProvider(); + byte[] retVal = md5.ComputeHash(file); + file.Close(); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < retVal.Length; i++) + { + sb.Append(retVal[i].ToString("x2")); + } + return sb.ToString(); + } + } + + private static void RemoveAllFiles() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + client.RunCommand("rm -rf *"); + client.Disconnect(); + } + } + + /// + /// Helper class to help with upload and download testing + /// + private class TestInfo + { + public string RemoteFileName { get; set; } + + public string UploadedFileName { get; set; } + + public string DownloadedFileName { get; set; } + + //public ulong UploadedBytes { get; set; } + + //public ulong DownloadedBytes { get; set; } + + public FileStream UploadedFile { get; set; } + + public FileStream DownloadedFile { get; set; } + + public string UploadedHash { get; set; } + + public string DownloadedHash { get; set; } + + public SftpUploadAsyncResult UploadResult { get; set; } + + public SftpDownloadAsyncResult DownloadResult { get; set; } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Connected.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Connected.cs index dae241e9..db06da60 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Connected.cs @@ -1,108 +1,108 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SftpClientTest_Dispose_Connected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SftpClient _sftpClient; - private ConnectionInfo _connectionInfo; - private Mock _sftpSessionMock; - private TimeSpan _operationTimeout; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); - _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sftpClient.OperationTimeout = _operationTimeout; - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) - .Returns(_sftpSessionMock.Object); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sftpClient.Connect(); - } - - protected void Act() - { - _sftpClient.Dispose(); - } - - [TestMethod] - public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify( - p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), - Times.Once); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SftpClientTest_Dispose_Connected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SftpClient _sftpClient; + private ConnectionInfo _connectionInfo; + private Mock _sftpSessionMock; + private TimeSpan _operationTimeout; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); + _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sftpClient.OperationTimeout = _operationTimeout; + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) + .Returns(_sftpSessionMock.Object); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sftpClient.Connect(); + } + + protected void Act() + { + _sftpClient.Dispose(); + } + + [TestMethod] + public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify( + p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), + Times.Once); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disconnected.cs index 9daf237d..d5e4f53c 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disconnected.cs @@ -1,109 +1,109 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SftpClientTest_Dispose_Disconnected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SftpClient _sftpClient; - private ConnectionInfo _connectionInfo; - private Mock _sftpSessionMock; - private TimeSpan _operationTimeout; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); - _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sftpClient.OperationTimeout = _operationTimeout; - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) - .Returns(_sftpSessionMock.Object); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sftpClient.Connect(); - _sftpClient.Disconnect(); - } - - protected void Act() - { - _sftpClient.Dispose(); - } - - [TestMethod] - public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify( - p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), - Times.Once); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SftpClientTest_Dispose_Disconnected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SftpClient _sftpClient; + private ConnectionInfo _connectionInfo; + private Mock _sftpSessionMock; + private TimeSpan _operationTimeout; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); + _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sftpClient.OperationTimeout = _operationTimeout; + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) + .Returns(_sftpSessionMock.Object); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sftpClient.Connect(); + _sftpClient.Disconnect(); + } + + protected void Act() + { + _sftpClient.Dispose(); + } + + [TestMethod] + public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify( + p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), + Times.Once); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disposed.cs index 841d705c..4fccdc72 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disposed.cs @@ -1,109 +1,109 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SftpClientTest_Dispose_Disposed - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SftpClient _sftpClient; - private ConnectionInfo _connectionInfo; - private Mock _sftpSessionMock; - private TimeSpan _operationTimeout; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); - _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sftpClient.OperationTimeout = _operationTimeout; - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) - .Returns(_sftpSessionMock.Object); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sftpClient.Connect(); - _sftpClient.Dispose(); - } - - protected void Act() - { - _sftpClient.Dispose(); - } - - [TestMethod] - public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify( - p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), - Times.Once); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SftpClientTest_Dispose_Disposed + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SftpClient _sftpClient; + private ConnectionInfo _connectionInfo; + private Mock _sftpSessionMock; + private TimeSpan _operationTimeout; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); + _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sftpClient.OperationTimeout = _operationTimeout; + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) + .Returns(_sftpSessionMock.Object); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sftpClient.Connect(); + _sftpClient.Dispose(); + } + + protected void Act() + { + _sftpClient.Dispose(); + } + + [TestMethod] + public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify( + p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), + Times.Once); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Finalize_Connected.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Finalize_Connected.cs index 9c95daac..5263f6ef 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Finalize_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Finalize_Connected.cs @@ -1,75 +1,75 @@ -using System; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SftpClientTest_Finalize_Connected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SftpClient _sftpClient; - private ConnectionInfo _connectionInfo; - private Mock _sftpSessionMock; - private TimeSpan _operationTimeout; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Loose); - _sessionMock = new Mock(MockBehavior.Strict); - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); - _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sftpClient.OperationTimeout = _operationTimeout; - - _serviceFactoryMock.Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.Setup(p => p.Connect()); - _serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) - .Returns(_sftpSessionMock.Object); - _sftpSessionMock.Setup(p => p.Connect()); - - _sftpClient.Connect(); - _sftpClient = null; - - _serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) - .Returns((ISftpSession) null); - _serviceFactoryMock.ResetCalls(); - - // we need to dereference all other mocks as they might otherwise hold the target alive - _sessionMock = null; - _connectionInfo = null; - _serviceFactoryMock = null; - } - - protected void Act() - { - GC.Collect(); - GC.WaitForPendingFinalizers(); - } - - [TestMethod] - public void DisconnectOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.Disconnect(), Times.Never); - } - - [TestMethod] - public void DisposeOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SftpClientTest_Finalize_Connected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SftpClient _sftpClient; + private ConnectionInfo _connectionInfo; + private Mock _sftpSessionMock; + private TimeSpan _operationTimeout; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Loose); + _sessionMock = new Mock(MockBehavior.Strict); + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); + _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sftpClient.OperationTimeout = _operationTimeout; + + _serviceFactoryMock.Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.Setup(p => p.Connect()); + _serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) + .Returns(_sftpSessionMock.Object); + _sftpSessionMock.Setup(p => p.Connect()); + + _sftpClient.Connect(); + _sftpClient = null; + + _serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) + .Returns((ISftpSession) null); + _serviceFactoryMock.ResetCalls(); + + // we need to dereference all other mocks as they might otherwise hold the target alive + _sessionMock = null; + _connectionInfo = null; + _serviceFactoryMock = null; + } + + protected void Act() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + } + + [TestMethod] + public void DisconnectOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.Disconnect(), Times.Never); + } + + [TestMethod] + public void DisposeOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ShellStream.cs b/src/Renci.SshNet.Tests/Classes/ShellStream.cs index 8640fb8e..f5d401af 100644 --- a/src/Renci.SshNet.Tests/Classes/ShellStream.cs +++ b/src/Renci.SshNet.Tests/Classes/ShellStream.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Contains operation for working with SSH Shell. - /// - [TestClass] - public class ShellStreamTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Contains operation for working with SSH Shell. + /// + [TestClass] + public class ShellStreamTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ShellStreamTest.cs b/src/Renci.SshNet.Tests/Classes/ShellStreamTest.cs index c3a944ec..df442ad2 100644 --- a/src/Renci.SshNet.Tests/Classes/ShellStreamTest.cs +++ b/src/Renci.SshNet.Tests/Classes/ShellStreamTest.cs @@ -1,118 +1,118 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Contains operation for working with SSH Shell. - /// - [TestClass] - public class ShellStreamTest : TestBase - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Encoding _encoding; - private string _terminalName; - private uint _widthColumns; - private uint _heightRows; - private uint _widthPixels; - private uint _heightPixels; - private Dictionary _terminalModes; - private Mock _channelSessionMock; - - protected override void OnInit() - { - base.OnInit(); - - 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(); - _terminalModes = new Dictionary(); - - _encoding = Encoding.UTF8; - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - _channelSessionMock = new Mock(MockBehavior.Strict); - } - - [TestMethod] // issue #2190 - public void ReadLine_MultiByteCharacters() - { - // 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"; - - var shellStream = CreateShellStream(); - - var channelDataPublishThread = new Thread(() => - { - _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"))); - }); - channelDataPublishThread.Start(); - - Assert.AreEqual(data1 + data2, shellStream.ReadLine()); - Assert.AreEqual(data3, shellStream.ReadLine()); - - channelDataPublishThread.Join(); - } - - [TestMethod] - public void Write_Text_ShouldWriteNothingWhenTextIsNull() - { - var shellStream = CreateShellStream(); - const string text = null; - - shellStream.Write(text); - - _channelSessionMock.Verify(p => p.SendData(It.IsAny()), Times.Never); - } - - [TestMethod] - public void WriteLine_Line_ShouldOnlyWriteLineTerminatorWhenLineIsNull() - { - var shellStream = CreateShellStream(); - const string line = null; - var lineTerminator = _encoding.GetBytes("\r"); - - _channelSessionMock.Setup(p => p.SendData(lineTerminator)); - - shellStream.WriteLine(line); - - _channelSessionMock.Verify(p => p.SendData(lineTerminator), Times.Once); - } - - private ShellStream CreateShellStream() - { - _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); - - return new ShellStream(_sessionMock.Object, _terminalName, _widthColumns, _heightRows, - _widthPixels, _heightPixels, _terminalModes); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Contains operation for working with SSH Shell. + /// + [TestClass] + public class ShellStreamTest : TestBase + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Encoding _encoding; + private string _terminalName; + private uint _widthColumns; + private uint _heightRows; + private uint _widthPixels; + private uint _heightPixels; + private Dictionary _terminalModes; + private Mock _channelSessionMock; + + protected override void OnInit() + { + base.OnInit(); + + 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(); + _terminalModes = new Dictionary(); + + _encoding = Encoding.UTF8; + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + _channelSessionMock = new Mock(MockBehavior.Strict); + } + + [TestMethod] // issue #2190 + public void ReadLine_MultiByteCharacters() + { + // 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"; + + var shellStream = CreateShellStream(); + + var channelDataPublishThread = new Thread(() => + { + _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"))); + }); + channelDataPublishThread.Start(); + + Assert.AreEqual(data1 + data2, shellStream.ReadLine()); + Assert.AreEqual(data3, shellStream.ReadLine()); + + channelDataPublishThread.Join(); + } + + [TestMethod] + public void Write_Text_ShouldWriteNothingWhenTextIsNull() + { + var shellStream = CreateShellStream(); + const string text = null; + + shellStream.Write(text); + + _channelSessionMock.Verify(p => p.SendData(It.IsAny()), Times.Never); + } + + [TestMethod] + public void WriteLine_Line_ShouldOnlyWriteLineTerminatorWhenLineIsNull() + { + var shellStream = CreateShellStream(); + const string line = null; + var lineTerminator = _encoding.GetBytes("\r"); + + _channelSessionMock.Setup(p => p.SendData(lineTerminator)); + + shellStream.WriteLine(line); + + _channelSessionMock.Verify(p => p.SendData(lineTerminator), Times.Once); + } + + private ShellStream CreateShellStream() + { + _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); + + return new ShellStream(_sessionMock.Object, _terminalName, _widthColumns, _heightRows, + _widthPixels, _heightPixels, _terminalModes); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ShellTestTest.cs b/src/Renci.SshNet.Tests/Classes/ShellTestTest.cs index 87246685..c7eceb1e 100644 --- a/src/Renci.SshNet.Tests/Classes/ShellTestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/ShellTestTest.cs @@ -1,82 +1,82 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using System.Collections.Generic; -using System.IO; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Represents instance of the SSH shell object - /// - [TestClass] - [Ignore] // class contains just for unit tests - public partial class ShellTestTest : TestBase - { - /// - ///A test for Dispose - /// - [TestMethod()] - public void DisposeTest() - { - Session session = null; // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = 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 - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Start - /// - [TestMethod()] - public void StartTest() - { - Session session = null; // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = 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 - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value - target.Start(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Stop - /// - [TestMethod()] - public void StopTest() - { - Session session = null; // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = 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 - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value - target.Stop(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using System.Collections.Generic; +using System.IO; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Represents instance of the SSH shell object + /// + [TestClass] + [Ignore] // class contains just for unit tests + public partial class ShellTestTest : TestBase + { + /// + ///A test for Dispose + /// + [TestMethod()] + public void DisposeTest() + { + Session session = null; // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = 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 + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Start + /// + [TestMethod()] + public void StartTest() + { + Session session = null; // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = 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 + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value + target.Start(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Stop + /// + [TestMethod()] + public void StopTest() + { + Session session = null; // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = 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 + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value + target.Stop(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest.cs index f06b5ba3..d7e295f8 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest.cs @@ -1,945 +1,945 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Linq; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides client connection to SSH server. - /// - [TestClass] - public class SshClientTest : TestBase - { - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Using_Correct_Password() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - #region Example SshClient(host, username) Connect - using (var client = new SshClient(host, username, password)) - { - client.Connect(); - // Do something here - client.Disconnect(); - } - #endregion - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Handle_HostKeyReceived() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - var hostKeyValidated = false; - - #region Example SshClient Connect HostKeyReceived - using (var client = new SshClient(host, username, password)) - { - client.HostKeyReceived += delegate(object sender, HostKeyEventArgs e) - { - hostKeyValidated = true; - - if (e.FingerPrint.SequenceEqual(new byte[] { 0x00, 0x01, 0x02, 0x03 })) - { - e.CanTrust = true; - } - else - { - e.CanTrust = false; - } - }; - client.Connect(); - // Do something here - client.Disconnect(); - } - #endregion - - Assert.IsTrue(hostKeyValidated); - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Timeout() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - #region Example SshClient Connect Timeout - var connectionInfo = new PasswordConnectionInfo(host, username, password); - - connectionInfo.Timeout = TimeSpan.FromSeconds(30); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - // Do something here - client.Disconnect(); - } - #endregion - Assert.Inconclusive(); - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Handle_ErrorOccurred() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - var exceptionOccured = false; - - #region Example SshClient Connect ErrorOccurred - using (var client = new SshClient(host, username, password)) - { - client.ErrorOccurred += delegate(object sender, ExceptionEventArgs e) - { - Console.WriteLine("Error occured: " + e.Exception.ToString()); - exceptionOccured = true; - }; - - client.Connect(); - // Do something here - client.Disconnect(); - } - #endregion - Assert.IsTrue(exceptionOccured); - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - [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] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Using_Rsa_Key_Without_PassPhrase() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); - - #region Example SshClient(host, username) Connect PrivateKeyFile - using (var client = new SshClient(host, username, new PrivateKeyFile(keyFileStream))) - { - client.Connect(); - client.Disconnect(); - } - #endregion - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Using_RsaKey_With_PassPhrase() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var passphrase = Resources.PASSWORD; - MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS)); - - #region Example SshClient(host, username) Connect PrivateKeyFile PassPhrase - using (var client = new SshClient(host, username, new PrivateKeyFile(keyFileStream, passphrase))) - { - client.Connect(); - client.Disconnect(); - } - #endregion - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - [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] - [TestCategory("Authentication")] - [TestCategory("integration")] - 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] - [TestCategory("Authentication")] - [TestCategory("integration")] - 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] - [TestCategory("Authentication")] - [TestCategory("integration")] - [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] - [TestCategory("Authentication")] - [TestCategory("integration")] - 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] - [TestCategory("Authentication")] - [TestCategory("integration")] - 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(); - } - } - - [TestMethod] - public void CreateShellStream1_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - const int bufferSize = 4096; - - try - { - client.CreateShellStream(terminalName, columns, rows, width, height, bufferSize); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShellStream2_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - var terminalModes = new Dictionary(); - const int bufferSize = 4096; - - try - { - client.CreateShellStream(terminalName, columns, rows, width, height, bufferSize, terminalModes); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - /// - ///A test for CreateShellStream - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellStreamTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // 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 bufferSize = 0; // TODO: Initialize to an appropriate value - IDictionary terminalModeValues = null; // TODO: Initialize to an appropriate value - ShellStream expected = null; // TODO: Initialize to an appropriate value - ShellStream actual; - actual = target.CreateShellStream(terminalName, columns, rows, width, height, bufferSize, terminalModeValues); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShellStream - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellStreamTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // 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 bufferSize = 0; // TODO: Initialize to an appropriate value - ShellStream expected = null; // TODO: Initialize to an appropriate value - ShellStream actual; - actual = target.CreateShellStream(terminalName, columns, rows, width, height, bufferSize); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - [TestMethod] - public void CreateShell1_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var encoding = Encoding.UTF8; - const string input = "INPUT"; - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - - - try - { - client.CreateShell(encoding, input, output, extendedOutput); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShell2_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var encoding = Encoding.UTF8; - const string input = "INPUT"; - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - var terminalModes = new Dictionary(); - - try - { - client.CreateShell( - encoding, - input, - output, - extendedOutput, - terminalName, - columns, - rows, - width, - height, - terminalModes); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShell3_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var encoding = Encoding.UTF8; - const string input = "INPUT"; - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - var terminalModes = new Dictionary(); - const int bufferSize = 4096; - - try - { - - client.CreateShell( - encoding, - input, - output, - extendedOutput, - terminalName, - columns, - rows, - width, - height, - terminalModes, - bufferSize); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShell4_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var input = new MemoryStream(); - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - - try - { - - client.CreateShell(input, output, extendedOutput); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShell5_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var input = new MemoryStream(); - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - var terminalModes = new Dictionary(); - - try - { - client.CreateShell( - input, - output, - extendedOutput, - terminalName, - columns, - rows, - width, - height, - terminalModes); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShell6_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var input = new MemoryStream(); - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - var terminalModes = new Dictionary(); - const int bufferSize = 4096; - - try - { - - client.CreateShell( - input, - output, - extendedOutput, - terminalName, - columns, - rows, - width, - height, - terminalModes, - bufferSize); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - string input = string.Empty; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = null; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(encoding, input, output, extendedOutput); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - string input = string.Empty; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = 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 - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(encoding, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest2() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - string input = string.Empty; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = 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 - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(encoding, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest3() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = null; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(input, output, extendedOutput); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest4() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = 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 - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest5() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = 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 - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - [TestMethod] - public void CreateCommand_CommandText_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - try - { - client.CreateCommand("ls"); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateCommand_CommandTextAndEncoding_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - try - { - client.CreateCommand("ls", Encoding.UTF8); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - /// - ///A test for CreateCommand - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateCommandTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - SshCommand expected = null; // TODO: Initialize to an appropriate value - SshCommand actual; - actual = target.CreateCommand(commandText, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateCommand - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateCommandTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - SshCommand expected = null; // TODO: Initialize to an appropriate value - SshCommand actual; - actual = target.CreateCommand(commandText); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - - [TestMethod] - public void AddForwardedPort_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var port = new ForwardedPortLocal(50, "host", 8080); - - try - { - client.AddForwardedPort(port); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - - /// - ///A test for AddForwardedPort - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AddForwardedPortTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - ForwardedPort port = null; // TODO: Initialize to an appropriate value - target.AddForwardedPort(port); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SshClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SshClientConstructorTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(host, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SshClientConstructorTest1() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(host, port, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SshClientConstructorTest2() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(host, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SshClientConstructorTest3() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(host, port, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SshClientConstructorTest4() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for RemoveForwardedPort - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RemoveForwardedPortTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - ForwardedPort port = null; // TODO: Initialize to an appropriate value - target.RemoveForwardedPort(port); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - [TestMethod] - public void RunCommand_CommandText_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - try - { - client.RunCommand("ls"); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - /// - ///A test for RunCommand - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RunCommandTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - SshCommand expected = null; // TODO: Initialize to an appropriate value - SshCommand actual; - actual = target.RunCommand(commandText); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ForwardedPorts - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ForwardedPortsTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.ForwardedPorts; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Linq; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides client connection to SSH server. + /// + [TestClass] + public class SshClientTest : TestBase + { + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Using_Correct_Password() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + #region Example SshClient(host, username) Connect + using (var client = new SshClient(host, username, password)) + { + client.Connect(); + // Do something here + client.Disconnect(); + } + #endregion + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Handle_HostKeyReceived() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + var hostKeyValidated = false; + + #region Example SshClient Connect HostKeyReceived + using (var client = new SshClient(host, username, password)) + { + client.HostKeyReceived += delegate(object sender, HostKeyEventArgs e) + { + hostKeyValidated = true; + + if (e.FingerPrint.SequenceEqual(new byte[] { 0x00, 0x01, 0x02, 0x03 })) + { + e.CanTrust = true; + } + else + { + e.CanTrust = false; + } + }; + client.Connect(); + // Do something here + client.Disconnect(); + } + #endregion + + Assert.IsTrue(hostKeyValidated); + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Timeout() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + #region Example SshClient Connect Timeout + var connectionInfo = new PasswordConnectionInfo(host, username, password); + + connectionInfo.Timeout = TimeSpan.FromSeconds(30); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + // Do something here + client.Disconnect(); + } + #endregion + Assert.Inconclusive(); + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Handle_ErrorOccurred() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + var exceptionOccured = false; + + #region Example SshClient Connect ErrorOccurred + using (var client = new SshClient(host, username, password)) + { + client.ErrorOccurred += delegate(object sender, ExceptionEventArgs e) + { + Console.WriteLine("Error occured: " + e.Exception.ToString()); + exceptionOccured = true; + }; + + client.Connect(); + // Do something here + client.Disconnect(); + } + #endregion + Assert.IsTrue(exceptionOccured); + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + [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] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Using_Rsa_Key_Without_PassPhrase() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); + + #region Example SshClient(host, username) Connect PrivateKeyFile + using (var client = new SshClient(host, username, new PrivateKeyFile(keyFileStream))) + { + client.Connect(); + client.Disconnect(); + } + #endregion + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Using_RsaKey_With_PassPhrase() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var passphrase = Resources.PASSWORD; + MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS)); + + #region Example SshClient(host, username) Connect PrivateKeyFile PassPhrase + using (var client = new SshClient(host, username, new PrivateKeyFile(keyFileStream, passphrase))) + { + client.Connect(); + client.Disconnect(); + } + #endregion + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + [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] + [TestCategory("Authentication")] + [TestCategory("integration")] + 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] + [TestCategory("Authentication")] + [TestCategory("integration")] + 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] + [TestCategory("Authentication")] + [TestCategory("integration")] + [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] + [TestCategory("Authentication")] + [TestCategory("integration")] + 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] + [TestCategory("Authentication")] + [TestCategory("integration")] + 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(); + } + } + + [TestMethod] + public void CreateShellStream1_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + const int bufferSize = 4096; + + try + { + client.CreateShellStream(terminalName, columns, rows, width, height, bufferSize); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShellStream2_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + var terminalModes = new Dictionary(); + const int bufferSize = 4096; + + try + { + client.CreateShellStream(terminalName, columns, rows, width, height, bufferSize, terminalModes); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + /// + ///A test for CreateShellStream + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellStreamTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // 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 bufferSize = 0; // TODO: Initialize to an appropriate value + IDictionary terminalModeValues = null; // TODO: Initialize to an appropriate value + ShellStream expected = null; // TODO: Initialize to an appropriate value + ShellStream actual; + actual = target.CreateShellStream(terminalName, columns, rows, width, height, bufferSize, terminalModeValues); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShellStream + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellStreamTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // 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 bufferSize = 0; // TODO: Initialize to an appropriate value + ShellStream expected = null; // TODO: Initialize to an appropriate value + ShellStream actual; + actual = target.CreateShellStream(terminalName, columns, rows, width, height, bufferSize); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + [TestMethod] + public void CreateShell1_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var encoding = Encoding.UTF8; + const string input = "INPUT"; + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + + + try + { + client.CreateShell(encoding, input, output, extendedOutput); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShell2_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var encoding = Encoding.UTF8; + const string input = "INPUT"; + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + var terminalModes = new Dictionary(); + + try + { + client.CreateShell( + encoding, + input, + output, + extendedOutput, + terminalName, + columns, + rows, + width, + height, + terminalModes); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShell3_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var encoding = Encoding.UTF8; + const string input = "INPUT"; + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + var terminalModes = new Dictionary(); + const int bufferSize = 4096; + + try + { + + client.CreateShell( + encoding, + input, + output, + extendedOutput, + terminalName, + columns, + rows, + width, + height, + terminalModes, + bufferSize); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShell4_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var input = new MemoryStream(); + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + + try + { + + client.CreateShell(input, output, extendedOutput); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShell5_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var input = new MemoryStream(); + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + var terminalModes = new Dictionary(); + + try + { + client.CreateShell( + input, + output, + extendedOutput, + terminalName, + columns, + rows, + width, + height, + terminalModes); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShell6_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var input = new MemoryStream(); + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + var terminalModes = new Dictionary(); + const int bufferSize = 4096; + + try + { + + client.CreateShell( + input, + output, + extendedOutput, + terminalName, + columns, + rows, + width, + height, + terminalModes, + bufferSize); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + string input = string.Empty; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = null; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(encoding, input, output, extendedOutput); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + string input = string.Empty; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = 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 + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(encoding, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest2() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + string input = string.Empty; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = 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 + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(encoding, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest3() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = null; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(input, output, extendedOutput); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest4() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = 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 + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest5() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = 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 + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + [TestMethod] + public void CreateCommand_CommandText_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + try + { + client.CreateCommand("ls"); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateCommand_CommandTextAndEncoding_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + try + { + client.CreateCommand("ls", Encoding.UTF8); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + /// + ///A test for CreateCommand + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateCommandTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + SshCommand expected = null; // TODO: Initialize to an appropriate value + SshCommand actual; + actual = target.CreateCommand(commandText, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateCommand + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateCommandTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + SshCommand expected = null; // TODO: Initialize to an appropriate value + SshCommand actual; + actual = target.CreateCommand(commandText); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + + [TestMethod] + public void AddForwardedPort_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var port = new ForwardedPortLocal(50, "host", 8080); + + try + { + client.AddForwardedPort(port); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + + /// + ///A test for AddForwardedPort + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AddForwardedPortTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + ForwardedPort port = null; // TODO: Initialize to an appropriate value + target.AddForwardedPort(port); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SshClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SshClientConstructorTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(host, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SshClientConstructorTest1() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(host, port, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SshClientConstructorTest2() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(host, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SshClientConstructorTest3() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(host, port, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SshClientConstructorTest4() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for RemoveForwardedPort + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RemoveForwardedPortTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + ForwardedPort port = null; // TODO: Initialize to an appropriate value + target.RemoveForwardedPort(port); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + [TestMethod] + public void RunCommand_CommandText_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + try + { + client.RunCommand("ls"); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + /// + ///A test for RunCommand + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RunCommandTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + SshCommand expected = null; // TODO: Initialize to an appropriate value + SshCommand actual; + actual = target.RunCommand(commandText); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ForwardedPorts + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ForwardedPortsTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.ForwardedPorts; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest_Disconnect_ForwardedPortStarted.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest_Disconnect_ForwardedPortStarted.cs index 0bf21792..4fe4116d 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest_Disconnect_ForwardedPortStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest_Disconnect_ForwardedPortStarted.cs @@ -1,82 +1,82 @@ -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshClientTest_Disconnect_ForwardedPortStarted - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private Mock _forwardedPortMock; - private SshClient _sshClient; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - - var sequence = new MockSequence(); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _forwardedPortMock = new Mock(MockBehavior.Strict); - - _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _forwardedPortMock.InSequence(sequence).Setup(p => p.Start()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _forwardedPortMock.InSequence(sequence).Setup(p => p.Stop()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sshClient.Connect(); - _sshClient.AddForwardedPort(_forwardedPortMock.Object); - - _forwardedPortMock.Object.Start(); - } - - protected void Act() - { - _sshClient.Disconnect(); - } - - [TestMethod] - public void ForwardedPortShouldBeStopped() - { - _forwardedPortMock.Verify(p => p.Stop(), Times.Once); - } - - [TestMethod] - public void ForwardedPortShouldBeRemovedFromSshClient() - { - Assert.IsFalse(_sshClient.ForwardedPorts.Any()); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshClientTest_Disconnect_ForwardedPortStarted + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private Mock _forwardedPortMock; + private SshClient _sshClient; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + + var sequence = new MockSequence(); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _forwardedPortMock = new Mock(MockBehavior.Strict); + + _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _forwardedPortMock.InSequence(sequence).Setup(p => p.Start()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _forwardedPortMock.InSequence(sequence).Setup(p => p.Stop()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sshClient.Connect(); + _sshClient.AddForwardedPort(_forwardedPortMock.Object); + + _forwardedPortMock.Object.Start(); + } + + protected void Act() + { + _sshClient.Disconnect(); + } + + [TestMethod] + public void ForwardedPortShouldBeStopped() + { + _forwardedPortMock.Verify(p => p.Stop(), Times.Once); + } + + [TestMethod] + public void ForwardedPortShouldBeRemovedFromSshClient() + { + Assert.IsFalse(_sshClient.ForwardedPorts.Any()); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Connected.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Connected.cs index 50e14468..584d0b5e 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Connected.cs @@ -1,73 +1,73 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshClientTest_Dispose_Connected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SshClient _sshClient; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sshClient.Connect(); - } - - protected void Act() - { - _sshClient.Dispose(); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshClientTest_Dispose_Connected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SshClient _sshClient; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sshClient.Connect(); + } + + protected void Act() + { + _sshClient.Dispose(); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disconnected.cs index 9c250e46..5590db59 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disconnected.cs @@ -1,74 +1,74 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshClientTest_Dispose_Disconnected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SshClient _sshClient; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sshClient.Connect(); - _sshClient.Disconnect(); - } - - protected void Act() - { - _sshClient.Dispose(); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshClientTest_Dispose_Disconnected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SshClient _sshClient; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sshClient.Connect(); + _sshClient.Disconnect(); + } + + protected void Act() + { + _sshClient.Dispose(); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disposed.cs index 35a713c6..4ac9cee3 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disposed.cs @@ -1,74 +1,74 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshClientTest_Dispose_Disposed - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SshClient _sshClient; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sshClient.Connect(); - _sshClient.Dispose(); - } - - protected void Act() - { - _sshClient.Dispose(); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshClientTest_Dispose_Disposed + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SshClient _sshClient; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sshClient.Connect(); + _sshClient.Dispose(); + } + + protected void Act() + { + _sshClient.Dispose(); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_ForwardedPortStarted.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_ForwardedPortStarted.cs index 4f45f580..193b1205 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_ForwardedPortStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_ForwardedPortStarted.cs @@ -1,97 +1,97 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshClientTest_Dispose_ForwardedPortStarted - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private Mock _forwardedPortMock; - private SshClient _sshClient; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - - var sequence = new MockSequence(); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _forwardedPortMock = new Mock(MockBehavior.Strict); - - _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _forwardedPortMock.InSequence(sequence).Setup(p => p.Start()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _forwardedPortMock.InSequence(sequence).Setup(p => p.Stop()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sshClient.Connect(); - _sshClient.AddForwardedPort(_forwardedPortMock.Object); - - _forwardedPortMock.Object.Start(); - } - - protected void Act() - { - _sshClient.Dispose(); - } - - [TestMethod] - public void ForwardedPortShouldBeStopped() - { - _forwardedPortMock.Verify(p => p.Stop(), Times.Once); - } - - [TestMethod] - public void ForwardedPortShouldBeRemovedFromSshClient() - { - Assert.IsFalse(_sshClient.ForwardedPorts.Any()); - } - - [TestMethod] - public void IsConnectedShouldThrowObjectDisposedException() - { - try - { - var connected = _sshClient.IsConnected; - Assert.Fail("IsConnected should have thrown {0} but returned {1}.", - typeof (ObjectDisposedException).FullName, connected); - } - catch (ObjectDisposedException) - { - } - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshClientTest_Dispose_ForwardedPortStarted + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private Mock _forwardedPortMock; + private SshClient _sshClient; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + + var sequence = new MockSequence(); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _forwardedPortMock = new Mock(MockBehavior.Strict); + + _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _forwardedPortMock.InSequence(sequence).Setup(p => p.Start()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _forwardedPortMock.InSequence(sequence).Setup(p => p.Stop()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sshClient.Connect(); + _sshClient.AddForwardedPort(_forwardedPortMock.Object); + + _forwardedPortMock.Object.Start(); + } + + protected void Act() + { + _sshClient.Dispose(); + } + + [TestMethod] + public void ForwardedPortShouldBeStopped() + { + _forwardedPortMock.Verify(p => p.Stop(), Times.Once); + } + + [TestMethod] + public void ForwardedPortShouldBeRemovedFromSshClient() + { + Assert.IsFalse(_sshClient.ForwardedPorts.Any()); + } + + [TestMethod] + public void IsConnectedShouldThrowObjectDisposedException() + { + try + { + var connected = _sshClient.IsConnected; + Assert.Fail("IsConnected should have thrown {0} but returned {1}.", + typeof (ObjectDisposedException).FullName, connected); + } + catch (ObjectDisposedException) + { + } + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SshCommandTest.NET40.cs b/src/Renci.SshNet.Tests/Classes/SshCommandTest.NET40.cs index 6fd3b088..589c6881 100644 --- a/src/Renci.SshNet.Tests/Classes/SshCommandTest.NET40.cs +++ b/src/Renci.SshNet.Tests/Classes/SshCommandTest.NET40.cs @@ -1,100 +1,100 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Properties; -using System; -using System.Diagnostics; -using System.Threading.Tasks; - -namespace Renci.SshNet.Tests.Classes -{ - public partial class SshCommandTest - { - - public void Test_MultipleThread_Example_MultipleConnections() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - try - { - #region Example SshCommand RunCommand Parallel - System.Threading.Tasks.Parallel.For(0, 10000, - () => - { - var client = new SshClient(host, username, password); - client.Connect(); - return client; - }, - (int counter, ParallelLoopState pls, SshClient client) => - { - var result = client.RunCommand("echo 123"); - Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter)); - return client; - }, - (SshClient client) => - { - client.Disconnect(); - client.Dispose(); - } - ); - #endregion - - } - catch (Exception exp) - { - Assert.Fail(exp.ToString()); - } - } - - //[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_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(); - } - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Properties; +using System; +using System.Diagnostics; +using System.Threading.Tasks; + +namespace Renci.SshNet.Tests.Classes +{ + public partial class SshCommandTest + { + + public void Test_MultipleThread_Example_MultipleConnections() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + try + { + #region Example SshCommand RunCommand Parallel + System.Threading.Tasks.Parallel.For(0, 10000, + () => + { + var client = new SshClient(host, username, password); + client.Connect(); + return client; + }, + (int counter, ParallelLoopState pls, SshClient client) => + { + var result = client.RunCommand("echo 123"); + Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter)); + return client; + }, + (SshClient client) => + { + client.Disconnect(); + client.Dispose(); + } + ); + #endregion + + } + catch (Exception exp) + { + Assert.Fail(exp.ToString()); + } + } + + //[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_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(); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SshCommandTest.cs b/src/Renci.SshNet.Tests/Classes/SshCommandTest.cs index fc4a3b0e..c1979ce3 100644 --- a/src/Renci.SshNet.Tests/Classes/SshCommandTest.cs +++ b/src/Renci.SshNet.Tests/Classes/SshCommandTest.cs @@ -1,635 +1,635 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; -using System.IO; -using System.Text; -using System.Threading; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Represents SSH command that can be executed. - /// - [TestClass] - public partial class SshCommandTest : TestBase - { - [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] - [TestCategory("integration")] - public void Test_Run_SingleCommand() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - using (var client = new SshClient(host, username, password)) - { - #region Example SshCommand RunCommand Result - client.Connect(); - - var testValue = Guid.NewGuid().ToString(); - var command = client.RunCommand(string.Format("echo {0}", testValue)); - var result = command.Result; - result = result.Substring(0, result.Length - 1); // Remove \n character returned by command - - client.Disconnect(); - #endregion - - Assert.IsTrue(result.Equals(testValue)); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_SingleCommand() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - using (var client = new SshClient(host, username, password)) - { - #region Example SshCommand CreateCommand Execute - client.Connect(); - - var testValue = Guid.NewGuid().ToString(); - var command = string.Format("echo {0}", testValue); - var cmd = client.CreateCommand(command); - var result = cmd.Execute(); - result = result.Substring(0, result.Length - 1); // Remove \n character returned by command - - client.Disconnect(); - #endregion - - Assert.IsTrue(result.Equals(testValue)); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_OutputStream() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - using (var client = new SshClient(host, username, password)) - { - #region Example SshCommand CreateCommand Execute OutputStream - client.Connect(); - - var cmd = client.CreateCommand("ls -l"); // very long list - var asynch = cmd.BeginExecute(); - - var reader = new StreamReader(cmd.OutputStream); - - while (!asynch.IsCompleted) - { - var result = reader.ReadToEnd(); - if (string.IsNullOrEmpty(result)) - continue; - Console.Write(result); - } - cmd.EndExecute(asynch); - - client.Disconnect(); - #endregion - - Assert.Inconclusive(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_ExtendedOutputStream() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - using (var client = new SshClient(host, username, password)) - { - #region Example SshCommand CreateCommand Execute ExtendedOutputStream - - client.Connect(); - var cmd = client.CreateCommand("echo 12345; echo 654321 >&2"); - var result = cmd.Execute(); - - Console.Write(result); - - var reader = new StreamReader(cmd.ExtendedOutputStream); - Console.WriteLine("DEBUG:"); - Console.Write(reader.ReadToEnd()); - - client.Disconnect(); - - #endregion - - Assert.Inconclusive(); - } - } - - [TestMethod] - [TestCategory("integration")] - [ExpectedException(typeof(SshOperationTimeoutException))] - public void Test_Execute_Timeout() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - #region Example SshCommand CreateCommand Execute CommandTimeout - client.Connect(); - var cmd = client.CreateCommand("sleep 10s"); - cmd.CommandTimeout = TimeSpan.FromSeconds(5); - cmd.Execute(); - client.Disconnect(); - #endregion - } - } - - [TestMethod] - [TestCategory("integration")] - 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] - [TestCategory("integration")] - 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] - [TestCategory("integration")] - 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] - [TestCategory("integration")] - 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] - [TestCategory("integration")] - 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] - [TestCategory("integration")] - public void Test_Execute_Command_ExitStatus() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - #region Example SshCommand RunCommand ExitStatus - client.Connect(); - - var cmd = client.RunCommand("exit 128"); - - Console.WriteLine(cmd.ExitStatus); - - client.Disconnect(); - #endregion - - Assert.IsTrue(cmd.ExitStatus == 128); - } - } - - [TestMethod] - [TestCategory("integration")] - 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] - [TestCategory("integration")] - 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] - [TestCategory("integration")] - 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] - [TestCategory("integration")] - 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(); - } - } - - /// - /// Tests for Issue 563. - /// - [WorkItem(563), TestMethod] - [TestCategory("integration")] - 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] - [TestCategory("integration")] - 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] - [TestCategory("integration")] - 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))] - [TestCategory("integration")] - 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(); - } - } - - /// - ///A test for BeginExecute - /// - [TestMethod()] - [TestCategory("integration")] - public void BeginExecuteTest() - { - string expected = "123\n"; - string result; - - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - #region Example SshCommand CreateCommand BeginExecute IsCompleted EndExecute - - client.Connect(); - - var cmd = client.CreateCommand("sleep 15s;echo 123"); // Perform long running task - - var asynch = cmd.BeginExecute(); - - while (!asynch.IsCompleted) - { - // Waiting for command to complete... - Thread.Sleep(2000); - } - result = cmd.EndExecute(asynch); - client.Disconnect(); - - #endregion - - Assert.IsNotNull(asynch); - Assert.AreEqual(expected, result); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_Invalid_Command() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - #region Example SshCommand CreateCommand Error - - client.Connect(); - - var cmd = client.CreateCommand(";"); - cmd.Execute(); - if (!string.IsNullOrEmpty(cmd.Error)) - { - Console.WriteLine(cmd.Error); - } - - client.Disconnect(); - - #endregion - - Assert.Inconclusive(); - } - } - - - /// - ///A test for BeginExecute - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginExecuteTest1() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - string commandText1 = string.Empty; // TODO: Initialize to an appropriate value - AsyncCallback callback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginExecute(commandText1, callback, state); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CancelAsync - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CancelAsyncTest() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - target.CancelAsync(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - - /// - ///A test for Execute - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ExecuteTest() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - string expected = string.Empty; // TODO: Initialize to an appropriate value - string actual; - actual = target.Execute(); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Execute - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ExecuteTest1() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - string commandText1 = string.Empty; // TODO: Initialize to an appropriate value - string expected = string.Empty; // TODO: Initialize to an appropriate value - string actual; - actual = target.Execute(commandText1); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CommandTimeout - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CommandTimeoutTest() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - TimeSpan expected = new TimeSpan(); // TODO: Initialize to an appropriate value - TimeSpan actual; - target.CommandTimeout = expected; - actual = target.CommandTimeout; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Error - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ErrorTest() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - string actual; - actual = target.Error; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Result - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ResultTest() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - string actual; - actual = target.Result; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - 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); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; +using System.IO; +using System.Text; +using System.Threading; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Represents SSH command that can be executed. + /// + [TestClass] + public partial class SshCommandTest : TestBase + { + [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] + [TestCategory("integration")] + public void Test_Run_SingleCommand() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + using (var client = new SshClient(host, username, password)) + { + #region Example SshCommand RunCommand Result + client.Connect(); + + var testValue = Guid.NewGuid().ToString(); + var command = client.RunCommand(string.Format("echo {0}", testValue)); + var result = command.Result; + result = result.Substring(0, result.Length - 1); // Remove \n character returned by command + + client.Disconnect(); + #endregion + + Assert.IsTrue(result.Equals(testValue)); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_SingleCommand() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + using (var client = new SshClient(host, username, password)) + { + #region Example SshCommand CreateCommand Execute + client.Connect(); + + var testValue = Guid.NewGuid().ToString(); + var command = string.Format("echo {0}", testValue); + var cmd = client.CreateCommand(command); + var result = cmd.Execute(); + result = result.Substring(0, result.Length - 1); // Remove \n character returned by command + + client.Disconnect(); + #endregion + + Assert.IsTrue(result.Equals(testValue)); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_OutputStream() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + using (var client = new SshClient(host, username, password)) + { + #region Example SshCommand CreateCommand Execute OutputStream + client.Connect(); + + var cmd = client.CreateCommand("ls -l"); // very long list + var asynch = cmd.BeginExecute(); + + var reader = new StreamReader(cmd.OutputStream); + + while (!asynch.IsCompleted) + { + var result = reader.ReadToEnd(); + if (string.IsNullOrEmpty(result)) + continue; + Console.Write(result); + } + cmd.EndExecute(asynch); + + client.Disconnect(); + #endregion + + Assert.Inconclusive(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_ExtendedOutputStream() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + using (var client = new SshClient(host, username, password)) + { + #region Example SshCommand CreateCommand Execute ExtendedOutputStream + + client.Connect(); + var cmd = client.CreateCommand("echo 12345; echo 654321 >&2"); + var result = cmd.Execute(); + + Console.Write(result); + + var reader = new StreamReader(cmd.ExtendedOutputStream); + Console.WriteLine("DEBUG:"); + Console.Write(reader.ReadToEnd()); + + client.Disconnect(); + + #endregion + + Assert.Inconclusive(); + } + } + + [TestMethod] + [TestCategory("integration")] + [ExpectedException(typeof(SshOperationTimeoutException))] + public void Test_Execute_Timeout() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + #region Example SshCommand CreateCommand Execute CommandTimeout + client.Connect(); + var cmd = client.CreateCommand("sleep 10s"); + cmd.CommandTimeout = TimeSpan.FromSeconds(5); + cmd.Execute(); + client.Disconnect(); + #endregion + } + } + + [TestMethod] + [TestCategory("integration")] + 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] + [TestCategory("integration")] + 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] + [TestCategory("integration")] + 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] + [TestCategory("integration")] + 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] + [TestCategory("integration")] + 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] + [TestCategory("integration")] + public void Test_Execute_Command_ExitStatus() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + #region Example SshCommand RunCommand ExitStatus + client.Connect(); + + var cmd = client.RunCommand("exit 128"); + + Console.WriteLine(cmd.ExitStatus); + + client.Disconnect(); + #endregion + + Assert.IsTrue(cmd.ExitStatus == 128); + } + } + + [TestMethod] + [TestCategory("integration")] + 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] + [TestCategory("integration")] + 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] + [TestCategory("integration")] + 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] + [TestCategory("integration")] + 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(); + } + } + + /// + /// Tests for Issue 563. + /// + [WorkItem(563), TestMethod] + [TestCategory("integration")] + 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] + [TestCategory("integration")] + 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] + [TestCategory("integration")] + 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))] + [TestCategory("integration")] + 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(); + } + } + + /// + ///A test for BeginExecute + /// + [TestMethod()] + [TestCategory("integration")] + public void BeginExecuteTest() + { + string expected = "123\n"; + string result; + + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + #region Example SshCommand CreateCommand BeginExecute IsCompleted EndExecute + + client.Connect(); + + var cmd = client.CreateCommand("sleep 15s;echo 123"); // Perform long running task + + var asynch = cmd.BeginExecute(); + + while (!asynch.IsCompleted) + { + // Waiting for command to complete... + Thread.Sleep(2000); + } + result = cmd.EndExecute(asynch); + client.Disconnect(); + + #endregion + + Assert.IsNotNull(asynch); + Assert.AreEqual(expected, result); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_Invalid_Command() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + #region Example SshCommand CreateCommand Error + + client.Connect(); + + var cmd = client.CreateCommand(";"); + cmd.Execute(); + if (!string.IsNullOrEmpty(cmd.Error)) + { + Console.WriteLine(cmd.Error); + } + + client.Disconnect(); + + #endregion + + Assert.Inconclusive(); + } + } + + + /// + ///A test for BeginExecute + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginExecuteTest1() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + string commandText1 = string.Empty; // TODO: Initialize to an appropriate value + AsyncCallback callback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginExecute(commandText1, callback, state); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CancelAsync + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CancelAsyncTest() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + target.CancelAsync(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + + /// + ///A test for Execute + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ExecuteTest() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + string expected = string.Empty; // TODO: Initialize to an appropriate value + string actual; + actual = target.Execute(); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Execute + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ExecuteTest1() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + string commandText1 = string.Empty; // TODO: Initialize to an appropriate value + string expected = string.Empty; // TODO: Initialize to an appropriate value + string actual; + actual = target.Execute(commandText1); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CommandTimeout + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CommandTimeoutTest() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + TimeSpan expected = new TimeSpan(); // TODO: Initialize to an appropriate value + TimeSpan actual; + target.CommandTimeout = expected; + actual = target.CommandTimeout; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Error + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ErrorTest() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + string actual; + actual = target.Error; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Result + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ResultTest() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + string actual; + actual = target.Result; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + 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); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs b/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs index e14d4938..8fbbeac7 100644 --- a/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs +++ b/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs @@ -1,72 +1,72 @@ -using System; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshCommand_EndExecute : TestBase - { - private Mock _sessionMock; - private Mock _channelSessionMock; - private string _commandText; - private Encoding _encoding; - private SshCommand _sshCommand; - - protected override void OnInit() - { - base.OnInit(); - - _sessionMock = new Mock(MockBehavior.Strict); - _commandText = new Random().Next().ToString(CultureInfo.InvariantCulture); - _encoding = Encoding.UTF8; - _channelSessionMock = new Mock(MockBehavior.Strict); - - _sshCommand = new SshCommand(_sessionMock.Object, _commandText, _encoding); - } - - [TestMethod] - public void EndExecute_ChannelClosed_ShouldDisposeChannelSession() - { - var seq = new MockSequence(); - - _sessionMock.InSequence(seq).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); - _channelSessionMock.InSequence(seq).Setup(p => p.Open()); - _channelSessionMock.InSequence(seq).Setup(p => p.SendExecRequest(_commandText)) - .Returns(true) - .Raises(c => c.Closed += null, new ChannelEventArgs(5)); - _channelSessionMock.InSequence(seq).Setup(p => p.IsOpen).Returns(false); - _channelSessionMock.InSequence(seq).Setup(p => p.Dispose()); - - var asyncResult = _sshCommand.BeginExecute(); - _sshCommand.EndExecute(asyncResult); - - _channelSessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void EndExecute_ChannelOpen_ShouldSendEofAndCloseAndDisposeChannelSession() - { - var seq = new MockSequence(); - - _sessionMock.InSequence(seq).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); - _channelSessionMock.InSequence(seq).Setup(p => p.Open()); - _channelSessionMock.InSequence(seq).Setup(p => p.SendExecRequest(_commandText)) - .Returns(true) - .Raises(c => c.Closed += null, new ChannelEventArgs(5)); - _channelSessionMock.InSequence(seq).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(seq).Setup(p => p.Close()); - _channelSessionMock.InSequence(seq).Setup(p => p.Dispose()); - - var asyncResult = _sshCommand.BeginExecute(); - _sshCommand.EndExecute(asyncResult); - - _channelSessionMock.Verify(p => p.Close(), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshCommand_EndExecute : TestBase + { + private Mock _sessionMock; + private Mock _channelSessionMock; + private string _commandText; + private Encoding _encoding; + private SshCommand _sshCommand; + + protected override void OnInit() + { + base.OnInit(); + + _sessionMock = new Mock(MockBehavior.Strict); + _commandText = new Random().Next().ToString(CultureInfo.InvariantCulture); + _encoding = Encoding.UTF8; + _channelSessionMock = new Mock(MockBehavior.Strict); + + _sshCommand = new SshCommand(_sessionMock.Object, _commandText, _encoding); + } + + [TestMethod] + public void EndExecute_ChannelClosed_ShouldDisposeChannelSession() + { + var seq = new MockSequence(); + + _sessionMock.InSequence(seq).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); + _channelSessionMock.InSequence(seq).Setup(p => p.Open()); + _channelSessionMock.InSequence(seq).Setup(p => p.SendExecRequest(_commandText)) + .Returns(true) + .Raises(c => c.Closed += null, new ChannelEventArgs(5)); + _channelSessionMock.InSequence(seq).Setup(p => p.IsOpen).Returns(false); + _channelSessionMock.InSequence(seq).Setup(p => p.Dispose()); + + var asyncResult = _sshCommand.BeginExecute(); + _sshCommand.EndExecute(asyncResult); + + _channelSessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void EndExecute_ChannelOpen_ShouldSendEofAndCloseAndDisposeChannelSession() + { + var seq = new MockSequence(); + + _sessionMock.InSequence(seq).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); + _channelSessionMock.InSequence(seq).Setup(p => p.Open()); + _channelSessionMock.InSequence(seq).Setup(p => p.SendExecRequest(_commandText)) + .Returns(true) + .Raises(c => c.Closed += null, new ChannelEventArgs(5)); + _channelSessionMock.InSequence(seq).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(seq).Setup(p => p.Close()); + _channelSessionMock.InSequence(seq).Setup(p => p.Dispose()); + + var asyncResult = _sshCommand.BeginExecute(); + _sshCommand.EndExecute(asyncResult); + + _channelSessionMock.Verify(p => p.Close(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSessionStub.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSessionStub.cs index 844f9a33..9fb77797 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSessionStub.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSessionStub.cs @@ -1,45 +1,45 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - internal class SubsystemSessionStub : SubsystemSession - { - private int _onChannelOpenInvocationCount; - - public SubsystemSessionStub(ISession session, string subsystemName, TimeSpan operationTimeout, Encoding encoding) : base(session, subsystemName, operationTimeout, encoding) - { - OnDataReceivedInvocations = new List(); - } - - public int OnChannelOpenInvocationCount - { - get { return _onChannelOpenInvocationCount; } - } - - public IList OnDataReceivedInvocations { get; private set; } - - public Exception OnChannelOpenException { get; set; } - - public Exception OnDataReceivedException { get; set; } - - protected override void OnChannelOpen() - { - Interlocked.Increment(ref _onChannelOpenInvocationCount); - - if (OnChannelOpenException != null) - throw OnChannelOpenException; - } - - protected override void OnDataReceived(byte[] data) - { - OnDataReceivedInvocations.Add(new ChannelDataEventArgs(0, data)); - - if (OnDataReceivedException != null) - throw OnDataReceivedException; - } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + internal class SubsystemSessionStub : SubsystemSession + { + private int _onChannelOpenInvocationCount; + + public SubsystemSessionStub(ISession session, string subsystemName, TimeSpan operationTimeout, Encoding encoding) : base(session, subsystemName, operationTimeout, encoding) + { + OnDataReceivedInvocations = new List(); + } + + public int OnChannelOpenInvocationCount + { + get { return _onChannelOpenInvocationCount; } + } + + public IList OnDataReceivedInvocations { get; private set; } + + public Exception OnChannelOpenException { get; set; } + + public Exception OnDataReceivedException { get; set; } + + protected override void OnChannelOpen() + { + Interlocked.Increment(ref _onChannelOpenInvocationCount); + + if (OnChannelOpenException != null) + throw OnChannelOpenException; + } + + protected override void OnDataReceived(byte[] data) + { + OnDataReceivedInvocations.Add(new ChannelDataEventArgs(0, data)); + + if (OnDataReceivedException != null) + throw OnDataReceivedException; + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs index d635829e..422b70d9 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs @@ -1,127 +1,127 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Connect_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private InvalidOperationException _actualException; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - try - { - _subsystemSession.Connect(); - Assert.Fail(); - } - catch (InvalidOperationException ex) - { - _actualException = ex; - } - - } - - [TestMethod] - public void ConnectShouldHaveThrownInvalidOperationException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual("The session is already connected.", _actualException.Message); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Connect_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private InvalidOperationException _actualException; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + try + { + _subsystemSession.Connect(); + Assert.Fail(); + } + catch (InvalidOperationException ex) + { + _actualException = ex; + } + + } + + [TestMethod] + public void ConnectShouldHaveThrownInvalidOperationException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual("The session is already connected.", _actualException.Message); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + + [TestMethod] + public void CloseOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs index e74c09a5..f5e9a5a1 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs @@ -1,128 +1,128 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Connect_Disconnected - { - private Mock _sessionMock; - private Mock _channelBeforeDisconnectMock; - private Mock _channelAfterDisconnectMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelBeforeDisconnectMock = new Mock(MockBehavior.Strict); - _channelAfterDisconnectMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelBeforeDisconnectMock.Object); - _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Open()); - _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Close()); - _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Dispose()); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelAfterDisconnectMock.Object); - _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.Open()); - _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Disconnect(); - } - - protected void Act() - { - _subsystemSession.Connect(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelAfterDisconnectMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelAfterDisconnectMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void CloseOnChannelBeforeDisconnectShouldBeInvokedOnce() - { - _channelBeforeDisconnectMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void CloseOnChannelAfterDisconnectShouldNeverBeInvoked() - { - _channelAfterDisconnectMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelBeforeDisconnectShouldBeInvokedOnce() - { - _channelBeforeDisconnectMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelAfterDisconnectShouldBeInvokedOnce() - { - _channelAfterDisconnectMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Connect_Disconnected + { + private Mock _sessionMock; + private Mock _channelBeforeDisconnectMock; + private Mock _channelAfterDisconnectMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelBeforeDisconnectMock = new Mock(MockBehavior.Strict); + _channelAfterDisconnectMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelBeforeDisconnectMock.Object); + _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Open()); + _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Close()); + _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Dispose()); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelAfterDisconnectMock.Object); + _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.Open()); + _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Disconnect(); + } + + protected void Act() + { + _subsystemSession.Connect(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelAfterDisconnectMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelAfterDisconnectMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void CloseOnChannelBeforeDisconnectShouldBeInvokedOnce() + { + _channelBeforeDisconnectMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void CloseOnChannelAfterDisconnectShouldNeverBeInvoked() + { + _channelAfterDisconnectMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelBeforeDisconnectShouldBeInvokedOnce() + { + _channelBeforeDisconnectMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelAfterDisconnectShouldBeInvokedOnce() + { + _channelAfterDisconnectMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disposed.cs index 44e23f4a..9dad3325 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disposed.cs @@ -1,97 +1,97 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Connect_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Dispose(); - } - - protected void Act() - { - try - { - _subsystemSession.Connect(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void ConnectShouldThrowObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual(string.Format("Cannot access a disposed object.{0}Object name: '{1}'.", Environment.NewLine, _actualException.ObjectName),_actualException.Message); - Assert.AreEqual(typeof(SubsystemSessionStub).FullName, _actualException.ObjectName); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Connect_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Dispose(); + } + + protected void Act() + { + try + { + _subsystemSession.Connect(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void ConnectShouldThrowObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual(string.Format("Cannot access a disposed object.{0}Object name: '{1}'.", Environment.NewLine, _actualException.ObjectName),_actualException.Message); + Assert.AreEqual(typeof(SubsystemSessionStub).FullName, _actualException.ObjectName); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_NeverConnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_NeverConnected.cs index 5994099e..d784c7ae 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_NeverConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_NeverConnected.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Renci.SshNet.Tests.Classes -{ - class SubsystemSession_Connect_NeverConnected - { - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Renci.SshNet.Tests.Classes +{ + class SubsystemSession_Connect_NeverConnected + { + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs index 8a2d9039..9a545f95 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Disconnect_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(_sequence).Setup(p => p.Close()); - _channelMock.InSequence(_sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _subsystemSession.Disconnect(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Disconnect_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(_sequence).Setup(p => p.Close()); + _channelMock.InSequence(_sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _subsystemSession.Disconnect(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs index 8a5295d5..734d8c5d 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Disconnect_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - _subsystemSession.Disconnect(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Disconnect_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + _subsystemSession.Disconnect(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_NeverConnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_NeverConnected.cs index 3aad8e66..ecdc46fc 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_NeverConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_NeverConnected.cs @@ -1,72 +1,72 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Disconnect_NeverConnected - { - private Mock _sessionMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - } - - protected void Act() - { - _subsystemSession.Disconnect(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Disconnect_NeverConnected + { + private Mock _sessionMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + } + + protected void Act() + { + _subsystemSession.Disconnect(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs index a2268d1d..3f03e5d4 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs @@ -1,95 +1,95 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Dispose_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _subsystemSession.Dispose(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Dispose_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _subsystemSession.Dispose(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs index d29a4429..6fc758e5 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Dispose_Disconnected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Disconnect(); - } - - protected void Act() - { - _subsystemSession.Dispose(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Dispose_Disconnected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Disconnect(); + } + + protected void Act() + { + _subsystemSession.Dispose(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs index 384e9929..1edec5bb 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Dispose_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - _subsystemSession.Dispose(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Dispose_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + _subsystemSession.Dispose(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_NeverConnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_NeverConnected.cs index 7d3726d0..63c22ea1 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_NeverConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_NeverConnected.cs @@ -1,73 +1,73 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Dispose_NeverConnected - { - private Mock _sessionMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - } - - protected void Act() - { - _subsystemSession.Dispose(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Dispose_NeverConnected + { + private Mock _sessionMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + } + + protected void Act() + { + _subsystemSession.Dispose(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs index 263a9037..5878f1a9 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs @@ -1,121 +1,121 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnChannelDataReceived_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ChannelDataEventArgs _channelDataEventArgs; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _channelDataEventArgs = new ChannelDataEventArgs( - (uint)random.Next(0, int.MaxValue), - new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void OnDataReceivedShouldBeInvokedOnce() - { - Assert.AreEqual(1, _subsystemSession.OnDataReceivedInvocations.Count); - - var received = _subsystemSession.OnDataReceivedInvocations[0]; - Assert.AreEqual(_channelDataEventArgs.Data, received.Data); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenSessionIsNotConnected() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnChannelDataReceived_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ChannelDataEventArgs _channelDataEventArgs; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _channelDataEventArgs = new ChannelDataEventArgs( + (uint)random.Next(0, int.MaxValue), + new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void OnDataReceivedShouldBeInvokedOnce() + { + Assert.AreEqual(1, _subsystemSession.OnDataReceivedInvocations.Count); + + var received = _subsystemSession.OnDataReceivedInvocations[0]; + Assert.AreEqual(_channelDataEventArgs.Data, received.Data); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenSessionIsNotConnected() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void CloseOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs index 55b393e9..66178326 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs @@ -1,94 +1,94 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnChannelDataReceived_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ChannelDataEventArgs _channelDataEventArgs; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _channelDataEventArgs = new ChannelDataEventArgs( - (uint)random.Next(0, int.MaxValue), - new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void OnDataReceivedShouldNeverBeInvoked() - { - Assert.AreEqual(0, _subsystemSession.OnDataReceivedInvocations.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnChannelDataReceived_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ChannelDataEventArgs _channelDataEventArgs; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _channelDataEventArgs = new ChannelDataEventArgs( + (uint)random.Next(0, int.MaxValue), + new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void OnDataReceivedShouldNeverBeInvoked() + { + Assert.AreEqual(0, _subsystemSession.OnDataReceivedInvocations.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs index 4f558eb9..b724e14d 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs @@ -1,92 +1,92 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ChannelDataEventArgs _channelDataEventArgs; - private Exception _onDataReceivedException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _channelDataEventArgs = new ChannelDataEventArgs( - (uint) random.Next(0, int.MaxValue), - new [] {(byte) random.Next(byte.MinValue, byte.MaxValue)}); - _onDataReceivedException = new SystemException(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.OnDataReceivedException = _onDataReceivedException; - _subsystemSession.Connect(); - } - - protected void Act() - { - _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHaveFiredOnce() - { - Assert.AreEqual(1, _errorOccurredRegister.Count); - Assert.AreSame(_onDataReceivedException, _errorOccurredRegister[0].Exception); - } - - [TestMethod] - public void OnDataReceivedShouldBeInvokedOnce() - { - Assert.AreEqual(1, _subsystemSession.OnDataReceivedInvocations.Count); - - var received = _subsystemSession.OnDataReceivedInvocations[0]; - Assert.AreEqual(_channelDataEventArgs.Data, received.Data); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ChannelDataEventArgs _channelDataEventArgs; + private Exception _onDataReceivedException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _channelDataEventArgs = new ChannelDataEventArgs( + (uint) random.Next(0, int.MaxValue), + new [] {(byte) random.Next(byte.MinValue, byte.MaxValue)}); + _onDataReceivedException = new SystemException(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.OnDataReceivedException = _onDataReceivedException; + _subsystemSession.Connect(); + } + + protected void Act() + { + _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHaveFiredOnce() + { + Assert.AreEqual(1, _errorOccurredRegister.Count); + Assert.AreSame(_onDataReceivedException, _errorOccurredRegister[0].Exception); + } + + [TestMethod] + public void OnDataReceivedShouldBeInvokedOnce() + { + Assert.AreEqual(1, _subsystemSession.OnDataReceivedInvocations.Count); + + var received = _subsystemSession.OnDataReceivedInvocations[0]; + Assert.AreEqual(_channelDataEventArgs.Data, received.Data); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs index f601758b..887330e5 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs @@ -1,111 +1,111 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnChannelException_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ExceptionEventArgs _channelExceptionEventArgs; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _channelExceptionEventArgs = new ExceptionEventArgs(new SystemException()); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _channelMock.Raise(s => s.Exception += null, _channelExceptionEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasFiredOnce() - { - Assert.AreEqual(1, _errorOccurredRegister.Count); - Assert.AreSame(_channelExceptionEventArgs.Exception, _errorOccurredRegister[0].Exception); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnChannelException_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ExceptionEventArgs _channelExceptionEventArgs; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _channelExceptionEventArgs = new ExceptionEventArgs(new SystemException()); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _channelMock.Raise(s => s.Exception += null, _channelExceptionEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasFiredOnce() + { + Assert.AreEqual(1, _errorOccurredRegister.Count); + Assert.AreSame(_channelExceptionEventArgs.Exception, _errorOccurredRegister[0].Exception); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void CloseOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs index 2bad6e46..6cb47486 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs @@ -1,89 +1,89 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnChannelException_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ExceptionEventArgs _channelExceptionEventArgs; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _channelExceptionEventArgs = new ExceptionEventArgs(new SystemException()); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - - _disconnectedRegister.Clear(); - _errorOccurredRegister.Clear(); - } - - protected void Act() - { - _channelMock.Raise(s => s.Exception += null, _channelExceptionEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnChannelException_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ExceptionEventArgs _channelExceptionEventArgs; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _channelExceptionEventArgs = new ExceptionEventArgs(new SystemException()); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + + _disconnectedRegister.Clear(); + _errorOccurredRegister.Clear(); + } + + protected void Act() + { + _channelMock.Raise(s => s.Exception += null, _channelExceptionEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs index 64a14670..318c64ae 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs @@ -1,108 +1,108 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnSessionDisconnected_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); - } - - [TestMethod] - public void DisconnectHasFiredOnce() - { - Assert.AreEqual(1, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnSessionDisconnected_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); + } + + [TestMethod] + public void DisconnectHasFiredOnce() + { + Assert.AreEqual(1, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void CloseOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs index 5c2c13ab..df4f0f59 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs @@ -1,84 +1,84 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnSessionDisconnected_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnSessionDisconnected_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs index 416fdf1e..aa2a135d 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs @@ -1,111 +1,111 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnSessionErrorOccurred_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ExceptionEventArgs _errorOccurredEventArgs; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _errorOccurredEventArgs = new ExceptionEventArgs(new SystemException()); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _sessionMock.Raise(s => s.ErrorOccured += null, _errorOccurredEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasFiredOnce() - { - Assert.AreEqual(1, _errorOccurredRegister.Count); - Assert.AreSame(_errorOccurredEventArgs.Exception, _errorOccurredRegister[0].Exception); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnSessionErrorOccurred_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ExceptionEventArgs _errorOccurredEventArgs; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _errorOccurredEventArgs = new ExceptionEventArgs(new SystemException()); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _sessionMock.Raise(s => s.ErrorOccured += null, _errorOccurredEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasFiredOnce() + { + Assert.AreEqual(1, _errorOccurredRegister.Count); + Assert.AreSame(_errorOccurredEventArgs.Exception, _errorOccurredRegister[0].Exception); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void CloseOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs index 9224fdd7..f59b0fcf 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs @@ -1,86 +1,86 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnSessionErrorOccurred_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ExceptionEventArgs _errorOccurredEventArgs; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _errorOccurredEventArgs = new ExceptionEventArgs(new SystemException()); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - _sessionMock.Raise(s => s.ErrorOccured += null, _errorOccurredEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnSessionErrorOccurred_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ExceptionEventArgs _errorOccurredEventArgs; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _errorOccurredEventArgs = new ExceptionEventArgs(new SystemException()); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + _sessionMock.Raise(s => s.ErrorOccured += null, _errorOccurredEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Connected.cs index a854da24..1d3e4090 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Connected.cs @@ -1,106 +1,106 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_SendData_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private byte[] _data; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _data = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - _channelMock.InSequence(_sequence).Setup(p => p.SendData(_data)); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _subsystemSession.SendData(_data); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void SendDataOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.SendData(_data), Times.Once); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_SendData_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private byte[] _data; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _data = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + _channelMock.InSequence(_sequence).Setup(p => p.SendData(_data)); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _subsystemSession.SendData(_data); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void SendDataOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.SendData(_data), Times.Once); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disconnected.cs index 19afb1ec..6d60a61b 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disconnected.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Renci.SshNet.Tests.Classes -{ - class SubsystemSession_SendData_Disconnected - { - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Renci.SshNet.Tests.Classes +{ + class SubsystemSession_SendData_Disconnected + { + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs index 8477efa9..f8e5ef0c 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs @@ -1,100 +1,100 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_SendData_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - try - { - _subsystemSession.SendData(new byte[0]); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SendDataShouldThrowObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual(string.Format("Cannot access a disposed object.{0}Object name: '{1}'.", Environment.NewLine, _actualException.ObjectName), _actualException.Message); - Assert.AreEqual(typeof(SubsystemSessionStub).FullName, _actualException.ObjectName); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_SendData_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + try + { + _subsystemSession.SendData(new byte[0]); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SendDataShouldThrowObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual(string.Format("Cannot access a disposed object.{0}Object name: '{1}'.", Environment.NewLine, _actualException.ObjectName), _actualException.Message); + Assert.AreEqual(typeof(SubsystemSessionStub).FullName, _actualException.ObjectName); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_NeverConnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_NeverConnected.cs index ff58cc4f..0de12487 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_NeverConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_NeverConnected.cs @@ -1,106 +1,106 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_SendData_NeverConnected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private InvalidOperationException _actualException; - private byte[] _data; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _data = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - } - - protected void Act() - { - try - { - _subsystemSession.SendData(_data); - } - catch (InvalidOperationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SendDataShouldHaveThrownInvalidOperationException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual("The session is not open.", _actualException.Message); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void SendDataOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.SendData(_data), Times.Never); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_SendData_NeverConnected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private InvalidOperationException _actualException; + private byte[] _data; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _data = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + } + + protected void Act() + { + try + { + _subsystemSession.SendData(_data); + } + catch (InvalidOperationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SendDataShouldHaveThrownInvalidOperationException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual("The session is not open.", _actualException.Message); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void SendDataOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.SendData(_data), Times.Never); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs b/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs index 6cd5c3a8..86b38c94 100644 --- a/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs +++ b/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs @@ -1,161 +1,161 @@ -using System; -using System.Net; -using System.Net.Sockets; -using System.Threading; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Common -{ - public class AsyncSocketListener : IDisposable - { - private readonly IPEndPoint _endPoint; - private readonly ManualResetEvent _acceptCallbackDone; - private Socket _listener; - private Thread _receiveThread; - private bool _started; - - public delegate void BytesReceivedHandler(byte[] bytesReceived, Socket socket); - public delegate void ConnectedHandler(Socket socket); - - public event BytesReceivedHandler BytesReceived; - public event ConnectedHandler Connected; - public event ConnectedHandler Disconnected; - - public AsyncSocketListener(IPEndPoint endPoint) - { - _endPoint = endPoint; - _acceptCallbackDone = new ManualResetEvent(false); - } - - public void Start() - { - _listener = new Socket(_endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); - _listener.Bind(_endPoint); - _listener.Listen(1); - - _started = true; - - _receiveThread = new Thread(StartListener); - _receiveThread.Start(_listener); - } - - public void Stop() - { - _started = false; - if (_listener != null) - { - _listener.Dispose(); - _listener = null; - } - if (_receiveThread != null) - { - _receiveThread.Join(); - _receiveThread = null; - } - } - - public void Dispose() - { - Stop(); - GC.SuppressFinalize(this); - } - - private void StartListener(object state) - { - var listener = (Socket)state; - while (_started) - { - _acceptCallbackDone.Reset(); - listener.BeginAccept(AcceptCallback, listener); - _acceptCallbackDone.WaitOne(); - } - } - - private void AcceptCallback(IAsyncResult ar) - { - // Signal the main thread to continue. - _acceptCallbackDone.Set(); - - // Get the socket that handles the client request. - var listener = (Socket)ar.AsyncState; - try - { - var handler = listener.EndAccept(ar); - SignalConnected(handler); - var state = new SocketStateObject(handler); - handler.BeginReceive(state.Buffer, 0, state.Buffer.Length, 0, ReadCallback, state); - } - catch (ObjectDisposedException) - { - // when the socket is closed, an ObjectDisposedException is thrown - // by Socket.EndAccept(IAsyncResult) - } - } - - private void ReadCallback(IAsyncResult ar) - { - // Retrieve the state object and the handler socket - // from the asynchronous state object. - var state = (SocketStateObject)ar.AsyncState; - var handler = state.Socket; - - // Read data from the client socket. - var bytesRead = handler.EndReceive(ar); - - if (bytesRead > 0) - { - var bytesReceived = new byte[bytesRead]; - Array.Copy(state.Buffer, bytesReceived, bytesRead); - SignalBytesReceived(bytesReceived, handler); - - // prepare to receive more bytes - try - { - handler.BeginReceive(state.Buffer, 0, state.Buffer.Length, 0, ReadCallback, state); - } - catch (ObjectDisposedException) - { - // when the socket is closed, an ObjectDisposedException is thrown - } - } - else - { - SignalDisconnected(handler); - handler.Shutdown(SocketShutdown.Send); - } - } - - private void SignalBytesReceived(byte[] bytesReceived, Socket client) - { - var subscribers = BytesReceived; - if (subscribers != null) - subscribers(bytesReceived, client); - } - - private void SignalConnected(Socket client) - { - var subscribers = Connected; - if (subscribers != null) - subscribers(client); - } - - private void SignalDisconnected(Socket client) - { - var subscribers = Disconnected; - if (subscribers != null) - subscribers(client); - } - - private class SocketStateObject - { - public Socket Socket { get; private set; } - - public readonly byte[] Buffer = new byte[1024]; - - public SocketStateObject(Socket handler) - { - Socket = handler; - } - } - } -} +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Common +{ + public class AsyncSocketListener : IDisposable + { + private readonly IPEndPoint _endPoint; + private readonly ManualResetEvent _acceptCallbackDone; + private Socket _listener; + private Thread _receiveThread; + private bool _started; + + public delegate void BytesReceivedHandler(byte[] bytesReceived, Socket socket); + public delegate void ConnectedHandler(Socket socket); + + public event BytesReceivedHandler BytesReceived; + public event ConnectedHandler Connected; + public event ConnectedHandler Disconnected; + + public AsyncSocketListener(IPEndPoint endPoint) + { + _endPoint = endPoint; + _acceptCallbackDone = new ManualResetEvent(false); + } + + public void Start() + { + _listener = new Socket(_endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); + _listener.Bind(_endPoint); + _listener.Listen(1); + + _started = true; + + _receiveThread = new Thread(StartListener); + _receiveThread.Start(_listener); + } + + public void Stop() + { + _started = false; + if (_listener != null) + { + _listener.Dispose(); + _listener = null; + } + if (_receiveThread != null) + { + _receiveThread.Join(); + _receiveThread = null; + } + } + + public void Dispose() + { + Stop(); + GC.SuppressFinalize(this); + } + + private void StartListener(object state) + { + var listener = (Socket)state; + while (_started) + { + _acceptCallbackDone.Reset(); + listener.BeginAccept(AcceptCallback, listener); + _acceptCallbackDone.WaitOne(); + } + } + + private void AcceptCallback(IAsyncResult ar) + { + // Signal the main thread to continue. + _acceptCallbackDone.Set(); + + // Get the socket that handles the client request. + var listener = (Socket)ar.AsyncState; + try + { + var handler = listener.EndAccept(ar); + SignalConnected(handler); + var state = new SocketStateObject(handler); + handler.BeginReceive(state.Buffer, 0, state.Buffer.Length, 0, ReadCallback, state); + } + catch (ObjectDisposedException) + { + // when the socket is closed, an ObjectDisposedException is thrown + // by Socket.EndAccept(IAsyncResult) + } + } + + private void ReadCallback(IAsyncResult ar) + { + // Retrieve the state object and the handler socket + // from the asynchronous state object. + var state = (SocketStateObject)ar.AsyncState; + var handler = state.Socket; + + // Read data from the client socket. + var bytesRead = handler.EndReceive(ar); + + if (bytesRead > 0) + { + var bytesReceived = new byte[bytesRead]; + Array.Copy(state.Buffer, bytesReceived, bytesRead); + SignalBytesReceived(bytesReceived, handler); + + // prepare to receive more bytes + try + { + handler.BeginReceive(state.Buffer, 0, state.Buffer.Length, 0, ReadCallback, state); + } + catch (ObjectDisposedException) + { + // when the socket is closed, an ObjectDisposedException is thrown + } + } + else + { + SignalDisconnected(handler); + handler.Shutdown(SocketShutdown.Send); + } + } + + private void SignalBytesReceived(byte[] bytesReceived, Socket client) + { + var subscribers = BytesReceived; + if (subscribers != null) + subscribers(bytesReceived, client); + } + + private void SignalConnected(Socket client) + { + var subscribers = Connected; + if (subscribers != null) + subscribers(client); + } + + private void SignalDisconnected(Socket client) + { + var subscribers = Disconnected; + if (subscribers != null) + subscribers(client); + } + + private class SocketStateObject + { + public Socket Socket { get; private set; } + + public readonly byte[] Buffer = new byte[1024]; + + public SocketStateObject(Socket handler) + { + Socket = handler; + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Common/HttpProxyStub.cs b/src/Renci.SshNet.Tests/Common/HttpProxyStub.cs index f0358d00..d7bdba50 100644 --- a/src/Renci.SshNet.Tests/Common/HttpProxyStub.cs +++ b/src/Renci.SshNet.Tests/Common/HttpProxyStub.cs @@ -1,169 +1,169 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using System.Text; - -namespace Renci.SshNet.Tests.Common -{ - public class HttpProxyStub : IDisposable - { - private readonly IPEndPoint _endPoint; - private AsyncSocketListener _listener; - private HttpRequestParser _httpRequestParser; - private readonly IList _responses; - - public HttpProxyStub(IPEndPoint endPoint) - { - _endPoint = endPoint; - _responses = new List(); - } - - public HttpRequest HttpRequest - { - get - { - if (_httpRequestParser == null) - throw new InvalidOperationException("The proxy is not started."); - return _httpRequestParser.HttpRequest; - } - } - - public IList Responses - { - get { return _responses; } - } - - public void Start() - { - _httpRequestParser = new HttpRequestParser(); - - _listener = new AsyncSocketListener(_endPoint); - _listener.BytesReceived += OnBytesReceived; - _listener.Start(); - } - - public void Stop() - { - if (_listener != null) - _listener.Stop(); - } - - public void Dispose() - { - Stop(); - GC.SuppressFinalize(this); - } - - private void OnBytesReceived(byte[] bytesReceived, Socket socket) - { - _httpRequestParser.ProcessData(bytesReceived); - - if (_httpRequestParser.CurrentState == HttpRequestParser.State.Content) - { - foreach (var response in Responses) - socket.Send(response); - socket.Shutdown(SocketShutdown.Send); - } - } - - private class HttpRequestParser - { - private readonly List _buffer; - private readonly HttpRequest _httpRequest; - - public enum State - { - RequestLine, - Headers, - Content - } - - public HttpRequestParser() - { - CurrentState = State.RequestLine; - _buffer = new List(); - _httpRequest = new HttpRequest(); - } - - public HttpRequest HttpRequest - { - get { return _httpRequest; } - } - - public State CurrentState { get; private set; } - - public void ProcessData(byte[] data) - { - var position = 0; - - while (position != data.Length) - { - if (CurrentState == State.RequestLine) - { - var requestLine = ReadLine(data, ref position); - if (requestLine != null) - { - _httpRequest.RequestLine = requestLine; - CurrentState = State.Headers; - } - } - - if (CurrentState == State.Headers) - { - var line = ReadLine(data, ref position); - if (line != null) - { - if (line.Length == 0) - { - CurrentState = State.Content; - } - else - { - _httpRequest.Headers.Add(line); - } - } - } - - if (CurrentState == State.Content) - { - if (position < data.Length) - { - var currentContent = _httpRequest.MessageBody; - var newBufferSize = currentContent.Length + (data.Length - position); - var copyBuffer = new byte[newBufferSize]; - Array.Copy(currentContent, copyBuffer, currentContent.Length); - Array.Copy(data, position, copyBuffer, currentContent.Length, data.Length - position); - _httpRequest.MessageBody = copyBuffer; - break; - } - } - } - } - - private string ReadLine(byte[] data, ref int position) - { - for (; position < data.Length; position++) - { - var b = data[position]; - if (b == '\n') - { - var buffer = _buffer.ToArray(); - var bytesInLine = buffer.Length; - // when the previous byte was a CR, then do not include it in line - if (buffer.Length > 0 && buffer[buffer.Length - 1] == '\r') - bytesInLine -= 1; - // clear the buffer - _buffer.Clear(); - // move position up one position as we've processed the current byte - position++; - return Encoding.ASCII.GetString(buffer, 0, bytesInLine); - } - _buffer.Add(b); - } - - return null; - } - } - } +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using System.Text; + +namespace Renci.SshNet.Tests.Common +{ + public class HttpProxyStub : IDisposable + { + private readonly IPEndPoint _endPoint; + private AsyncSocketListener _listener; + private HttpRequestParser _httpRequestParser; + private readonly IList _responses; + + public HttpProxyStub(IPEndPoint endPoint) + { + _endPoint = endPoint; + _responses = new List(); + } + + public HttpRequest HttpRequest + { + get + { + if (_httpRequestParser == null) + throw new InvalidOperationException("The proxy is not started."); + return _httpRequestParser.HttpRequest; + } + } + + public IList Responses + { + get { return _responses; } + } + + public void Start() + { + _httpRequestParser = new HttpRequestParser(); + + _listener = new AsyncSocketListener(_endPoint); + _listener.BytesReceived += OnBytesReceived; + _listener.Start(); + } + + public void Stop() + { + if (_listener != null) + _listener.Stop(); + } + + public void Dispose() + { + Stop(); + GC.SuppressFinalize(this); + } + + private void OnBytesReceived(byte[] bytesReceived, Socket socket) + { + _httpRequestParser.ProcessData(bytesReceived); + + if (_httpRequestParser.CurrentState == HttpRequestParser.State.Content) + { + foreach (var response in Responses) + socket.Send(response); + socket.Shutdown(SocketShutdown.Send); + } + } + + private class HttpRequestParser + { + private readonly List _buffer; + private readonly HttpRequest _httpRequest; + + public enum State + { + RequestLine, + Headers, + Content + } + + public HttpRequestParser() + { + CurrentState = State.RequestLine; + _buffer = new List(); + _httpRequest = new HttpRequest(); + } + + public HttpRequest HttpRequest + { + get { return _httpRequest; } + } + + public State CurrentState { get; private set; } + + public void ProcessData(byte[] data) + { + var position = 0; + + while (position != data.Length) + { + if (CurrentState == State.RequestLine) + { + var requestLine = ReadLine(data, ref position); + if (requestLine != null) + { + _httpRequest.RequestLine = requestLine; + CurrentState = State.Headers; + } + } + + if (CurrentState == State.Headers) + { + var line = ReadLine(data, ref position); + if (line != null) + { + if (line.Length == 0) + { + CurrentState = State.Content; + } + else + { + _httpRequest.Headers.Add(line); + } + } + } + + if (CurrentState == State.Content) + { + if (position < data.Length) + { + var currentContent = _httpRequest.MessageBody; + var newBufferSize = currentContent.Length + (data.Length - position); + var copyBuffer = new byte[newBufferSize]; + Array.Copy(currentContent, copyBuffer, currentContent.Length); + Array.Copy(data, position, copyBuffer, currentContent.Length, data.Length - position); + _httpRequest.MessageBody = copyBuffer; + break; + } + } + } + } + + private string ReadLine(byte[] data, ref int position) + { + for (; position < data.Length; position++) + { + var b = data[position]; + if (b == '\n') + { + var buffer = _buffer.ToArray(); + var bytesInLine = buffer.Length; + // when the previous byte was a CR, then do not include it in line + if (buffer.Length > 0 && buffer[buffer.Length - 1] == '\r') + bytesInLine -= 1; + // clear the buffer + _buffer.Clear(); + // move position up one position as we've processed the current byte + position++; + return Encoding.ASCII.GetString(buffer, 0, bytesInLine); + } + _buffer.Add(b); + } + + return null; + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Common/HttpRequest.cs b/src/Renci.SshNet.Tests/Common/HttpRequest.cs index 87797d20..56185fdd 100644 --- a/src/Renci.SshNet.Tests/Common/HttpRequest.cs +++ b/src/Renci.SshNet.Tests/Common/HttpRequest.cs @@ -1,17 +1,17 @@ -using System.Collections.Generic; - -namespace Renci.SshNet.Tests.Common -{ - public class HttpRequest - { - public HttpRequest() - { - Headers = new List(); - MessageBody = new byte[0]; - } - - public string RequestLine { get; set; } - public IList Headers { get; set; } - public byte[] MessageBody { get; set; } - } -} +using System.Collections.Generic; + +namespace Renci.SshNet.Tests.Common +{ + public class HttpRequest + { + public HttpRequest() + { + Headers = new List(); + MessageBody = new byte[0]; + } + + public string RequestLine { get; set; } + public IList Headers { get; set; } + public byte[] MessageBody { get; set; } + } +} diff --git a/src/Renci.SshNet.Tests/Common/TestBase.cs b/src/Renci.SshNet.Tests/Common/TestBase.cs index cda7e002..345fd1bd 100644 --- a/src/Renci.SshNet.Tests/Common/TestBase.cs +++ b/src/Renci.SshNet.Tests/Common/TestBase.cs @@ -1,56 +1,56 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.IO; -using System.Reflection; - -namespace Renci.SshNet.Tests.Common -{ - [TestClass] - public abstract class TestBase - { - private static Assembly _executingAssembly = Assembly.GetExecutingAssembly(); - [TestInitialize()] - public void Init() - { - this.OnInit(); - } - - [TestCleanup()] - public void Cleanup() - { - this.OnCleanup(); - } - - protected virtual void OnInit() - { - } - - protected virtual void OnCleanup() - { - } - - /// - /// Creates the test file. - /// - /// Name of the file. - /// Size in megabytes. - protected void CreateTestFile(string fileName, int size) - { - using (var testFile = File.Create(fileName)) - { - var random = new Random(); - for (int i = 0; i < 1024 * size; i++) - { - var buffer = new byte[1024]; - random.NextBytes(buffer); - testFile.Write(buffer, 0, buffer.Length); - } - } - } - - protected Stream GetData(string name) - { - return _executingAssembly.GetManifestResourceStream(string.Format("Renci.SshNet.Tests.Data.{0}", name)); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.IO; +using System.Reflection; + +namespace Renci.SshNet.Tests.Common +{ + [TestClass] + public abstract class TestBase + { + private static Assembly _executingAssembly = Assembly.GetExecutingAssembly(); + [TestInitialize()] + public void Init() + { + this.OnInit(); + } + + [TestCleanup()] + public void Cleanup() + { + this.OnCleanup(); + } + + protected virtual void OnInit() + { + } + + protected virtual void OnCleanup() + { + } + + /// + /// Creates the test file. + /// + /// Name of the file. + /// Size in megabytes. + protected void CreateTestFile(string fileName, int size) + { + using (var testFile = File.Create(fileName)) + { + var random = new Random(); + for (int i = 0; i < 1024 * size; i++) + { + var buffer = new byte[1024]; + random.NextBytes(buffer); + testFile.Write(buffer, 0, buffer.Length); + } + } + } + + protected Stream GetData(string name) + { + return _executingAssembly.GetManifestResourceStream(string.Format("Renci.SshNet.Tests.Data.{0}", name)); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.128.CBC.12345.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.128.CBC.12345.txt index 1c8303f3..cc017a90 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.128.CBC.12345.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.128.CBC.12345.txt @@ -1,30 +1,30 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: AES-128-CBC,AD7A2024C208E41F91C191B89AB9515A - -TFSgpmvpdkk1noN8C3hhiVMIW6aQ9sLhTbw/vrOh6Atp3/DgmgNOjXrClWXrZi6C -dyEV/ohLL12FCSkhEz5yl88IeSG0SA970zPoBrCi0OAyc40kQe/oQOHPg948BYcp -MIhJRYdbc6yZJC7umyteIaDg4BT2u9C1512JI/7CV1JzzfdYxFNpRVqW06wOdz/2 -IdtbusQsHRU0faGP6F3VMRLuCkS/l96K7orXQofpLw78f8siyNFqOvTrZNsIjErl -OXnY3k77SEtcfJ+Gji7BZBNHmDPG4mFacFGotypYb422C3ENCIrjFa5JsU5IGVe+ -3YDaZySq7JkgsFF3owwQvJycO0IDO8WgyYhDTFkWLL5bLU+R1bqvWxVq0WtLJO0n -B4katSG+kxhFFE85k2hmEOQjsWNvQD7EbPwQBXQUr80/sPFhfzm228z8aeLa/9nb -WCNg9ilEx7QAjc7i3RfqcJ9O4svZy5JUV5K1oe5CsTmTGfQiG93R8RNA/coRcv36 -iw3jldW+otB22hHxktrQIhPz3cRocVvr3xSe+2RsWrOOuCaJrrduPnlFTUHt3gRD -yBWoA6AD+Bt+0yW7TFpbR77rz2svcgoJ64wrA2sG0OtUlMzG52IX69pWA6tRKbdJ -rGj/j/9fIQi83bAUXpWG/gA4hL18+QiNAfyk3fmMtOvp58fyoWYguLAc794ar0jJ -HAseTc1RzBzRp2Ic/LwIQyxOwNBM0KXuVoyJjkFg6qNudVrIv0PSIPuu84Ro4dbn -HN+a7O/SQXk3NOSN4N/XSbBpu8tZVq94w3mPoNXcsnObeN/Br4cr0pGlm8sJJNbh -HZSAz+MxqXmpwPr7UUd3jmtnYmOgE89H7k2nayj06J2a7EgbzaXCeeXUg+IJN1xi -o1TMU4uQgX0XgChnRZ1Uo8ksAqWAEvgFypexFulNxHPCnLrjWOIA8nyt9Ue8T/SO -eEVsSLNhUuQsn+TiKgP4f4JaXMl2tchzSth2Gv2QEReMb1ftzIH41VZndhJlxmAE -o1AButj+5+d6oBuJo8rueRUz6invlv9FUXQWaDEjpFXACmXC+KtZ5rBa8oP9yak5 -Hh1GxVYHCs0WGyWdIRgW44oVWIfEBGLer2G9krhnZNF4lbyG8SuGhju+LYRe726Y -/Un1r/6+nykMNsAgR0vjnYkwx1Qd2mm8L8eLkz/Q7BsZLpChLqHv5HnXNuXqTsFB -orWBELQQsvLU69j70h3KK549gGPO4KBX8VrMaj0tIss7PYQub7lbyhNFXlfHy+xN -4EZntnj3gf0eqxsqduq6rP18vhaE3onIJ2I6twR+ivTulacNHxSH0/ieh+QCB9Bw -3gggWZ9Trf7QvyGEqzewfYMZ0RjagascnFFVjyTtPLn6jfaIoxSxMy7kcyIYHxPu -3qgLtO+AW6bY4VuT3cJroNrdrnGTXiGzim5TWDw2EcuLUpA8p3G+0RnSgM/EyjVQ -dZo8roiKvKSpdVS6cWsScyAvecq+fXTGzd95DDj15/feWP/4vk4WjTeSEr95k2cq -TGwZ2mF2ZKxS3eXVHOKysreLIQQOeMi+rlHAMAfzu5PTQhaYhhFZ2oPBmPsYYrJD +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: AES-128-CBC,AD7A2024C208E41F91C191B89AB9515A + +TFSgpmvpdkk1noN8C3hhiVMIW6aQ9sLhTbw/vrOh6Atp3/DgmgNOjXrClWXrZi6C +dyEV/ohLL12FCSkhEz5yl88IeSG0SA970zPoBrCi0OAyc40kQe/oQOHPg948BYcp +MIhJRYdbc6yZJC7umyteIaDg4BT2u9C1512JI/7CV1JzzfdYxFNpRVqW06wOdz/2 +IdtbusQsHRU0faGP6F3VMRLuCkS/l96K7orXQofpLw78f8siyNFqOvTrZNsIjErl +OXnY3k77SEtcfJ+Gji7BZBNHmDPG4mFacFGotypYb422C3ENCIrjFa5JsU5IGVe+ +3YDaZySq7JkgsFF3owwQvJycO0IDO8WgyYhDTFkWLL5bLU+R1bqvWxVq0WtLJO0n +B4katSG+kxhFFE85k2hmEOQjsWNvQD7EbPwQBXQUr80/sPFhfzm228z8aeLa/9nb +WCNg9ilEx7QAjc7i3RfqcJ9O4svZy5JUV5K1oe5CsTmTGfQiG93R8RNA/coRcv36 +iw3jldW+otB22hHxktrQIhPz3cRocVvr3xSe+2RsWrOOuCaJrrduPnlFTUHt3gRD +yBWoA6AD+Bt+0yW7TFpbR77rz2svcgoJ64wrA2sG0OtUlMzG52IX69pWA6tRKbdJ +rGj/j/9fIQi83bAUXpWG/gA4hL18+QiNAfyk3fmMtOvp58fyoWYguLAc794ar0jJ +HAseTc1RzBzRp2Ic/LwIQyxOwNBM0KXuVoyJjkFg6qNudVrIv0PSIPuu84Ro4dbn +HN+a7O/SQXk3NOSN4N/XSbBpu8tZVq94w3mPoNXcsnObeN/Br4cr0pGlm8sJJNbh +HZSAz+MxqXmpwPr7UUd3jmtnYmOgE89H7k2nayj06J2a7EgbzaXCeeXUg+IJN1xi +o1TMU4uQgX0XgChnRZ1Uo8ksAqWAEvgFypexFulNxHPCnLrjWOIA8nyt9Ue8T/SO +eEVsSLNhUuQsn+TiKgP4f4JaXMl2tchzSth2Gv2QEReMb1ftzIH41VZndhJlxmAE +o1AButj+5+d6oBuJo8rueRUz6invlv9FUXQWaDEjpFXACmXC+KtZ5rBa8oP9yak5 +Hh1GxVYHCs0WGyWdIRgW44oVWIfEBGLer2G9krhnZNF4lbyG8SuGhju+LYRe726Y +/Un1r/6+nykMNsAgR0vjnYkwx1Qd2mm8L8eLkz/Q7BsZLpChLqHv5HnXNuXqTsFB +orWBELQQsvLU69j70h3KK549gGPO4KBX8VrMaj0tIss7PYQub7lbyhNFXlfHy+xN +4EZntnj3gf0eqxsqduq6rP18vhaE3onIJ2I6twR+ivTulacNHxSH0/ieh+QCB9Bw +3gggWZ9Trf7QvyGEqzewfYMZ0RjagascnFFVjyTtPLn6jfaIoxSxMy7kcyIYHxPu +3qgLtO+AW6bY4VuT3cJroNrdrnGTXiGzim5TWDw2EcuLUpA8p3G+0RnSgM/EyjVQ +dZo8roiKvKSpdVS6cWsScyAvecq+fXTGzd95DDj15/feWP/4vk4WjTeSEr95k2cq +TGwZ2mF2ZKxS3eXVHOKysreLIQQOeMi+rlHAMAfzu5PTQhaYhhFZ2oPBmPsYYrJD -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.192.CBC.12345.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.192.CBC.12345.txt index ef6ddde8..51e90210 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.192.CBC.12345.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.192.CBC.12345.txt @@ -1,30 +1,30 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: AES-192-CBC,0E34605476FC4C57886CE6350CD6F61E - -yOzUZ81fSG2jBfhe7h/f2Uy7K86+VZFXVG3Y3qdQe6HD6kvQgQJLN+g8OVHan7vA -CYnKImqS5fiTIwvsMxzVWtCeY2kJ9BMNeNIoLXebD5RV93lKPBgl0IldrkfJrg0w -VNPkCHLFHWIOUA/bxYiXEeLRHuvndSkYH/JCzESiquf51chU4CIEmrbuvtvLXKta -YPO9eCw0PP1QKO/fJVrUHfp6Bsvai/J0+PG19XzkKCMsewG0MkAqpkzQrAjaCJyj -IwiqxxV72FIQDITgIQf5sY2yPzya/TjnBpu4m9D7TzQhCw9J2EDx61qvvKt3BDyq -DahaY6/T/wgcYvdoJ3RzOiWmSLvXNc1PNVY9OfQXG2EtJa/xi2BHyeHgo/Kib7Wr -nfaKgM7V998bLjiUnLK9CoD2WG3oSIrkAieNYbaD+RvU/mR/TNp5xMLMVJYduZo+ -EeyooM1a29WjOU8LPZ/AwNS4/DHnzEG1UBsUbKtyzQHiKU3JoW+5BkZ2tAs+VEWo -b5Jx9XCKfL9JepP0Ti2adAlPYU9jH6YzTpZZfu+sd2+X/N8obYssUP6bFSB0KWL0 -s/nx7DKzbXo4P+Lm04FpmeqmP3h4lhsInoozr0tP3JJKTb99kGV480eVdqDuV+Af -WJ4HLKlWxu8aHNnYb8/ATWEvh0Li0Qmx/ok8Ixa4XmHv2W0hjk7yhNewLpIwQ35X -qJgQph96gGzMGZQ3r/TjNd7YiAfPishOC/TnitIZzC/Es+zZ7QsGgBP4j1hPLAjs -OTrOvwkLuGUOoI9jJwm6343ZeGBFuWXJu0CSk4OF1EUMNziMUz9Rfw6xHSAnzff/ -YuQwDx+EtZLyyxFsfdhLjwcR38R6WoFqeDPpb3i6B5dYhHG6w60Yq5X1J4EnJgLL -4zYqVLoC6rvUuslFX2EFGrTTZP/7qRi5H3ZhNzMf/KDVbTyhzzHx27LR/8vbScA0 -IFp5NhmbmBbH7PmEF3UoVwSn/u+5iF8dmuhuOqNidImAULLCf5qCSbJNvagk9sSf -c6SdbX+EOkF6nTZYfSA0lT2u7rSfFw7khn6f+/ySRlQra7v3MBeeIuqrHEamlc73 -4hPKnl8eGcT3XvrpMnuiYADjJ4qOYzwx3YiKGqvdGzqd+ML6f2Tk31N7E53UDvSR -96gYz7IiBEkbaQSV1iZ95iiv/0m2J8B7VR5FfwvLltrmD10Alq97Gpj7HUH/Yy+8 -Wu4ADp6wdSWXMki2+QUxucIqWJ4nViE6K4FJy3SbPwtJWxiLkLQibGxdZl0jHDOl -F/FuWxjizKtOwn9rzQ+viVvYaQW1QTv5kS0d0L7FV2J8lQbsr8T86jUAJRASt5Cf -/+Z628xFSwDZjITOjhHT2GJqho/eW4h/naWgMRoThFI2l+o8Ko+kBFZ+fvmnY+MU -VcueeowDqsPawOj2YaaifvOzzsoP4C6Uu7K8UwAXE7gnKRWjIB4EJZLEaTXBpIUM -BcBcYCqd1X+JFQxp7fID+EGxlMfTjdZM4c51y67EHzMquZSiLEGBQgE8KiJclsIN -/PjY3hlwcZpyTEnqTYLnhL5SG/1fskUWPLaJ66u+aGoo9bcfOq9AE0yzPsl6MCes +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: AES-192-CBC,0E34605476FC4C57886CE6350CD6F61E + +yOzUZ81fSG2jBfhe7h/f2Uy7K86+VZFXVG3Y3qdQe6HD6kvQgQJLN+g8OVHan7vA +CYnKImqS5fiTIwvsMxzVWtCeY2kJ9BMNeNIoLXebD5RV93lKPBgl0IldrkfJrg0w +VNPkCHLFHWIOUA/bxYiXEeLRHuvndSkYH/JCzESiquf51chU4CIEmrbuvtvLXKta +YPO9eCw0PP1QKO/fJVrUHfp6Bsvai/J0+PG19XzkKCMsewG0MkAqpkzQrAjaCJyj +IwiqxxV72FIQDITgIQf5sY2yPzya/TjnBpu4m9D7TzQhCw9J2EDx61qvvKt3BDyq +DahaY6/T/wgcYvdoJ3RzOiWmSLvXNc1PNVY9OfQXG2EtJa/xi2BHyeHgo/Kib7Wr +nfaKgM7V998bLjiUnLK9CoD2WG3oSIrkAieNYbaD+RvU/mR/TNp5xMLMVJYduZo+ +EeyooM1a29WjOU8LPZ/AwNS4/DHnzEG1UBsUbKtyzQHiKU3JoW+5BkZ2tAs+VEWo +b5Jx9XCKfL9JepP0Ti2adAlPYU9jH6YzTpZZfu+sd2+X/N8obYssUP6bFSB0KWL0 +s/nx7DKzbXo4P+Lm04FpmeqmP3h4lhsInoozr0tP3JJKTb99kGV480eVdqDuV+Af +WJ4HLKlWxu8aHNnYb8/ATWEvh0Li0Qmx/ok8Ixa4XmHv2W0hjk7yhNewLpIwQ35X +qJgQph96gGzMGZQ3r/TjNd7YiAfPishOC/TnitIZzC/Es+zZ7QsGgBP4j1hPLAjs +OTrOvwkLuGUOoI9jJwm6343ZeGBFuWXJu0CSk4OF1EUMNziMUz9Rfw6xHSAnzff/ +YuQwDx+EtZLyyxFsfdhLjwcR38R6WoFqeDPpb3i6B5dYhHG6w60Yq5X1J4EnJgLL +4zYqVLoC6rvUuslFX2EFGrTTZP/7qRi5H3ZhNzMf/KDVbTyhzzHx27LR/8vbScA0 +IFp5NhmbmBbH7PmEF3UoVwSn/u+5iF8dmuhuOqNidImAULLCf5qCSbJNvagk9sSf +c6SdbX+EOkF6nTZYfSA0lT2u7rSfFw7khn6f+/ySRlQra7v3MBeeIuqrHEamlc73 +4hPKnl8eGcT3XvrpMnuiYADjJ4qOYzwx3YiKGqvdGzqd+ML6f2Tk31N7E53UDvSR +96gYz7IiBEkbaQSV1iZ95iiv/0m2J8B7VR5FfwvLltrmD10Alq97Gpj7HUH/Yy+8 +Wu4ADp6wdSWXMki2+QUxucIqWJ4nViE6K4FJy3SbPwtJWxiLkLQibGxdZl0jHDOl +F/FuWxjizKtOwn9rzQ+viVvYaQW1QTv5kS0d0L7FV2J8lQbsr8T86jUAJRASt5Cf +/+Z628xFSwDZjITOjhHT2GJqho/eW4h/naWgMRoThFI2l+o8Ko+kBFZ+fvmnY+MU +VcueeowDqsPawOj2YaaifvOzzsoP4C6Uu7K8UwAXE7gnKRWjIB4EJZLEaTXBpIUM +BcBcYCqd1X+JFQxp7fID+EGxlMfTjdZM4c51y67EHzMquZSiLEGBQgE8KiJclsIN +/PjY3hlwcZpyTEnqTYLnhL5SG/1fskUWPLaJ66u+aGoo9bcfOq9AE0yzPsl6MCes -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.256.CBC.12345.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.256.CBC.12345.txt index 98243dc9..cb31e913 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.256.CBC.12345.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.256.CBC.12345.txt @@ -1,30 +1,30 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: AES-256-CBC,063DE67AE11456C89BCE9D4A21BE3DFB - -6mS1GhCjAg5mEwMFcKRJwg1uxCeY3ekJNCQewIN9NSI5A8prBOQ+JSyWAsn6c3Gw -OeRyur+5dxMFdt5Hz1CBi9EePvhVyMry7U5U86BWB0HgtDAD02b324sfc6Wk+kj5 -PZvuKyXDiqdwy0rsbBUT+bLtXjCI4Ws1k/KbbF0OqGhFJJvErNU5x8zMD9mqp92R -D8ZZ/F8Sks3V/JeUisAF86sgMfVCELJobn5Zq/IaUyzQwC6IEL+Sy5fSBB5NHiex -NDIJg2RW79uLbufCpuoMPS/GKydf4dq0L5MwvKeqtUgf9Wddc+ZAE4+q1Xz/T8iN -3IMqsQfVbYjVK7uTaVGKH+Ew77Qryj01Vg+zyzdf4UwOV3XXQKLVCjNxpMCVtoq7 -S45M3Ad7598vb7ooa/BFCIcEM8TkuzPnuttLqjzXEzUcA5kqm3kV14IKtlexBfNT -tarbidlZcOinvJaoIT3baP4rVnEWDKcxpc+UzNU5RRty6l0zpRmw/9RQ5+FKreh8 -eXDHD8TT8ArdaREFM8J2OGpkmIK5sLhhYi9gnTopmKIHn8OAXusmQosEOzS6kGxk -aFtZezXSCBGgXp5RsrBGGx3oXWHGuWbEFXAq+M7PKXMQe5rLRv6sQdfTFSB5hgNK -82P8UzV1wWtAX4JYAhRh2zA8agY2arbNvbjRyjSbp9HNVBgSbVQ60JInesOqLxEg -XURuCYp4F8AeHzyO805MTNpcX7PZT2kOxp9sKKABJ9BJ0RoSWa0LJqXzGCHvrExE -g7XY/ZfDFZlPLbQnrOgVlYh7pzyfyKB74/oXHkonAisRfsgnQ87yT2DmcHNP6Cek -eae2nrpx2yn9Bf8rYdpmJgNxduO8IZvpn84xEyPqK+FbQsdOefBvsg5TgfzETkh/ -SJjzbqCTDa3XHEUCInixo/wT7FxT8KR9vk43FGPNVRUvPB2GNxe9ZwLYIir64hcQ -CpdA3ipVx4/jVzWQH8KXG9UP9TDAKXEvbndLnr2taPnUdAnznwHN2EkfzS/PrFG4 -/j3l1+VY2AyRybbCTI2iuwJPnKdxOR5oWW6I2Ksfq93Oy+NQz/zasjyNpCZBZWds -5gBmwiNk2Xzq7ikEVtVk3osOQRw/u9GbretfaT9jtClALL3DFbOzL4WxA+0NJqpd -NB2MohOJa1BJjdfh6x6EVhugH85Y9uYyz/MQj7piljAJY96190n3Q86b/7phfwuD -A/ixS42nqpyOPO+EjiWFerFVTJ3iBj7GXXOZGwCrZfpTbqE7OdTDnE3Vr4MO/Etq -kSDmJ/+4SFFh80YwYVERDNFdDxCYxx5AnxaBFwbqjzatTV/btgGVabIf6zm2L6aY -BJ5wnBZnRnsRaIMehDQmTjioMcyHBSMqId+LYQp+KFpBXqXQTEjJPnq+t4o2FF/N -8yoKR8BX6HXSO5qUndI8emwec1JeveiRai6SDnEz1EFfetYXImR290mlqt0aRjQk -t/HXRv+fmDQk5hJbCPICydcVSRyrbzxKkppVceEf9NwkBT1MBsOZIFJ3s3A9I72n -XPIab5czlgSLYA/U9nEg2XU21hKD2kRH1OF0WSlpNhN2SJFViVqlC3v36MgHoWNh +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: AES-256-CBC,063DE67AE11456C89BCE9D4A21BE3DFB + +6mS1GhCjAg5mEwMFcKRJwg1uxCeY3ekJNCQewIN9NSI5A8prBOQ+JSyWAsn6c3Gw +OeRyur+5dxMFdt5Hz1CBi9EePvhVyMry7U5U86BWB0HgtDAD02b324sfc6Wk+kj5 +PZvuKyXDiqdwy0rsbBUT+bLtXjCI4Ws1k/KbbF0OqGhFJJvErNU5x8zMD9mqp92R +D8ZZ/F8Sks3V/JeUisAF86sgMfVCELJobn5Zq/IaUyzQwC6IEL+Sy5fSBB5NHiex +NDIJg2RW79uLbufCpuoMPS/GKydf4dq0L5MwvKeqtUgf9Wddc+ZAE4+q1Xz/T8iN +3IMqsQfVbYjVK7uTaVGKH+Ew77Qryj01Vg+zyzdf4UwOV3XXQKLVCjNxpMCVtoq7 +S45M3Ad7598vb7ooa/BFCIcEM8TkuzPnuttLqjzXEzUcA5kqm3kV14IKtlexBfNT +tarbidlZcOinvJaoIT3baP4rVnEWDKcxpc+UzNU5RRty6l0zpRmw/9RQ5+FKreh8 +eXDHD8TT8ArdaREFM8J2OGpkmIK5sLhhYi9gnTopmKIHn8OAXusmQosEOzS6kGxk +aFtZezXSCBGgXp5RsrBGGx3oXWHGuWbEFXAq+M7PKXMQe5rLRv6sQdfTFSB5hgNK +82P8UzV1wWtAX4JYAhRh2zA8agY2arbNvbjRyjSbp9HNVBgSbVQ60JInesOqLxEg +XURuCYp4F8AeHzyO805MTNpcX7PZT2kOxp9sKKABJ9BJ0RoSWa0LJqXzGCHvrExE +g7XY/ZfDFZlPLbQnrOgVlYh7pzyfyKB74/oXHkonAisRfsgnQ87yT2DmcHNP6Cek +eae2nrpx2yn9Bf8rYdpmJgNxduO8IZvpn84xEyPqK+FbQsdOefBvsg5TgfzETkh/ +SJjzbqCTDa3XHEUCInixo/wT7FxT8KR9vk43FGPNVRUvPB2GNxe9ZwLYIir64hcQ +CpdA3ipVx4/jVzWQH8KXG9UP9TDAKXEvbndLnr2taPnUdAnznwHN2EkfzS/PrFG4 +/j3l1+VY2AyRybbCTI2iuwJPnKdxOR5oWW6I2Ksfq93Oy+NQz/zasjyNpCZBZWds +5gBmwiNk2Xzq7ikEVtVk3osOQRw/u9GbretfaT9jtClALL3DFbOzL4WxA+0NJqpd +NB2MohOJa1BJjdfh6x6EVhugH85Y9uYyz/MQj7piljAJY96190n3Q86b/7phfwuD +A/ixS42nqpyOPO+EjiWFerFVTJ3iBj7GXXOZGwCrZfpTbqE7OdTDnE3Vr4MO/Etq +kSDmJ/+4SFFh80YwYVERDNFdDxCYxx5AnxaBFwbqjzatTV/btgGVabIf6zm2L6aY +BJ5wnBZnRnsRaIMehDQmTjioMcyHBSMqId+LYQp+KFpBXqXQTEjJPnq+t4o2FF/N +8yoKR8BX6HXSO5qUndI8emwec1JeveiRai6SDnEz1EFfetYXImR290mlqt0aRjQk +t/HXRv+fmDQk5hJbCPICydcVSRyrbzxKkppVceEf9NwkBT1MBsOZIFJ3s3A9I72n +XPIab5czlgSLYA/U9nEg2XU21hKD2kRH1OF0WSlpNhN2SJFViVqlC3v36MgHoWNh -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.CBC.12345.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.CBC.12345.txt index 5ae4cc17..32734a07 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.CBC.12345.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.CBC.12345.txt @@ -1,30 +1,30 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-CBC,BD35E157CDD07CAD - -VU1aEcNJaFe1bhZ+sEzv70KQB94Pu2H+VoemLXtyIVzEQJV9+cymnRYjkgzykJ5d -s4J0vJMdiGtMH5lYRYEPQRNroOzJMwLngNyPiV8yLZARMR7tINdQyM7JBUFL4GfA -+0Jl/e7cZaCRJKAKQZu5L5DGuP6488tG7bKY9Rhzys21hPF+ck/8Gzfp1vC91AxF -zuy71e8ihEERF55DB5Ai1/lvEN15GUvkx14s0Oonfarxueu3dp/ch4P4PhzkY9Ci -7/ONnlpfrBR7bLajcXUq2XAO21ftDZejk5m6y0Z0bl0L+HpbJk2zFJGtwM+B+T3h -WkZqEK+RyTER67KUeecoKl297sh2YQtbxbdoTseUxktCb2/BSkpOHV5cgS64c3Ys -zGbk4dUmKv4HFs4VJ7HD3Ix6qAhMJyGQXOqze1c7ky9NoU2e05HdfgI/9We0EZQJ -PbequZZ4GOKnj4f70EbIEFyJldsJgijNCLKCafRYtygIs8zZkj/oE/S92iYZtesn -q2wxBAat3ZYn6tpkXx+4u9bSZ+U9OfYijxBv2x+BnAf0nQ1zNqmTOolEAIEMLS60 -5WFWKVaOeqAP0Q185TEqpUFqcaTCycV2w1hN/XXuAiYqXaSYwg4ZtCmWmxbn20QH -SMvRuY6MZSNNncgoLbm+ySq1yP1Z46kRsU1ufAyN3Jue+6DVd8wFrEOXfLJnCbFk -Eykpd7vxzczHXWgrlakl2sPFy4ltcALc8ZhsmGO+goWNqwp4QPX4LMHeUsA9n86Q -ABNV+KkCyIzp6FsFVqeHCxD8EoE/MuiuMHy/n0oEGj7zp9Moq5DHrgQDmdKnhrAG -B2HqYlCH54LDKd3wlgT76/HJ8yviFZECY2q6Z1BnMzm2ikKLCyPBMKln2eaNUqss -YNt/16DUgxpThoXfS1T8zbYHGCO0niPGMy6LYWFu0XBVgKrFcl+D1mz9vGC2CBto -VA9YhIhjtlUWwmIaJAmlTXbHCXKWLjaK9/DbsnJOlUYG5XwTC+ntW24jZnDGkHzn -Vj87JDijGzziM6qte/JM4WrUKxd6Zrvl6AaTqGH3aPxZWdFsKETfJhfbBX3vjw5+ -j6ltm4ZA+YXE2j8DLUQ8XMQlo66FUpiOj559aOXxfEb4HhJNrwo7VLsKuK56LdYb -keQmeQr+4HkDGjD0T8+0sAOx82B0TkgWYaCFU1wmzIsny+wiQmMoKJIR3T3Mzb07 -9d5ncndS7DqcdAKMuG/F9w46QWW8G0veaJlV8ws7Ags1iBOxgTKrNsQNedB7B+zw -cTqikGnDgxVfiXOBRzHq7F3ZH9HcT4SSxuM6y2YN91C2DmPbtZAwlJX5nkORANy7 -05kCAW/Md35jfVkZJsLsDDLNfRqukcWadkcKp3XvDB7/4WWFu8BrR9CHBY9j8hEt -FC4FTxZnnoDnnVg5sC8rYB6avD/MiomOUGOlHgM3MMk/Ta7fmioauCUBR5oXa/We -uhSoNyRY0/VZgE+fJ7P0Y5hzgnBDncVH5j57G0q4KTiTBDfuHBTLw+h5Htd5VBGS -5PwhKfrAvIwetRWMyRhfjixPDtcWZ2jx20fWCVxpPp+3MxBtuMgn7A== ------END RSA PRIVATE KEY----- +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-CBC,BD35E157CDD07CAD + +VU1aEcNJaFe1bhZ+sEzv70KQB94Pu2H+VoemLXtyIVzEQJV9+cymnRYjkgzykJ5d +s4J0vJMdiGtMH5lYRYEPQRNroOzJMwLngNyPiV8yLZARMR7tINdQyM7JBUFL4GfA ++0Jl/e7cZaCRJKAKQZu5L5DGuP6488tG7bKY9Rhzys21hPF+ck/8Gzfp1vC91AxF +zuy71e8ihEERF55DB5Ai1/lvEN15GUvkx14s0Oonfarxueu3dp/ch4P4PhzkY9Ci +7/ONnlpfrBR7bLajcXUq2XAO21ftDZejk5m6y0Z0bl0L+HpbJk2zFJGtwM+B+T3h +WkZqEK+RyTER67KUeecoKl297sh2YQtbxbdoTseUxktCb2/BSkpOHV5cgS64c3Ys +zGbk4dUmKv4HFs4VJ7HD3Ix6qAhMJyGQXOqze1c7ky9NoU2e05HdfgI/9We0EZQJ +PbequZZ4GOKnj4f70EbIEFyJldsJgijNCLKCafRYtygIs8zZkj/oE/S92iYZtesn +q2wxBAat3ZYn6tpkXx+4u9bSZ+U9OfYijxBv2x+BnAf0nQ1zNqmTOolEAIEMLS60 +5WFWKVaOeqAP0Q185TEqpUFqcaTCycV2w1hN/XXuAiYqXaSYwg4ZtCmWmxbn20QH +SMvRuY6MZSNNncgoLbm+ySq1yP1Z46kRsU1ufAyN3Jue+6DVd8wFrEOXfLJnCbFk +Eykpd7vxzczHXWgrlakl2sPFy4ltcALc8ZhsmGO+goWNqwp4QPX4LMHeUsA9n86Q +ABNV+KkCyIzp6FsFVqeHCxD8EoE/MuiuMHy/n0oEGj7zp9Moq5DHrgQDmdKnhrAG +B2HqYlCH54LDKd3wlgT76/HJ8yviFZECY2q6Z1BnMzm2ikKLCyPBMKln2eaNUqss +YNt/16DUgxpThoXfS1T8zbYHGCO0niPGMy6LYWFu0XBVgKrFcl+D1mz9vGC2CBto +VA9YhIhjtlUWwmIaJAmlTXbHCXKWLjaK9/DbsnJOlUYG5XwTC+ntW24jZnDGkHzn +Vj87JDijGzziM6qte/JM4WrUKxd6Zrvl6AaTqGH3aPxZWdFsKETfJhfbBX3vjw5+ +j6ltm4ZA+YXE2j8DLUQ8XMQlo66FUpiOj559aOXxfEb4HhJNrwo7VLsKuK56LdYb +keQmeQr+4HkDGjD0T8+0sAOx82B0TkgWYaCFU1wmzIsny+wiQmMoKJIR3T3Mzb07 +9d5ncndS7DqcdAKMuG/F9w46QWW8G0veaJlV8ws7Ags1iBOxgTKrNsQNedB7B+zw +cTqikGnDgxVfiXOBRzHq7F3ZH9HcT4SSxuM6y2YN91C2DmPbtZAwlJX5nkORANy7 +05kCAW/Md35jfVkZJsLsDDLNfRqukcWadkcKp3XvDB7/4WWFu8BrR9CHBY9j8hEt +FC4FTxZnnoDnnVg5sC8rYB6avD/MiomOUGOlHgM3MMk/Ta7fmioauCUBR5oXa/We +uhSoNyRY0/VZgE+fJ7P0Y5hzgnBDncVH5j57G0q4KTiTBDfuHBTLw+h5Htd5VBGS +5PwhKfrAvIwetRWMyRhfjixPDtcWZ2jx20fWCVxpPp+3MxBtuMgn7A== +-----END RSA PRIVATE KEY----- diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt index ac61e0d8..aa9250a6 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt @@ -1,30 +1,30 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,AF373EFF708479DF - -iiuyZiL4qEI7nrJQL4gQZFyYYfji0GaNntX5rPrBlBLbwQySYq5d7ExLbv3tpB++ -V1sQBHV9vcxNdq+uYqFofOuKHBXebIJLwluS+qVHC4sZoaYJxFIizl0Cf2RQzPPH -4XtAet8lrherbVm48YGAIcop9on87ILcOinNPf+0mT+wNLwFmymMkHmSByEMXU1m -7CF0GWY31rtFgfEZGw8KUjrolA0/JKUn7taLEHKHrmsXJKH2O/c7DvxMgL7ldBFk -mPVNQxsJfNGWsuU1/OzJjXWc5YYbziO2zKnJsCDpYOhATl92WABA7dPhI5jAJhWT -N1xo2JStdgy/wnyrye4WWzRZdPL47hO1bbQnpcG+VAHMsTSNngJuy1Y0pezsb7OW -2vmRM/I4QY2sPLhMOm9nbVfImJXIBukPbwpO5AtT3m+JwiyElnJcihDIaSkFTGOk -89i2tKPxWrl3obdo9CYy8ukrFMDHiOP4EGRAYFbxHLI20QDuyBEw5TR90ClCFE7P -ltM2NZRU/wCtF/4XEZ3P1KNVYu33d3hjr2J/fkba1xQ0xkCEfTXA8EgCA5ioQLie -WzdJndxuWMDZkHHeFbrLDmUBBtcv2ubC9eL6ULyeTk/v9F3gbnh46Oye3KUG64Ur -7H+NugCIDYyKdvcLl9O8JfspcNpg7ooLUliRMFCjIZI8G8V5fXqP1c4OTMaU0bGt -kBiVZeULxpKhPe8Inx4E33C1TAaHGwYezxzr9QP162ib9iWQ6hAWHizkzOYC8vRx -v0TKYR//1joVw7Wh27KOogoZEGy/gR3FZ5RxHai8inW22wlV9DobLJcib2dPkhMU -6ACAhGNwmjr1oHnCmINmKaTCxGsiqs7R13k+3qbTF5SfofOIdNzgP0rlo1X4ckuU -uA0jcNMk/R2qAn7xWDS1bdlBwj+85DlqWkKsrYuc9Jrll11HYCPoyIiY/kTahVLL -VJ+FDIjRaHEK0knjfVMtB+E3aZhaHpvLBRFNsU1POoLkqer7CyUAxD4UJSC87kIc -x8gX7kLR+ZTPuZ8Dx39jEpH+501bvoVxgDRstQkH0JTnOYJmLu/zobwAaX/+Xgdx -ALu2YJZJ8ikkFU7vbqUdzvCYKiM4srbMa+E/5wqIr6G4SSk8FupWIJWsAkczbEkH -PEfbVmWR0Lgh2i/RZU3kNqmUgV6DRfaML64z6dA13UIYIhVyg7ix6KYsJFJVKC5P -YY8No7y29htDbPqjWDZ1Y95/9foKAKhv+iNOTLfIa7H7iWYFTLYXMLt3Vsux6V9V -15+eUCe82yg7/MqcdL3IkX41AgQ6yijBWk761mbYJQ0TFNfPdtHxwKd9Rvj7nU+R -g0XhLT/b9gBNNvJeo02Hgs0axNo1WtMvd/HqYFpEx7SJf/ClniJd+kBBpn29zbLA -vaZAkxmIZc4rVeZEV8N14i9HfzmfjLM69wiMjfpO3H9nwzHHLhZCnzp483yTGKbc -EGa4dkBt3eYQDPkiK68vTt6fUfAWtiqhjmHCpOi+bZF/EfbTmz1zGIRNscFOl1Ln -bIk+F6YypdWnYjwQMr0e/RBZDVvsFH0XgHESq8hLEFXa6kWzQPIaVw== +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,AF373EFF708479DF + +iiuyZiL4qEI7nrJQL4gQZFyYYfji0GaNntX5rPrBlBLbwQySYq5d7ExLbv3tpB++ +V1sQBHV9vcxNdq+uYqFofOuKHBXebIJLwluS+qVHC4sZoaYJxFIizl0Cf2RQzPPH +4XtAet8lrherbVm48YGAIcop9on87ILcOinNPf+0mT+wNLwFmymMkHmSByEMXU1m +7CF0GWY31rtFgfEZGw8KUjrolA0/JKUn7taLEHKHrmsXJKH2O/c7DvxMgL7ldBFk +mPVNQxsJfNGWsuU1/OzJjXWc5YYbziO2zKnJsCDpYOhATl92WABA7dPhI5jAJhWT +N1xo2JStdgy/wnyrye4WWzRZdPL47hO1bbQnpcG+VAHMsTSNngJuy1Y0pezsb7OW +2vmRM/I4QY2sPLhMOm9nbVfImJXIBukPbwpO5AtT3m+JwiyElnJcihDIaSkFTGOk +89i2tKPxWrl3obdo9CYy8ukrFMDHiOP4EGRAYFbxHLI20QDuyBEw5TR90ClCFE7P +ltM2NZRU/wCtF/4XEZ3P1KNVYu33d3hjr2J/fkba1xQ0xkCEfTXA8EgCA5ioQLie +WzdJndxuWMDZkHHeFbrLDmUBBtcv2ubC9eL6ULyeTk/v9F3gbnh46Oye3KUG64Ur +7H+NugCIDYyKdvcLl9O8JfspcNpg7ooLUliRMFCjIZI8G8V5fXqP1c4OTMaU0bGt +kBiVZeULxpKhPe8Inx4E33C1TAaHGwYezxzr9QP162ib9iWQ6hAWHizkzOYC8vRx +v0TKYR//1joVw7Wh27KOogoZEGy/gR3FZ5RxHai8inW22wlV9DobLJcib2dPkhMU +6ACAhGNwmjr1oHnCmINmKaTCxGsiqs7R13k+3qbTF5SfofOIdNzgP0rlo1X4ckuU +uA0jcNMk/R2qAn7xWDS1bdlBwj+85DlqWkKsrYuc9Jrll11HYCPoyIiY/kTahVLL +VJ+FDIjRaHEK0knjfVMtB+E3aZhaHpvLBRFNsU1POoLkqer7CyUAxD4UJSC87kIc +x8gX7kLR+ZTPuZ8Dx39jEpH+501bvoVxgDRstQkH0JTnOYJmLu/zobwAaX/+Xgdx +ALu2YJZJ8ikkFU7vbqUdzvCYKiM4srbMa+E/5wqIr6G4SSk8FupWIJWsAkczbEkH +PEfbVmWR0Lgh2i/RZU3kNqmUgV6DRfaML64z6dA13UIYIhVyg7ix6KYsJFJVKC5P +YY8No7y29htDbPqjWDZ1Y95/9foKAKhv+iNOTLfIa7H7iWYFTLYXMLt3Vsux6V9V +15+eUCe82yg7/MqcdL3IkX41AgQ6yijBWk761mbYJQ0TFNfPdtHxwKd9Rvj7nU+R +g0XhLT/b9gBNNvJeo02Hgs0axNo1WtMvd/HqYFpEx7SJf/ClniJd+kBBpn29zbLA +vaZAkxmIZc4rVeZEV8N14i9HfzmfjLM69wiMjfpO3H9nwzHHLhZCnzp483yTGKbc +EGa4dkBt3eYQDPkiK68vTt6fUfAWtiqhjmHCpOi+bZF/EfbTmz1zGIRNscFOl1Ln +bIk+F6YypdWnYjwQMr0e/RBZDVvsFH0XgHESq8hLEFXa6kWzQPIaVw== -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt index 91cf550d..066d39fb 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt @@ -1,18 +1,18 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CFB,81C75CC63A21DFFB - -7BCpj4mM2LTaWGP2f/IK8+Zd7XssLHtagETCURfg+x+IYhOOsW/qORNBeOL4lT8G -s8ymGJIMjNC0aGwJb214Kp19ajMlRN8IaHtw1QD3BYIxFSx35DSWd6WrECcdaJCm -FZ5y+rXf0NMUOUKg9xXF+Xnbucau3QN4NiLBB50oJyRIRco6Wy/9AB1yKrZsll4N -3+1XnnXZuanvIugi8TybUgzyrGE1dqwyGjHtN+bf8hWu8jrnx3AkjmzXJ+yiGbd4 -w/JYfCzyVsEZuEzkn62johwNpwcuXFYEXxSSU444/TZf2BuuvvpkbCltkfvhOC3z -fp1DOtToaZadwHsH8laB+HPktisfetoPaQdqi/fGgqiERzDq9Xy7wY9JXdT65WeU -mh+USBy7mF6I57UgRM6AAZLvrJmG+hE8GYezThT9ZEnFyumrQgt8sTdWWFStYJcW -jlohuNO8c4IXwvXfVgafaIIAcFUcAKk/XgSLjMcn7YyBlaR6qIdwLLfRNEspv9mR -IF0M2ua4vZRLJfn+NOcs0n10v0jUFgMXoIqDr86OB3pW3ud/lET6bz6QYO3rNHW4 -NtAmD2wwl66nuq2d9uLUSSkQj5spVDbFzfvnZCN3yl4hdyWlmzRJqybyr5xTIbT7 -x5JF/eg3xq8weaZrFqq7r5uIhDYI7/sexxL9M/8nyV8COUYkDxxISbNpoDuCKbv8 -fyIX92mGQtM8D7YftvCbEr8kw1fga9XhkDdOEuBzKZyIAD50xE39rFFMNNq8l8/Y -Gxo8zq0rW/IsrwvhWLLGtvmy68Be+WAi/mDHf6x4 +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CFB,81C75CC63A21DFFB + +7BCpj4mM2LTaWGP2f/IK8+Zd7XssLHtagETCURfg+x+IYhOOsW/qORNBeOL4lT8G +s8ymGJIMjNC0aGwJb214Kp19ajMlRN8IaHtw1QD3BYIxFSx35DSWd6WrECcdaJCm +FZ5y+rXf0NMUOUKg9xXF+Xnbucau3QN4NiLBB50oJyRIRco6Wy/9AB1yKrZsll4N +3+1XnnXZuanvIugi8TybUgzyrGE1dqwyGjHtN+bf8hWu8jrnx3AkjmzXJ+yiGbd4 +w/JYfCzyVsEZuEzkn62johwNpwcuXFYEXxSSU444/TZf2BuuvvpkbCltkfvhOC3z +fp1DOtToaZadwHsH8laB+HPktisfetoPaQdqi/fGgqiERzDq9Xy7wY9JXdT65WeU +mh+USBy7mF6I57UgRM6AAZLvrJmG+hE8GYezThT9ZEnFyumrQgt8sTdWWFStYJcW +jlohuNO8c4IXwvXfVgafaIIAcFUcAKk/XgSLjMcn7YyBlaR6qIdwLLfRNEspv9mR +IF0M2ua4vZRLJfn+NOcs0n10v0jUFgMXoIqDr86OB3pW3ud/lET6bz6QYO3rNHW4 +NtAmD2wwl66nuq2d9uLUSSkQj5spVDbFzfvnZCN3yl4hdyWlmzRJqybyr5xTIbT7 +x5JF/eg3xq8weaZrFqq7r5uIhDYI7/sexxL9M/8nyV8COUYkDxxISbNpoDuCKbv8 +fyIX92mGQtM8D7YftvCbEr8kw1fga9XhkDdOEuBzKZyIAD50xE39rFFMNNq8l8/Y +Gxo8zq0rW/IsrwvhWLLGtvmy68Be+WAi/mDHf6x4 -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.txt index bdd30e06..cf2cc979 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.txt @@ -1,27 +1,27 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEoQIBAAKCAQEAuTtXn+BatX1oJuvhqfJZw5jc/pcIxJUPmuoFCH3+bXfKBJ/9 -4ixNETzZBasyvT/ozboAbCG3qcJOYxf2BEeTAIXe1jLAoTd1GKCwMvZOyjnsPN95 -/lChwfdnBbMzpZYTGfoUylXme/mzjjLu/J0qXgR5lyk9HFT+x5YEtRl8VSHiDkLK -TZ37dwhsqgcs+PkfvYMUK+C8evnfE0tgWgKZk0Eatl87nLWyVXB4LzhSDtGKLCPA -OgrX7fYfplDwJ2WK1N6nG0FnxW1HhDeSK7e2TbAa2vZQgvFXMWnO4O/NZKp4COpO -ReyliWhdtKAjr/+cD4yDfPjhjjKOYfxbvdRG4QIBIwKCAQAqVrTxV9o4HKoXhl93 -TVZYl/f/rX5Y0Z0quSW4zFdpendRg6e+qwpNFTjrWlS9ivNiOSSrAGR+ktAWpmQe -PD7bjFAw9ahfXSIUQfxja3+5Mc+Y4p+KlhZYOIyTlqy4Ik2CR8o84G8yR7QDPteK -Mo1XUXrguPgGedPV2SWlvK60XyAXqsewDhi7SeImZomKzbh33SXjVxakzHfa8BEU -eIIeR9oFlQMuYdo4GrHhFO2T+g/gqw/kVd1zkeEwt06fZVDErVwp+twewxxvwrk4 -CKUCzavfhDfi5sJ5YdzhDBRgkyBgJI+f15dKyqqOiAparV9+uzrD6vIuNnlVoqQA -iugLAoGBAPBliy32e83nshBknBn5HOK2rO3a1zHxvYr/NzITXtdZOjatNyfXtkwi -Ll/el5tZhJvKe9nItSI/4w7mvlvXZfW8h3MR0qb8at4jWa8ya2hwEerqaJonqjjb -+eBhg27ltZIQRk8Bv6ApXTAWkc+dFGhEIysokDQX7V72Bdrizup1AoGBAMVBLHK0 -5IFb8x7danlAmDX6bqCObId4Pce2OeONFIj1jIowvCXaE0t9zU4X5SdN5ujqu4Dq -XgzUdNeKcJxWpFO74MDRxT3CbMz36fikJnvxWl/+q0HalYuCY8gm14VYcThUBAro -3c941INueybGNLIA9jc7RMnsFtyVTvNYpaU9AoGAFJr9TRUgjf3qsPKuS15+0Zqh -G7OsC5hgtCSBEuu3rA72XHU/Pe3rDdcLSgvD2h2dpvQZPo2L3l0/WQx2t2o78H3f -uWftfAcB2Iav6nIJNNZn75BvXaug4E1ej5NUaJdYtL+Q/3UtrqR1s6opwVabWWTt -ElPvGmhzboodwk30en8CgYAyuPzNCfGdm00lMZ8JPH7pTwaBDq4xdrDM9FgHUCna -E0FlXP0uTgT2J6nSQKijtPI75JadfhgvL1E+vTLmX2wViBU45XvcrlZ92Vlr0nBL -wbgnUB1otIzauyD49AuIsFegxSWcZ8QCJmKIMlouir0X1FyR3Apfzv6Qfio+kyNH -vwKBgQCtwxojkzUSfV3zDt6bYSLBzgXgo/Zr9lS+gSggP72DzINmW2gbA0fkM2Zu -JltcfakKv4gVX/1zooz+7t+4bj6dqt+bl7hYz0VnTSDZGuo5LKDif/4gSGrdblC2 -QLTuX2HjWCZdsue7mRwL7cXR4zlIoE99+Ryhdxvc5wHSfYr/JA== +-----BEGIN RSA PRIVATE KEY----- +MIIEoQIBAAKCAQEAuTtXn+BatX1oJuvhqfJZw5jc/pcIxJUPmuoFCH3+bXfKBJ/9 +4ixNETzZBasyvT/ozboAbCG3qcJOYxf2BEeTAIXe1jLAoTd1GKCwMvZOyjnsPN95 +/lChwfdnBbMzpZYTGfoUylXme/mzjjLu/J0qXgR5lyk9HFT+x5YEtRl8VSHiDkLK +TZ37dwhsqgcs+PkfvYMUK+C8evnfE0tgWgKZk0Eatl87nLWyVXB4LzhSDtGKLCPA +OgrX7fYfplDwJ2WK1N6nG0FnxW1HhDeSK7e2TbAa2vZQgvFXMWnO4O/NZKp4COpO +ReyliWhdtKAjr/+cD4yDfPjhjjKOYfxbvdRG4QIBIwKCAQAqVrTxV9o4HKoXhl93 +TVZYl/f/rX5Y0Z0quSW4zFdpendRg6e+qwpNFTjrWlS9ivNiOSSrAGR+ktAWpmQe +PD7bjFAw9ahfXSIUQfxja3+5Mc+Y4p+KlhZYOIyTlqy4Ik2CR8o84G8yR7QDPteK +Mo1XUXrguPgGedPV2SWlvK60XyAXqsewDhi7SeImZomKzbh33SXjVxakzHfa8BEU +eIIeR9oFlQMuYdo4GrHhFO2T+g/gqw/kVd1zkeEwt06fZVDErVwp+twewxxvwrk4 +CKUCzavfhDfi5sJ5YdzhDBRgkyBgJI+f15dKyqqOiAparV9+uzrD6vIuNnlVoqQA +iugLAoGBAPBliy32e83nshBknBn5HOK2rO3a1zHxvYr/NzITXtdZOjatNyfXtkwi +Ll/el5tZhJvKe9nItSI/4w7mvlvXZfW8h3MR0qb8at4jWa8ya2hwEerqaJonqjjb ++eBhg27ltZIQRk8Bv6ApXTAWkc+dFGhEIysokDQX7V72Bdrizup1AoGBAMVBLHK0 +5IFb8x7danlAmDX6bqCObId4Pce2OeONFIj1jIowvCXaE0t9zU4X5SdN5ujqu4Dq +XgzUdNeKcJxWpFO74MDRxT3CbMz36fikJnvxWl/+q0HalYuCY8gm14VYcThUBAro +3c941INueybGNLIA9jc7RMnsFtyVTvNYpaU9AoGAFJr9TRUgjf3qsPKuS15+0Zqh +G7OsC5hgtCSBEuu3rA72XHU/Pe3rDdcLSgvD2h2dpvQZPo2L3l0/WQx2t2o78H3f +uWftfAcB2Iav6nIJNNZn75BvXaug4E1ej5NUaJdYtL+Q/3UtrqR1s6opwVabWWTt +ElPvGmhzboodwk30en8CgYAyuPzNCfGdm00lMZ8JPH7pTwaBDq4xdrDM9FgHUCna +E0FlXP0uTgT2J6nSQKijtPI75JadfhgvL1E+vTLmX2wViBU45XvcrlZ92Vlr0nBL +wbgnUB1otIzauyD49AuIsFegxSWcZ8QCJmKIMlouir0X1FyR3Apfzv6Qfio+kyNH +vwKBgQCtwxojkzUSfV3zDt6bYSLBzgXgo/Zr9lS+gSggP72DzINmW2gbA0fkM2Zu +JltcfakKv4gVX/1zooz+7t+4bj6dqt+bl7hYz0VnTSDZGuo5LKDif/4gSGrdblC2 +QLTuX2HjWCZdsue7mRwL7cXR4zlIoE99+Ryhdxvc5wHSfYr/JA== -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Properties/AssemblyInfo.cs b/src/Renci.SshNet.Tests/Properties/AssemblyInfo.cs index f68e8b94..443203d0 100644 --- a/src/Renci.SshNet.Tests/Properties/AssemblyInfo.cs +++ b/src/Renci.SshNet.Tests/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SSH.NET Tests .NET 4.0")] -[assembly: Guid("defb66b2-a4b9-40ca-b205-2183d84b7323")] +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SSH.NET Tests .NET 4.0")] +[assembly: Guid("defb66b2-a4b9-40ca-b205-2183d84b7323")] diff --git a/src/Renci.SshNet.Tests/Properties/Resources.Designer.cs b/src/Renci.SshNet.Tests/Properties/Resources.Designer.cs index 51f0afb9..cfec397f 100644 --- a/src/Renci.SshNet.Tests/Properties/Resources.Designer.cs +++ b/src/Renci.SshNet.Tests/Properties/Resources.Designer.cs @@ -1,206 +1,206 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.18033 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Renci.SshNet.Tests.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Renci.SshNet.Tests.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- - ///Proc-Type: 4,ENCRYPTED - ///DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 - /// - ///nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva - ///swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI - ///qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 - ///2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP - ///iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd - ///nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm - ///P+lkxKf2RWnh406F [rest of string was truncated]";. - /// - internal static string DSA_KEY_WITH_PASS { - get { - return ResourceManager.GetString("DSA_KEY_WITH_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- - ///MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw - ///fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe - ///bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 - ///UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr - ///u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB - ///xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM - ///HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH - ///4UOFA/UFdQ0TYXXW0 [rest of string was truncated]";. - /// - internal static string DSA_KEY_WITHOUT_PASS { - get { - return ResourceManager.GetString("DSA_KEY_WITHOUT_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to 192.168.10.192. - /// - internal static string HOST { - get { - return ResourceManager.GetString("HOST", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- - ///MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO - ///h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P - ///12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT - ///1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO - ///eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy - ///wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq - ///JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi - ///YTV9H2SWRF6UF+GiR [rest of string was truncated]";. - /// - internal static string INVALID_KEY { - get { - return ResourceManager.GetString("INVALID_KEY", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to tester. - /// - internal static string PASSWORD { - get { - return ResourceManager.GetString("PASSWORD", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to 22. - /// - internal static string PORT { - get { - return ResourceManager.GetString("PORT", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to proxy.oleg-centos.edc.renci.org. - /// - internal static string PROXY_HOST { - get { - return ResourceManager.GetString("PROXY_HOST", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to 8123. - /// - internal static string PROXY_PORT { - get { - return ResourceManager.GetString("PROXY_PORT", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- - ///Proc-Type: 4,ENCRYPTED - ///DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 - /// - ///Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr - ///uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG - ///FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ - ///OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB - ///nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ - ///bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 - ///SMP7QVfPf5aJIaa8 [rest of string was truncated]";. - /// - internal static string RSA_KEY_WITH_PASS { - get { - return ResourceManager.GetString("RSA_KEY_WITH_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- - ///MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D - ///9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl - ///9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba - ///orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb - ///d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q - ///mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz - ///9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA - ///RW493jlECIBWjd+1a [rest of string was truncated]";. - /// - internal static string RSA_KEY_WITHOUT_PASS { - get { - return ResourceManager.GetString("RSA_KEY_WITHOUT_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to tester. - /// - internal static string USERNAME { - get { - return ResourceManager.GetString("USERNAME", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18033 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Renci.SshNet.Tests.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Renci.SshNet.Tests.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- + ///Proc-Type: 4,ENCRYPTED + ///DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 + /// + ///nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva + ///swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI + ///qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 + ///2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP + ///iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd + ///nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm + ///P+lkxKf2RWnh406F [rest of string was truncated]";. + /// + internal static string DSA_KEY_WITH_PASS { + get { + return ResourceManager.GetString("DSA_KEY_WITH_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- + ///MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw + ///fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe + ///bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 + ///UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr + ///u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB + ///xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM + ///HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH + ///4UOFA/UFdQ0TYXXW0 [rest of string was truncated]";. + /// + internal static string DSA_KEY_WITHOUT_PASS { + get { + return ResourceManager.GetString("DSA_KEY_WITHOUT_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 192.168.10.192. + /// + internal static string HOST { + get { + return ResourceManager.GetString("HOST", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- + ///MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO + ///h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P + ///12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT + ///1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO + ///eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy + ///wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq + ///JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi + ///YTV9H2SWRF6UF+GiR [rest of string was truncated]";. + /// + internal static string INVALID_KEY { + get { + return ResourceManager.GetString("INVALID_KEY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to tester. + /// + internal static string PASSWORD { + get { + return ResourceManager.GetString("PASSWORD", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 22. + /// + internal static string PORT { + get { + return ResourceManager.GetString("PORT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to proxy.oleg-centos.edc.renci.org. + /// + internal static string PROXY_HOST { + get { + return ResourceManager.GetString("PROXY_HOST", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 8123. + /// + internal static string PROXY_PORT { + get { + return ResourceManager.GetString("PROXY_PORT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- + ///Proc-Type: 4,ENCRYPTED + ///DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 + /// + ///Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr + ///uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG + ///FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ + ///OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB + ///nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ + ///bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 + ///SMP7QVfPf5aJIaa8 [rest of string was truncated]";. + /// + internal static string RSA_KEY_WITH_PASS { + get { + return ResourceManager.GetString("RSA_KEY_WITH_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- + ///MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D + ///9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl + ///9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba + ///orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb + ///d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q + ///mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz + ///9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA + ///RW493jlECIBWjd+1a [rest of string was truncated]";. + /// + internal static string RSA_KEY_WITHOUT_PASS { + get { + return ResourceManager.GetString("RSA_KEY_WITHOUT_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to tester. + /// + internal static string USERNAME { + get { + return ResourceManager.GetString("USERNAME", resourceCulture); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Properties/Resources.resx b/src/Renci.SshNet.Tests/Properties/Resources.resx index 60fb7011..c392eb5c 100644 --- a/src/Renci.SshNet.Tests/Properties/Resources.resx +++ b/src/Renci.SshNet.Tests/Properties/Resources.resx @@ -1,244 +1,244 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - -----BEGIN DSA PRIVATE KEY----- -MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw -fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe -bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 -UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr -u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB -xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM -HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH -4UOFA/UFdQ0TYXXW0wRX/amynT4iTEXAx0FjxUNK5ryxloeoXiXEH4FK7D8RtJO1 -1UsaRrN+nqWiSTVAehl6tzoMCPargGcWeFlAZZnPGN76OD9J1GiKZj8CFQCl8SkF -GWfS+mH8xhLsxh1nI7rfJw== ------END DSA PRIVATE KEY----- - - - -----BEGIN DSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 - -nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva -swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI -qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 -2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP -iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd -nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm -P+lkxKf2RWnh406FxBvBZzwB3rQeeM7QTg2IcFqGnlf005FIikp6SlyhZ/3M/Nl3 -FW235vuO37jLCL8qosGt4NOWAstXaxDujfIb/Q+IYxUpWZrdiH5tM/mUXARK0Sjf -D8DHbFwAT2mUv1QxRXYJO1y4pENboEzT6LUqxJgE+ae/F/29g2RD9DhtwqKqWjhM -7jB0kNVZrz3qUKnoJHIozA== ------END DSA PRIVATE KEY----- - - - 192.168.10.192 - - - -----BEGIN DSA PRIVATE KEY----- -MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO -h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P -12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT -1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO -eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy -wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq -JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi -YTV9H2SWRF6UF+GiR5SajChveS106T9O+tepip+7V5YgFfW+ALOxwar+6V8VoUF4 -xNvNTWtaw+wK8xsgxhhYDaWVhVLVhR40QmeQhx/BQm+EYkSSa9kkCQIURGd0R+Zj -tM7dZpB+reWl9L5e2L8= ------END DSA PRIVATE KEY----- - - - tester - - - 22 - - - proxy.oleg-centos.edc.renci.org - - - 8123 - - - -----BEGIN RSA PRIVATE KEY----- -MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D -9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl -9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba -orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb -d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q -mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz -9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA -RW493jlECIBWjd+1aZWPM2vGKJtTp2q802u6DOX9cbgFUcVB899ugFqDjREVxLqU -dBqhtjDJQ0sTPBVy2CBkrsrvLy7AZd4LlaqxpdTdpkD/auUxg4zdThHT/XeQ0V0G -3BS5vGehfqgkDOQpQSm7HexM+9GDJnnzMdNXjmWBPxZU49QAlxujZeZ1M2IgKwMq -eNkWAOnZJidfsfwYluSCi8OHPN2i1s/b7pgn6ffb50S/k2mmhTHxNChDdGTlW91G -6CFLAoGBAPlGA4qzZCG4SLBQicGhhXZlwaKKfTvWNi4xNPZeoJezC0G+yZZT7IIV -zCj83t3dteaRRw15e+7NuIXZx3zl2hANfEpBZwnS4sOekvbS9/S7cEVzOEk53jRU -TOtHRsvNxS2xK3RywqoaqzcPaK2Df917yzbqvEajMRudRPrsTvYdAoGBAPggB/kJ -+VxZf13JqV2KgrFoVvykJpRlw2F5+lkH69ON9gdl976J3TNJDqAmHeWFxBUL+6Lt -9TSpMq3fYueJXg9xaTkSYg177sPRGCmRLO5aneA4nJkIB6KHRXsR71C9D4fJK8Fi -YB5n5dnBUTBhkvaI6KsxcxDzEg2zAJEcn4WNAoGBAOsHf66pI+VHWnpakINdxvqa -dL3TCFz9K8UnFK3G7y/x9Kuz4qOuNsPLaLjua7s+wXL+ASn2MwW6pqoWekKPkxZz -HWqVb8dvEFIKipDyzIepadsU3UxbIfbTI/PG3FnCAw3S7nUbvtrl8eN07arpsxKn -63zr81iLPO4mkX7ezhs/AoGADi23UA8y0hO+Ip3PKeqoYei0g3cYJbysFDLbGwfE -VTtP4ypl7aF6WrO3sWFDiXVbqW5mJpFBNjWN3gzD0rdkdek5NnYUO0jpEoD6EQD7 -QNH6ZJWFSpK+m5Kzg2AcTcGpHbO5W4H23SqCKbNGd8sPtlD3Wj1XCEhnbn9B3GgJ -HZMCgYEAjn9BH4fcobMaM15AV0s6sCEyr/vzn3QBfoIBqqqlipMqOtPDv8oyvGO4 -5tSpMrTKf4e3YAMPA4TXRAiVLjeRYlhdj3He0LkAuZZabrHeRmWqjDruMWd1TcKZ -3o8DLgYbSH7eGXUJ+euM4spKr5OLkBEkmH7Of6Qxss2njvjVNTE= ------END RSA PRIVATE KEY----- - - - -----BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 - -Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr -uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG -FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ -OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB -nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ -bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 -SMP7QVfPf5aJIaa8t+SlpvtIFTIkEhTViOCl+udT04670DGwmJUgrJAV0r+/Ytf7 -Mi+m3DagN7gGmCvYo+7r7EBl1G6e3hCSYm0rFxGOBesmCWriRoeRpxirWnkrns57 -D57pEC1hg90IdycCGpiwqubGDKFljuMLiVd2w0onVhudShPszP+nJAaq18wUB+rE -mtBv+GlpqCITREB4lG2noP4r9P9lgrOTqmKvWjvUTQjfS3u0XO/1aQllKlwe97C7 -mfOxcZQWy5F7+9CiWpDpomW7Eso89ja6uyupw4Q4gsm7EUacqOOaVxHrm3MVhYjE -Bfk9I5agKFqeHdjBUUP0DQ6X7JUEtb/Ri8ZrFnyT8sBG7JYnMTXfjPQqdR493cp2 -hWI5reZLi4CCUqt4Pcmhm2vtwJz5HXChARPYq2C3DhdJHcdhxUr97rfTGE1w8mPY -JcwSFnNN47UBcDg6nvSfY3SJKV0gmmqz9fEw1pBoCrudJKw9U0vQrNoCEJOpEETG -4XojbAMsTr0Ps5fI2X1VbVYWtU1uyZxqF8KaTCTN1Paapmqaq4N+qIFrrXA+PTH+ -dyaMLmYJ263Gy5eNkCZMeWLDFZ9WHX/Zx2ERMXfI6fyGImXkb6E0Dia+bB087BZP -9C5gHAvZIjv+FosZrViFqDfrV5hDXL6bO3+V3zieemRxRCTvMtk+RXUJDd50qIOW -gKNcSbevLPOyQH7eQbR+fU4KtJDUigbTFunSn2MZkDl2GDDlKI35wUAVr5yGsJbE -yiIQe5DgLGZcMiEpqbhuqSfuOw0cUlFVyKeNZ/Hr701HWngLt677IY8ExyuNbBfT -PRaes+hcjJ1QmJoRHZx9rQ3w0IpezCpRkRLRKJzzuQZOuwd95whKFXroFsdeaHxO -hS4PqlLbuSMLiSIaPSZM6Huc4kb5lqCaxg/SBlXTCX17Z/8TFoqV/wCJz17XnkH6 -9WtKAC2TwKxiLZ2Qzwr2XV48lASugIOZkSW2qxM9ui+b1T9ICFKRGLn/UB//pOiG -270hNJDLB/BKRExjS+RXeOpdAIJB5XsAEp8h56ub9emhhf9tCEXOn7PN7HbMCnQh -7k8EpAG0h5StLUhY1HHvynVz2/qyMvZa/bIaaudL2565Z6nDU+iBxed7O1qrbRAH -Vakr7Sa3K5niCyH5kxdyO1t29l1ksBqpDUrj+vViFuLkd3XIiui8IA== ------END RSA PRIVATE KEY----- - - - tester - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + -----BEGIN DSA PRIVATE KEY----- +MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw +fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe +bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 +UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr +u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB +xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM +HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH +4UOFA/UFdQ0TYXXW0wRX/amynT4iTEXAx0FjxUNK5ryxloeoXiXEH4FK7D8RtJO1 +1UsaRrN+nqWiSTVAehl6tzoMCPargGcWeFlAZZnPGN76OD9J1GiKZj8CFQCl8SkF +GWfS+mH8xhLsxh1nI7rfJw== +-----END DSA PRIVATE KEY----- + + + -----BEGIN DSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 + +nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva +swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI +qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 +2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP +iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd +nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm +P+lkxKf2RWnh406FxBvBZzwB3rQeeM7QTg2IcFqGnlf005FIikp6SlyhZ/3M/Nl3 +FW235vuO37jLCL8qosGt4NOWAstXaxDujfIb/Q+IYxUpWZrdiH5tM/mUXARK0Sjf +D8DHbFwAT2mUv1QxRXYJO1y4pENboEzT6LUqxJgE+ae/F/29g2RD9DhtwqKqWjhM +7jB0kNVZrz3qUKnoJHIozA== +-----END DSA PRIVATE KEY----- + + + 192.168.10.192 + + + -----BEGIN DSA PRIVATE KEY----- +MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO +h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P +12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT +1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO +eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy +wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq +JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi +YTV9H2SWRF6UF+GiR5SajChveS106T9O+tepip+7V5YgFfW+ALOxwar+6V8VoUF4 +xNvNTWtaw+wK8xsgxhhYDaWVhVLVhR40QmeQhx/BQm+EYkSSa9kkCQIURGd0R+Zj +tM7dZpB+reWl9L5e2L8= +-----END DSA PRIVATE KEY----- + + + tester + + + 22 + + + proxy.oleg-centos.edc.renci.org + + + 8123 + + + -----BEGIN RSA PRIVATE KEY----- +MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D +9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl +9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba +orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb +d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q +mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz +9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA +RW493jlECIBWjd+1aZWPM2vGKJtTp2q802u6DOX9cbgFUcVB899ugFqDjREVxLqU +dBqhtjDJQ0sTPBVy2CBkrsrvLy7AZd4LlaqxpdTdpkD/auUxg4zdThHT/XeQ0V0G +3BS5vGehfqgkDOQpQSm7HexM+9GDJnnzMdNXjmWBPxZU49QAlxujZeZ1M2IgKwMq +eNkWAOnZJidfsfwYluSCi8OHPN2i1s/b7pgn6ffb50S/k2mmhTHxNChDdGTlW91G +6CFLAoGBAPlGA4qzZCG4SLBQicGhhXZlwaKKfTvWNi4xNPZeoJezC0G+yZZT7IIV +zCj83t3dteaRRw15e+7NuIXZx3zl2hANfEpBZwnS4sOekvbS9/S7cEVzOEk53jRU +TOtHRsvNxS2xK3RywqoaqzcPaK2Df917yzbqvEajMRudRPrsTvYdAoGBAPggB/kJ ++VxZf13JqV2KgrFoVvykJpRlw2F5+lkH69ON9gdl976J3TNJDqAmHeWFxBUL+6Lt +9TSpMq3fYueJXg9xaTkSYg177sPRGCmRLO5aneA4nJkIB6KHRXsR71C9D4fJK8Fi +YB5n5dnBUTBhkvaI6KsxcxDzEg2zAJEcn4WNAoGBAOsHf66pI+VHWnpakINdxvqa +dL3TCFz9K8UnFK3G7y/x9Kuz4qOuNsPLaLjua7s+wXL+ASn2MwW6pqoWekKPkxZz +HWqVb8dvEFIKipDyzIepadsU3UxbIfbTI/PG3FnCAw3S7nUbvtrl8eN07arpsxKn +63zr81iLPO4mkX7ezhs/AoGADi23UA8y0hO+Ip3PKeqoYei0g3cYJbysFDLbGwfE +VTtP4ypl7aF6WrO3sWFDiXVbqW5mJpFBNjWN3gzD0rdkdek5NnYUO0jpEoD6EQD7 +QNH6ZJWFSpK+m5Kzg2AcTcGpHbO5W4H23SqCKbNGd8sPtlD3Wj1XCEhnbn9B3GgJ +HZMCgYEAjn9BH4fcobMaM15AV0s6sCEyr/vzn3QBfoIBqqqlipMqOtPDv8oyvGO4 +5tSpMrTKf4e3YAMPA4TXRAiVLjeRYlhdj3He0LkAuZZabrHeRmWqjDruMWd1TcKZ +3o8DLgYbSH7eGXUJ+euM4spKr5OLkBEkmH7Of6Qxss2njvjVNTE= +-----END RSA PRIVATE KEY----- + + + -----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 + +Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr +uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG +FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ +OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB +nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ +bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 +SMP7QVfPf5aJIaa8t+SlpvtIFTIkEhTViOCl+udT04670DGwmJUgrJAV0r+/Ytf7 +Mi+m3DagN7gGmCvYo+7r7EBl1G6e3hCSYm0rFxGOBesmCWriRoeRpxirWnkrns57 +D57pEC1hg90IdycCGpiwqubGDKFljuMLiVd2w0onVhudShPszP+nJAaq18wUB+rE +mtBv+GlpqCITREB4lG2noP4r9P9lgrOTqmKvWjvUTQjfS3u0XO/1aQllKlwe97C7 +mfOxcZQWy5F7+9CiWpDpomW7Eso89ja6uyupw4Q4gsm7EUacqOOaVxHrm3MVhYjE +Bfk9I5agKFqeHdjBUUP0DQ6X7JUEtb/Ri8ZrFnyT8sBG7JYnMTXfjPQqdR493cp2 +hWI5reZLi4CCUqt4Pcmhm2vtwJz5HXChARPYq2C3DhdJHcdhxUr97rfTGE1w8mPY +JcwSFnNN47UBcDg6nvSfY3SJKV0gmmqz9fEw1pBoCrudJKw9U0vQrNoCEJOpEETG +4XojbAMsTr0Ps5fI2X1VbVYWtU1uyZxqF8KaTCTN1Paapmqaq4N+qIFrrXA+PTH+ +dyaMLmYJ263Gy5eNkCZMeWLDFZ9WHX/Zx2ERMXfI6fyGImXkb6E0Dia+bB087BZP +9C5gHAvZIjv+FosZrViFqDfrV5hDXL6bO3+V3zieemRxRCTvMtk+RXUJDd50qIOW +gKNcSbevLPOyQH7eQbR+fU4KtJDUigbTFunSn2MZkDl2GDDlKI35wUAVr5yGsJbE +yiIQe5DgLGZcMiEpqbhuqSfuOw0cUlFVyKeNZ/Hr701HWngLt677IY8ExyuNbBfT +PRaes+hcjJ1QmJoRHZx9rQ3w0IpezCpRkRLRKJzzuQZOuwd95whKFXroFsdeaHxO +hS4PqlLbuSMLiSIaPSZM6Huc4kb5lqCaxg/SBlXTCX17Z/8TFoqV/wCJz17XnkH6 +9WtKAC2TwKxiLZ2Qzwr2XV48lASugIOZkSW2qxM9ui+b1T9ICFKRGLn/UB//pOiG +270hNJDLB/BKRExjS+RXeOpdAIJB5XsAEp8h56ub9emhhf9tCEXOn7PN7HbMCnQh +7k8EpAG0h5StLUhY1HHvynVz2/qyMvZa/bIaaudL2565Z6nDU+iBxed7O1qrbRAH +Vakr7Sa3K5niCyH5kxdyO1t29l1ksBqpDUrj+vViFuLkd3XIiui8IA== +-----END RSA PRIVATE KEY----- + + + tester + \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj index 9aac0d87..e4b8f4d0 100644 --- a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj +++ b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj @@ -1,566 +1,566 @@ - - - - Debug - AnyCPU - 2.0 - {C45379B9-17B1-4E89-BC2E-6D41726413E8} - Library - Properties - Renci.SshNet.Tests - Renci.SshNet.Tests - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - true - full - false - bin\Debug\ - TRACE;DEBUG;FEATURE_ENCODING_ASCII - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 0 - - - - - - - true - - - ..\Renci.SshNet.snk - - - - - - ..\..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll - - - - 3.5 - - - - - - - - - False - - - - - Classes\Abstractions\CryptoAbstraction_GenerateRandom.cs - - - Classes\Abstractions\DnsAbstraction_GetHostAddresses.cs - - - Classes\Abstractions\ThreadAbstraction_ExecuteThread.cs - - - Classes\SshMessageFactoryTest.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Resources.resx - True - True - - - - Properties\CommonAssemblyInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {2F5F8C90-0BD1-424F-997C-7BC6280919D1} - Renci.SshNet - - - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - - - - - - - - - - - - - - - Renci.SshNet.snk - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + 2.0 + {C45379B9-17B1-4E89-BC2E-6D41726413E8} + Library + Properties + Renci.SshNet.Tests + Renci.SshNet.Tests + v4.0 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + TRACE;DEBUG;FEATURE_ENCODING_ASCII + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 0 + + + + + + + true + + + ..\Renci.SshNet.snk + + + + + + ..\..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll + + + + 3.5 + + + + + + + + + False + + + + + Classes\Abstractions\CryptoAbstraction_GenerateRandom.cs + + + Classes\Abstractions\DnsAbstraction_GetHostAddresses.cs + + + Classes\Abstractions\ThreadAbstraction_ExecuteThread.cs + + + Classes\SshMessageFactoryTest.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Resources.resx + True + True + + + + Properties\CommonAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {2F5F8C90-0BD1-424F-997C-7BC6280919D1} + Renci.SshNet + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + + + + + + + + + + + + + + + Renci.SshNet.snk + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/packages.config b/src/Renci.SshNet.Tests/packages.config index 1ebfe799..f6c56582 100644 --- a/src/Renci.SshNet.Tests/packages.config +++ b/src/Renci.SshNet.Tests/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/src/Renci.SshNet.WindowsPhone/Properties/AssemblyInfo.cs b/src/Renci.SshNet.WindowsPhone/Properties/AssemblyInfo.cs index 6025b9f7..f61fb134 100644 --- a/src/Renci.SshNet.WindowsPhone/Properties/AssemblyInfo.cs +++ b/src/Renci.SshNet.WindowsPhone/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SSH.NET Windows Phone 7.1")] -[assembly: Guid("b044a9d9-fe40-4d7e-b198-c142ab9721f0")] +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SSH.NET Windows Phone 7.1")] +[assembly: Guid("b044a9d9-fe40-4d7e-b198-c142ab9721f0")] diff --git a/src/Renci.SshNet.WindowsPhone/Session.WP.cs b/src/Renci.SshNet.WindowsPhone/Session.WP.cs index e6ba0f3e..ed9b07f3 100644 --- a/src/Renci.SshNet.WindowsPhone/Session.WP.cs +++ b/src/Renci.SshNet.WindowsPhone/Session.WP.cs @@ -1,77 +1,77 @@ -using System; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Messages; -using Renci.SshNet.Messages.Authentication; -using Renci.SshNet.Messages.Connection; -using System.Diagnostics; - -namespace Renci.SshNet -{ - public partial class Session - { - partial void HandleMessageCore(Message message) - { - if (message == null) - throw new ArgumentNullException("message"); - else if (message is DisconnectMessage) - this.HandleMessage((DisconnectMessage)message); - else if (message is IgnoreMessage) - this.HandleMessage((IgnoreMessage)message); - else if (message is UnimplementedMessage) - this.HandleMessage((UnimplementedMessage)message); - else if (message is DebugMessage) - this.HandleMessage((DebugMessage)message); - else if (message is ServiceRequestMessage) - this.HandleMessage((ServiceRequestMessage)message); - else if (message is ServiceAcceptMessage) - this.HandleMessage((ServiceAcceptMessage)message); - else if (message is KeyExchangeInitMessage) - this.HandleMessage((KeyExchangeInitMessage)message); - else if (message is NewKeysMessage) - this.HandleMessage((NewKeysMessage)message); - else if (message is RequestMessage) - this.HandleMessage((RequestMessage)message); - else if (message is FailureMessage) - this.HandleMessage((FailureMessage)message); - else if (message is SuccessMessage) - this.HandleMessage((SuccessMessage)message); - else if (message is BannerMessage) - this.HandleMessage((BannerMessage)message); - else if (message is GlobalRequestMessage) - this.HandleMessage((GlobalRequestMessage)message); - else if (message is RequestSuccessMessage) - this.HandleMessage((RequestSuccessMessage)message); - else if (message is RequestFailureMessage) - this.HandleMessage((RequestFailureMessage)message); - else if (message is ChannelOpenMessage) - this.HandleMessage((ChannelOpenMessage)message); - else if (message is ChannelOpenConfirmationMessage) - this.HandleMessage((ChannelOpenConfirmationMessage)message); - else if (message is ChannelOpenFailureMessage) - this.HandleMessage((ChannelOpenFailureMessage)message); - else if (message is ChannelWindowAdjustMessage) - this.HandleMessage((ChannelWindowAdjustMessage)message); - else if (message is ChannelDataMessage) - this.HandleMessage((ChannelDataMessage)message); - else if (message is ChannelExtendedDataMessage) - this.HandleMessage((ChannelExtendedDataMessage)message); - else if (message is ChannelEofMessage) - this.HandleMessage((ChannelEofMessage)message); - else if (message is ChannelCloseMessage) - this.HandleMessage((ChannelCloseMessage)message); - else if (message is ChannelRequestMessage) - this.HandleMessage((ChannelRequestMessage)message); - else if (message is ChannelSuccessMessage) - this.HandleMessage((ChannelSuccessMessage)message); - else if (message is ChannelFailureMessage) - this.HandleMessage((ChannelFailureMessage)message); - else - { - Debug.WriteLine("SSH.NET WARNING: unknown message type {0} - may need to add new type to Session.WP.cs, HandleMessageCore method", - message.GetType().FullName); - - this.HandleMessage(message); - } - } - } -} +using System; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Messages; +using Renci.SshNet.Messages.Authentication; +using Renci.SshNet.Messages.Connection; +using System.Diagnostics; + +namespace Renci.SshNet +{ + public partial class Session + { + partial void HandleMessageCore(Message message) + { + if (message == null) + throw new ArgumentNullException("message"); + else if (message is DisconnectMessage) + this.HandleMessage((DisconnectMessage)message); + else if (message is IgnoreMessage) + this.HandleMessage((IgnoreMessage)message); + else if (message is UnimplementedMessage) + this.HandleMessage((UnimplementedMessage)message); + else if (message is DebugMessage) + this.HandleMessage((DebugMessage)message); + else if (message is ServiceRequestMessage) + this.HandleMessage((ServiceRequestMessage)message); + else if (message is ServiceAcceptMessage) + this.HandleMessage((ServiceAcceptMessage)message); + else if (message is KeyExchangeInitMessage) + this.HandleMessage((KeyExchangeInitMessage)message); + else if (message is NewKeysMessage) + this.HandleMessage((NewKeysMessage)message); + else if (message is RequestMessage) + this.HandleMessage((RequestMessage)message); + else if (message is FailureMessage) + this.HandleMessage((FailureMessage)message); + else if (message is SuccessMessage) + this.HandleMessage((SuccessMessage)message); + else if (message is BannerMessage) + this.HandleMessage((BannerMessage)message); + else if (message is GlobalRequestMessage) + this.HandleMessage((GlobalRequestMessage)message); + else if (message is RequestSuccessMessage) + this.HandleMessage((RequestSuccessMessage)message); + else if (message is RequestFailureMessage) + this.HandleMessage((RequestFailureMessage)message); + else if (message is ChannelOpenMessage) + this.HandleMessage((ChannelOpenMessage)message); + else if (message is ChannelOpenConfirmationMessage) + this.HandleMessage((ChannelOpenConfirmationMessage)message); + else if (message is ChannelOpenFailureMessage) + this.HandleMessage((ChannelOpenFailureMessage)message); + else if (message is ChannelWindowAdjustMessage) + this.HandleMessage((ChannelWindowAdjustMessage)message); + else if (message is ChannelDataMessage) + this.HandleMessage((ChannelDataMessage)message); + else if (message is ChannelExtendedDataMessage) + this.HandleMessage((ChannelExtendedDataMessage)message); + else if (message is ChannelEofMessage) + this.HandleMessage((ChannelEofMessage)message); + else if (message is ChannelCloseMessage) + this.HandleMessage((ChannelCloseMessage)message); + else if (message is ChannelRequestMessage) + this.HandleMessage((ChannelRequestMessage)message); + else if (message is ChannelSuccessMessage) + this.HandleMessage((ChannelSuccessMessage)message); + else if (message is ChannelFailureMessage) + this.HandleMessage((ChannelFailureMessage)message); + else + { + Debug.WriteLine("SSH.NET WARNING: unknown message type {0} - may need to add new type to Session.WP.cs, HandleMessageCore method", + message.GetType().FullName); + + this.HandleMessage(message); + } + } + } +} diff --git a/src/Renci.SshNet.WindowsPhone8/Properties/AssemblyInfo.cs b/src/Renci.SshNet.WindowsPhone8/Properties/AssemblyInfo.cs index ca080563..3db5746c 100644 --- a/src/Renci.SshNet.WindowsPhone8/Properties/AssemblyInfo.cs +++ b/src/Renci.SshNet.WindowsPhone8/Properties/AssemblyInfo.cs @@ -1,8 +1,8 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SSH.NET Windows Phone 8.0")] -[assembly: Guid("b044a9d9-fe40-4d7e-b198-c142ab9721f0")] - +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SSH.NET Windows Phone 8.0")] +[assembly: Guid("b044a9d9-fe40-4d7e-b198-c142ab9721f0")] + [assembly: InternalsVisibleTo("Renci.SshNet.Tests")] \ No newline at end of file diff --git a/src/Renci.SshNet.WindowsPhone8/Renci.SshNet.WindowsPhone8.csproj b/src/Renci.SshNet.WindowsPhone8/Renci.SshNet.WindowsPhone8.csproj index 714d15da..5d5391f6 100644 --- a/src/Renci.SshNet.WindowsPhone8/Renci.SshNet.WindowsPhone8.csproj +++ b/src/Renci.SshNet.WindowsPhone8/Renci.SshNet.WindowsPhone8.csproj @@ -1,948 +1,948 @@ - - - - Debug - AnyCPU - 10.0.20506 - 2.0 - {4A6CA785-1C8A-47FE-98C0-30C675A9328B} - {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - Renci.SshNet - Renci.SshNet - v8.0 - WindowsPhone - false - true - true - 11.0 - - - true - full - false - Bin\Debug - TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - true - prompt - 4 - false - Bin\Debug\Renci.SshNet.xml - true - - - none - true - Bin\Release - TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - true - prompt - 4 - false - Bin\Release\Renci.SshNet.xml - - - true - - - true - Bin\x86\Debug - TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - full - - - prompt - MinimumRecommendedRules.ruleset - false - - - Bin\x86\Release - TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - true - pdbonly - - - prompt - MinimumRecommendedRules.ruleset - - - true - Bin\ARM\Debug - TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - full - - - prompt - MinimumRecommendedRules.ruleset - false - - - Bin\ARM\Release - TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - true - pdbonly - - - prompt - MinimumRecommendedRules.ruleset - - - - Session.WP.cs - - - Abstractions\CryptoAbstraction.cs - - - Abstractions\DiagnosticAbstraction.cs - - - Abstractions\DnsAbstraction.cs - - - Abstractions\ReflectionAbstraction.cs - - - Abstractions\SocketAbstraction.cs - - - Abstractions\ThreadAbstraction.cs - - - AuthenticationMethod.cs - - - AuthenticationResult.cs - - - BaseClient.cs - - - Channels\Channel.cs - - - Channels\ChannelDirectTcpip.cs - - - Channels\ChannelForwardedTcpip.cs - - - Channels\ChannelSession.cs - - - Channels\ChannelTypes.cs - - - Channels\ClientChannel.cs - - - Channels\IChannel.cs - - - Channels\IChannelDirectTcpip.cs - - - Channels\IChannelForwardedTcpip.cs - - - Channels\IChannelSession.cs - - - Channels\ServerChannel.cs - - - CipherInfo.cs - - - ClientAuthentication.cs - - - CommandAsyncResult.cs - - - Common\Array.cs - - - Common\ASCIIEncoding.cs - - - Common\AsyncResult.cs - - - Common\AuthenticationBannerEventArgs.cs - - - Common\AuthenticationEventArgs.cs - - - Common\AuthenticationPasswordChangeEventArgs.cs - - - Common\AuthenticationPrompt.cs - - - Common\AuthenticationPromptEventArgs.cs - - - Common\BigInteger.cs - - - Common\ChannelDataEventArgs.cs - - - Common\ChannelEventArgs.cs - - - Common\ChannelExtendedDataEventArgs.cs - - - Common\ChannelOpenConfirmedEventArgs.cs - - - Common\ChannelOpenFailedEventArgs.cs - - - Common\ChannelRequestEventArgs.cs - - - Common\DerData.cs - - - Common\ExceptionEventArgs.cs - - - Common\Extensions.cs - - - Common\Extensions.cs - - - Common\HostKeyEventArgs.cs - - - Common\ObjectIdentifier.cs - - - Common\PipeStream.cs - - - Common\PortForwardEventArgs.cs - - - Common\ProxyException.cs - - - Common\ScpDownloadEventArgs.cs - - - Common\ScpException.cs - - - Common\ScpUploadEventArgs.cs - - - Common\SemaphoreLight.cs - - - Common\SftpPathNotFoundException.cs - - - Common\SftpPermissionDeniedException.cs - - - Common\ShellDataEventArgs.cs - - - Common\SshAuthenticationException.cs - - - Common\SshConnectionException.cs - - - Common\SshData.cs - - - Common\SshDataStream.cs - - - Common\SshException.cs - - - Common\SshOperationTimeoutException.cs - - - Common\SshPassPhraseNullOrEmptyException.cs - - - Common\TerminalModes.cs - - - Compression\CompressionMode.cs - - - Compression\Compressor.cs - - - Compression\Zlib.cs - - - Compression\ZlibOpenSsh.cs - - - Compression\ZlibStream.cs - - - ConnectionInfo.cs - - - ExpectAction.cs - - - ExpectAsyncResult.cs - - - ForwardedPort.cs - - - ForwardedPortDynamic.cs - - - ForwardedPortLocal.cs - - - ForwardedPortRemote.cs - - - HashInfo.cs - - - IAuthenticationMethod.cs - - - IClientAuthentication.cs - - - IConnectionInfo.cs - - - IForwardedPort.cs - - - IServiceFactory.cs - - - ISession.cs - - - ISubsystemSession.cs - - - KeyboardInteractiveAuthenticationMethod.cs - - - KeyboardInteractiveConnectionInfo.cs - - - MessageEventArgs.cs - - - Messages\Authentication\BannerMessage.cs - - - Messages\Authentication\FailureMessage.cs - - - Messages\Authentication\InformationRequestMessage.cs - - - Messages\Authentication\InformationResponseMessage.cs - - - Messages\Authentication\PasswordChangeRequiredMessage.cs - - - Messages\Authentication\PublicKeyMessage.cs - - - Messages\Authentication\RequestMessage.cs - - - Messages\Authentication\RequestMessageHost.cs - - - Messages\Authentication\RequestMessageKeyboardInteractive.cs - - - Messages\Authentication\RequestMessageNone.cs - - - Messages\Authentication\RequestMessagePassword.cs - - - Messages\Authentication\RequestMessagePublicKey.cs - - - Messages\Authentication\SuccessMessage.cs - - - Messages\Connection\ChannelCloseMessage.cs - - - Messages\Connection\ChannelDataMessage.cs - - - Messages\Connection\ChannelEofMessage.cs - - - Messages\Connection\ChannelExtendedDataMessage.cs - - - Messages\Connection\ChannelFailureMessage.cs - - - Messages\Connection\ChannelMessage.cs - - - Messages\Connection\ChannelOpenConfirmationMessage.cs - - - Messages\Connection\ChannelOpenFailureMessage.cs - - - Messages\Connection\ChannelOpenFailureReasons.cs - - - Messages\Connection\ChannelOpen\ChannelOpenInfo.cs - - - Messages\Connection\ChannelOpen\ChannelOpenMessage.cs - - - Messages\Connection\ChannelOpen\DirectTcpipChannelInfo.cs - - - Messages\Connection\ChannelOpen\ForwardedTcpipChannelInfo.cs - - - Messages\Connection\ChannelOpen\SessionChannelOpenInfo.cs - - - Messages\Connection\ChannelOpen\X11ChannelOpenInfo.cs - - - Messages\Connection\ChannelRequest\BreakRequestInfo.cs - - - Messages\Connection\ChannelRequest\ChannelRequestMessage.cs - - - Messages\Connection\ChannelRequest\EndOfWriteRequestInfo.cs - - - Messages\Connection\ChannelRequest\EnvironmentVariableRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExecRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExitSignalRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExitStatusRequestInfo.cs - - - Messages\Connection\ChannelRequest\KeepAliveRequestInfo.cs - - - Messages\Connection\ChannelRequest\PseudoTerminalInfo.cs - - - Messages\Connection\ChannelRequest\RequestInfo.cs - - - Messages\Connection\ChannelRequest\ShellRequestInfo.cs - - - Messages\Connection\ChannelRequest\SignalRequestInfo.cs - - - Messages\Connection\ChannelRequest\SubsystemRequestInfo.cs - - - Messages\Connection\ChannelRequest\WindowChangeRequestInfo.cs - - - Messages\Connection\ChannelRequest\X11ForwardingRequestInfo.cs - - - Messages\Connection\ChannelRequest\XonXoffRequestInfo.cs - - - Messages\Connection\ChannelSuccessMessage.cs - - - Messages\Connection\ChannelWindowAdjustMessage.cs - - - Messages\Connection\GlobalRequestMessage.cs - - - Messages\Connection\GlobalRequestName.cs - - - Messages\Connection\RequestFailureMessage.cs - - - Messages\Connection\RequestSuccessMessage.cs - - - Messages\Message.cs - - - Messages\MessageAttribute.cs - - - Messages\ServiceName.cs - - - Messages\Transport\DebugMessage.cs - - - Messages\Transport\DisconnectMessage.cs - - - Messages\Transport\DisconnectReason.cs - - - Messages\Transport\IgnoreMessage.cs - - - Messages\Transport\IKeyExchangedAllowed.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeGroup.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeInit.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeReply.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeRequest.cs - - - Messages\Transport\KeyExchangeDhInitMessage.cs - - - Messages\Transport\KeyExchangeDhReplyMessage.cs - - - Messages\Transport\KeyExchangeEcdhInitMessage.cs - - - Messages\Transport\KeyExchangeEcdhReplyMessage.cs - - - Messages\Transport\KeyExchangeInitMessage.cs - - - Messages\Transport\NewKeysMessage.cs - - - Messages\Transport\ServiceAcceptMessage.cs - - - Messages\Transport\ServiceRequestMessage.cs - - - Messages\Transport\UnimplementedMessage.cs - - - NoneAuthenticationMethod.cs - - - PasswordAuthenticationMethod.cs - - - PasswordConnectionInfo.cs - - - PrivateKeyAuthenticationMethod.cs - - - PrivateKeyConnectionInfo.cs - - - PrivateKeyFile.cs - - - ProxyTypes.cs - - - ScpClient.cs - - - Security\Algorithm.cs - - - Security\CertificateHostAlgorithm.cs - - - Security\Cryptography\AsymmetricCipher.cs - - - Security\Cryptography\BlockCipher.cs - - - Security\Cryptography\Cipher.cs - - - Security\Cryptography\CipherDigitalSignature.cs - - - Security\Cryptography\Ciphers\AesCipher.cs - - - Security\Cryptography\Ciphers\Arc4Cipher.cs - - - Security\Cryptography\Ciphers\BlowfishCipher.cs - - - Security\Cryptography\Ciphers\CastCipher.cs - - - Security\Cryptography\Ciphers\CipherMode.cs - - - Security\Cryptography\Ciphers\CipherPadding.cs - - - Security\Cryptography\Ciphers\DesCipher.cs - - - Security\Cryptography\Ciphers\Modes\CbcCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\CfbCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\CtrCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\OfbCipherMode.cs - - - Security\Cryptography\Ciphers\Paddings\PKCS7Padding.cs - - - Security\Cryptography\Ciphers\RsaCipher.cs - - - Security\Cryptography\Ciphers\SerpentCipher.cs - - - Security\Cryptography\Ciphers\TripleDesCipher.cs - - - Security\Cryptography\Ciphers\TwofishCipher.cs - - - Security\Cryptography\DigitalSignature.cs - - - Security\Cryptography\DsaDigitalSignature.cs - - - Security\Cryptography\DsaKey.cs - - - Security\Cryptography\HMACMD5.cs - - - Security\Cryptography\HMACSHA1.cs - - - Security\Cryptography\HMACSHA256.cs - - - Security\Cryptography\HMACSHA384.cs - - - Security\Cryptography\HMACSHA512.cs - - - Security\Cryptography\Key.cs - - - Security\Cryptography\RsaDigitalSignature.cs - - - Security\Cryptography\RsaKey.cs - - - Security\Cryptography\StreamCipher.cs - - - Security\Cryptography\SymmetricCipher.cs - - - Security\GroupExchangeHashData.cs - - - Security\HostAlgorithm.cs - - - Security\IKeyExchange.cs - - - Security\KeyExchange.cs - - - Security\KeyExchangeDiffieHellman.cs - - - Security\KeyExchangeDiffieHellmanGroup14Sha1.cs - - - Security\KeyExchangeDiffieHellmanGroup1Sha1.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeSha1.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeSha256.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeShaBase.cs - - - Security\KeyExchangeDiffieHellmanGroupSha1.cs - - - Security\KeyHostAlgorithm.cs - - - ServiceFactory.cs - - - Session.cs - - - Session.cs - - - SftpClient.cs - - - Sftp\Flags.cs - - - Sftp\ISftpSession.cs - - - Sftp\Requests\ExtendedRequests\FStatVfsRequest.cs - - - Sftp\Requests\ExtendedRequests\HardLinkRequest.cs - - - Sftp\Requests\ExtendedRequests\PosixRenameRequest.cs - - - Sftp\Requests\ExtendedRequests\StatVfsRequest.cs - - - Sftp\Requests\SftpBlockRequest.cs - - - Sftp\Requests\SftpCloseRequest.cs - - - Sftp\Requests\SftpExtendedRequest.cs - - - Sftp\Requests\SftpFSetStatRequest.cs - - - Sftp\Requests\SftpFStatRequest.cs - - - Sftp\Requests\SftpInitRequest.cs - - - Sftp\Requests\SftpLinkRequest.cs - - - Sftp\Requests\SftpLStatRequest.cs - - - Sftp\Requests\SftpMkDirRequest.cs - - - Sftp\Requests\SftpOpenDirRequest.cs - - - Sftp\Requests\SftpOpenRequest.cs - - - Sftp\Requests\SftpReadDirRequest.cs - - - Sftp\Requests\SftpReadLinkRequest.cs - - - Sftp\Requests\SftpReadRequest.cs - - - Sftp\Requests\SftpRealPathRequest.cs - - - Sftp\Requests\SftpRemoveRequest.cs - - - Sftp\Requests\SftpRenameRequest.cs - - - Sftp\Requests\SftpRequest.cs - - - Sftp\Requests\SftpRmDirRequest.cs - - - Sftp\Requests\SftpSetStatRequest.cs - - - Sftp\Requests\SftpStatRequest.cs - - - Sftp\Requests\SftpSymLinkRequest.cs - - - Sftp\Requests\SftpUnblockRequest.cs - - - Sftp\Requests\SftpWriteRequest.cs - - - Sftp\Responses\ExtendedReplies\ExtendedReplyInfo.cs - - - Sftp\Responses\ExtendedReplies\StatVfsReplyInfo.cs - - - Sftp\Responses\SftpAttrsResponse.cs - - - Sftp\Responses\SftpDataResponse.cs - - - Sftp\Responses\SftpExtendedReplyResponse.cs - - - Sftp\Responses\SftpHandleResponse.cs - - - Sftp\Responses\SftpNameResponse.cs - - - Sftp\Responses\SftpResponse.cs - - - Sftp\Responses\SftpStatusResponse.cs - - - Sftp\Responses\SftpVersionResponse.cs - - - Sftp\SftpDownloadAsyncResult.cs - - - Sftp\SftpFile.cs - - - Sftp\SftpFileAttributes.cs - - - Sftp\SftpFileStream.cs - - - Sftp\SftpFileSystemInformation.cs - - - Sftp\SftpListDirectoryAsyncResult.cs - - - Sftp\SftpMessage.cs - - - Sftp\SftpMessageTypes.cs - - - Sftp\SftpSession.cs - - - Sftp\SftpSynchronizeDirectoriesAsyncResult.cs - - - Sftp\SftpUploadAsyncResult.cs - - - Sftp\StatusCodes.cs - - - Shell.cs - - - ShellStream.cs - - - SshClient.cs - - - SshCommand.cs - - - SshMessageFactory.cs - - - SubsystemSession.cs - - - - Properties\CommonAssemblyInfo.cs - - - - - False - ..\..\packages\SshNet.Security.Cryptography.1.0.0\lib\wp8\SshNet.Security.Cryptography.dll - True - - - - - - - - - - - - - + + + + Debug + AnyCPU + 10.0.20506 + 2.0 + {4A6CA785-1C8A-47FE-98C0-30C675A9328B} + {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Renci.SshNet + Renci.SshNet + v8.0 + WindowsPhone + false + true + true + 11.0 + + + true + full + false + Bin\Debug + TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + true + prompt + 4 + false + Bin\Debug\Renci.SshNet.xml + true + + + none + true + Bin\Release + TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + true + prompt + 4 + false + Bin\Release\Renci.SshNet.xml + + + true + + + true + Bin\x86\Debug + TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + full + + + prompt + MinimumRecommendedRules.ruleset + false + + + Bin\x86\Release + TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + true + pdbonly + + + prompt + MinimumRecommendedRules.ruleset + + + true + Bin\ARM\Debug + TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + full + + + prompt + MinimumRecommendedRules.ruleset + false + + + Bin\ARM\Release + TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + true + pdbonly + + + prompt + MinimumRecommendedRules.ruleset + + + + Session.WP.cs + + + Abstractions\CryptoAbstraction.cs + + + Abstractions\DiagnosticAbstraction.cs + + + Abstractions\DnsAbstraction.cs + + + Abstractions\ReflectionAbstraction.cs + + + Abstractions\SocketAbstraction.cs + + + Abstractions\ThreadAbstraction.cs + + + AuthenticationMethod.cs + + + AuthenticationResult.cs + + + BaseClient.cs + + + Channels\Channel.cs + + + Channels\ChannelDirectTcpip.cs + + + Channels\ChannelForwardedTcpip.cs + + + Channels\ChannelSession.cs + + + Channels\ChannelTypes.cs + + + Channels\ClientChannel.cs + + + Channels\IChannel.cs + + + Channels\IChannelDirectTcpip.cs + + + Channels\IChannelForwardedTcpip.cs + + + Channels\IChannelSession.cs + + + Channels\ServerChannel.cs + + + CipherInfo.cs + + + ClientAuthentication.cs + + + CommandAsyncResult.cs + + + Common\Array.cs + + + Common\ASCIIEncoding.cs + + + Common\AsyncResult.cs + + + Common\AuthenticationBannerEventArgs.cs + + + Common\AuthenticationEventArgs.cs + + + Common\AuthenticationPasswordChangeEventArgs.cs + + + Common\AuthenticationPrompt.cs + + + Common\AuthenticationPromptEventArgs.cs + + + Common\BigInteger.cs + + + Common\ChannelDataEventArgs.cs + + + Common\ChannelEventArgs.cs + + + Common\ChannelExtendedDataEventArgs.cs + + + Common\ChannelOpenConfirmedEventArgs.cs + + + Common\ChannelOpenFailedEventArgs.cs + + + Common\ChannelRequestEventArgs.cs + + + Common\DerData.cs + + + Common\ExceptionEventArgs.cs + + + Common\Extensions.cs + + + Common\Extensions.cs + + + Common\HostKeyEventArgs.cs + + + Common\ObjectIdentifier.cs + + + Common\PipeStream.cs + + + Common\PortForwardEventArgs.cs + + + Common\ProxyException.cs + + + Common\ScpDownloadEventArgs.cs + + + Common\ScpException.cs + + + Common\ScpUploadEventArgs.cs + + + Common\SemaphoreLight.cs + + + Common\SftpPathNotFoundException.cs + + + Common\SftpPermissionDeniedException.cs + + + Common\ShellDataEventArgs.cs + + + Common\SshAuthenticationException.cs + + + Common\SshConnectionException.cs + + + Common\SshData.cs + + + Common\SshDataStream.cs + + + Common\SshException.cs + + + Common\SshOperationTimeoutException.cs + + + Common\SshPassPhraseNullOrEmptyException.cs + + + Common\TerminalModes.cs + + + Compression\CompressionMode.cs + + + Compression\Compressor.cs + + + Compression\Zlib.cs + + + Compression\ZlibOpenSsh.cs + + + Compression\ZlibStream.cs + + + ConnectionInfo.cs + + + ExpectAction.cs + + + ExpectAsyncResult.cs + + + ForwardedPort.cs + + + ForwardedPortDynamic.cs + + + ForwardedPortLocal.cs + + + ForwardedPortRemote.cs + + + HashInfo.cs + + + IAuthenticationMethod.cs + + + IClientAuthentication.cs + + + IConnectionInfo.cs + + + IForwardedPort.cs + + + IServiceFactory.cs + + + ISession.cs + + + ISubsystemSession.cs + + + KeyboardInteractiveAuthenticationMethod.cs + + + KeyboardInteractiveConnectionInfo.cs + + + MessageEventArgs.cs + + + Messages\Authentication\BannerMessage.cs + + + Messages\Authentication\FailureMessage.cs + + + Messages\Authentication\InformationRequestMessage.cs + + + Messages\Authentication\InformationResponseMessage.cs + + + Messages\Authentication\PasswordChangeRequiredMessage.cs + + + Messages\Authentication\PublicKeyMessage.cs + + + Messages\Authentication\RequestMessage.cs + + + Messages\Authentication\RequestMessageHost.cs + + + Messages\Authentication\RequestMessageKeyboardInteractive.cs + + + Messages\Authentication\RequestMessageNone.cs + + + Messages\Authentication\RequestMessagePassword.cs + + + Messages\Authentication\RequestMessagePublicKey.cs + + + Messages\Authentication\SuccessMessage.cs + + + Messages\Connection\ChannelCloseMessage.cs + + + Messages\Connection\ChannelDataMessage.cs + + + Messages\Connection\ChannelEofMessage.cs + + + Messages\Connection\ChannelExtendedDataMessage.cs + + + Messages\Connection\ChannelFailureMessage.cs + + + Messages\Connection\ChannelMessage.cs + + + Messages\Connection\ChannelOpenConfirmationMessage.cs + + + Messages\Connection\ChannelOpenFailureMessage.cs + + + Messages\Connection\ChannelOpenFailureReasons.cs + + + Messages\Connection\ChannelOpen\ChannelOpenInfo.cs + + + Messages\Connection\ChannelOpen\ChannelOpenMessage.cs + + + Messages\Connection\ChannelOpen\DirectTcpipChannelInfo.cs + + + Messages\Connection\ChannelOpen\ForwardedTcpipChannelInfo.cs + + + Messages\Connection\ChannelOpen\SessionChannelOpenInfo.cs + + + Messages\Connection\ChannelOpen\X11ChannelOpenInfo.cs + + + Messages\Connection\ChannelRequest\BreakRequestInfo.cs + + + Messages\Connection\ChannelRequest\ChannelRequestMessage.cs + + + Messages\Connection\ChannelRequest\EndOfWriteRequestInfo.cs + + + Messages\Connection\ChannelRequest\EnvironmentVariableRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExecRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExitSignalRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExitStatusRequestInfo.cs + + + Messages\Connection\ChannelRequest\KeepAliveRequestInfo.cs + + + Messages\Connection\ChannelRequest\PseudoTerminalInfo.cs + + + Messages\Connection\ChannelRequest\RequestInfo.cs + + + Messages\Connection\ChannelRequest\ShellRequestInfo.cs + + + Messages\Connection\ChannelRequest\SignalRequestInfo.cs + + + Messages\Connection\ChannelRequest\SubsystemRequestInfo.cs + + + Messages\Connection\ChannelRequest\WindowChangeRequestInfo.cs + + + Messages\Connection\ChannelRequest\X11ForwardingRequestInfo.cs + + + Messages\Connection\ChannelRequest\XonXoffRequestInfo.cs + + + Messages\Connection\ChannelSuccessMessage.cs + + + Messages\Connection\ChannelWindowAdjustMessage.cs + + + Messages\Connection\GlobalRequestMessage.cs + + + Messages\Connection\GlobalRequestName.cs + + + Messages\Connection\RequestFailureMessage.cs + + + Messages\Connection\RequestSuccessMessage.cs + + + Messages\Message.cs + + + Messages\MessageAttribute.cs + + + Messages\ServiceName.cs + + + Messages\Transport\DebugMessage.cs + + + Messages\Transport\DisconnectMessage.cs + + + Messages\Transport\DisconnectReason.cs + + + Messages\Transport\IgnoreMessage.cs + + + Messages\Transport\IKeyExchangedAllowed.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeGroup.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeInit.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeReply.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeRequest.cs + + + Messages\Transport\KeyExchangeDhInitMessage.cs + + + Messages\Transport\KeyExchangeDhReplyMessage.cs + + + Messages\Transport\KeyExchangeEcdhInitMessage.cs + + + Messages\Transport\KeyExchangeEcdhReplyMessage.cs + + + Messages\Transport\KeyExchangeInitMessage.cs + + + Messages\Transport\NewKeysMessage.cs + + + Messages\Transport\ServiceAcceptMessage.cs + + + Messages\Transport\ServiceRequestMessage.cs + + + Messages\Transport\UnimplementedMessage.cs + + + NoneAuthenticationMethod.cs + + + PasswordAuthenticationMethod.cs + + + PasswordConnectionInfo.cs + + + PrivateKeyAuthenticationMethod.cs + + + PrivateKeyConnectionInfo.cs + + + PrivateKeyFile.cs + + + ProxyTypes.cs + + + ScpClient.cs + + + Security\Algorithm.cs + + + Security\CertificateHostAlgorithm.cs + + + Security\Cryptography\AsymmetricCipher.cs + + + Security\Cryptography\BlockCipher.cs + + + Security\Cryptography\Cipher.cs + + + Security\Cryptography\CipherDigitalSignature.cs + + + Security\Cryptography\Ciphers\AesCipher.cs + + + Security\Cryptography\Ciphers\Arc4Cipher.cs + + + Security\Cryptography\Ciphers\BlowfishCipher.cs + + + Security\Cryptography\Ciphers\CastCipher.cs + + + Security\Cryptography\Ciphers\CipherMode.cs + + + Security\Cryptography\Ciphers\CipherPadding.cs + + + Security\Cryptography\Ciphers\DesCipher.cs + + + Security\Cryptography\Ciphers\Modes\CbcCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\CfbCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\CtrCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\OfbCipherMode.cs + + + Security\Cryptography\Ciphers\Paddings\PKCS7Padding.cs + + + Security\Cryptography\Ciphers\RsaCipher.cs + + + Security\Cryptography\Ciphers\SerpentCipher.cs + + + Security\Cryptography\Ciphers\TripleDesCipher.cs + + + Security\Cryptography\Ciphers\TwofishCipher.cs + + + Security\Cryptography\DigitalSignature.cs + + + Security\Cryptography\DsaDigitalSignature.cs + + + Security\Cryptography\DsaKey.cs + + + Security\Cryptography\HMACMD5.cs + + + Security\Cryptography\HMACSHA1.cs + + + Security\Cryptography\HMACSHA256.cs + + + Security\Cryptography\HMACSHA384.cs + + + Security\Cryptography\HMACSHA512.cs + + + Security\Cryptography\Key.cs + + + Security\Cryptography\RsaDigitalSignature.cs + + + Security\Cryptography\RsaKey.cs + + + Security\Cryptography\StreamCipher.cs + + + Security\Cryptography\SymmetricCipher.cs + + + Security\GroupExchangeHashData.cs + + + Security\HostAlgorithm.cs + + + Security\IKeyExchange.cs + + + Security\KeyExchange.cs + + + Security\KeyExchangeDiffieHellman.cs + + + Security\KeyExchangeDiffieHellmanGroup14Sha1.cs + + + Security\KeyExchangeDiffieHellmanGroup1Sha1.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeSha1.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeSha256.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeShaBase.cs + + + Security\KeyExchangeDiffieHellmanGroupSha1.cs + + + Security\KeyHostAlgorithm.cs + + + ServiceFactory.cs + + + Session.cs + + + Session.cs + + + SftpClient.cs + + + Sftp\Flags.cs + + + Sftp\ISftpSession.cs + + + Sftp\Requests\ExtendedRequests\FStatVfsRequest.cs + + + Sftp\Requests\ExtendedRequests\HardLinkRequest.cs + + + Sftp\Requests\ExtendedRequests\PosixRenameRequest.cs + + + Sftp\Requests\ExtendedRequests\StatVfsRequest.cs + + + Sftp\Requests\SftpBlockRequest.cs + + + Sftp\Requests\SftpCloseRequest.cs + + + Sftp\Requests\SftpExtendedRequest.cs + + + Sftp\Requests\SftpFSetStatRequest.cs + + + Sftp\Requests\SftpFStatRequest.cs + + + Sftp\Requests\SftpInitRequest.cs + + + Sftp\Requests\SftpLinkRequest.cs + + + Sftp\Requests\SftpLStatRequest.cs + + + Sftp\Requests\SftpMkDirRequest.cs + + + Sftp\Requests\SftpOpenDirRequest.cs + + + Sftp\Requests\SftpOpenRequest.cs + + + Sftp\Requests\SftpReadDirRequest.cs + + + Sftp\Requests\SftpReadLinkRequest.cs + + + Sftp\Requests\SftpReadRequest.cs + + + Sftp\Requests\SftpRealPathRequest.cs + + + Sftp\Requests\SftpRemoveRequest.cs + + + Sftp\Requests\SftpRenameRequest.cs + + + Sftp\Requests\SftpRequest.cs + + + Sftp\Requests\SftpRmDirRequest.cs + + + Sftp\Requests\SftpSetStatRequest.cs + + + Sftp\Requests\SftpStatRequest.cs + + + Sftp\Requests\SftpSymLinkRequest.cs + + + Sftp\Requests\SftpUnblockRequest.cs + + + Sftp\Requests\SftpWriteRequest.cs + + + Sftp\Responses\ExtendedReplies\ExtendedReplyInfo.cs + + + Sftp\Responses\ExtendedReplies\StatVfsReplyInfo.cs + + + Sftp\Responses\SftpAttrsResponse.cs + + + Sftp\Responses\SftpDataResponse.cs + + + Sftp\Responses\SftpExtendedReplyResponse.cs + + + Sftp\Responses\SftpHandleResponse.cs + + + Sftp\Responses\SftpNameResponse.cs + + + Sftp\Responses\SftpResponse.cs + + + Sftp\Responses\SftpStatusResponse.cs + + + Sftp\Responses\SftpVersionResponse.cs + + + Sftp\SftpDownloadAsyncResult.cs + + + Sftp\SftpFile.cs + + + Sftp\SftpFileAttributes.cs + + + Sftp\SftpFileStream.cs + + + Sftp\SftpFileSystemInformation.cs + + + Sftp\SftpListDirectoryAsyncResult.cs + + + Sftp\SftpMessage.cs + + + Sftp\SftpMessageTypes.cs + + + Sftp\SftpSession.cs + + + Sftp\SftpSynchronizeDirectoriesAsyncResult.cs + + + Sftp\SftpUploadAsyncResult.cs + + + Sftp\StatusCodes.cs + + + Shell.cs + + + ShellStream.cs + + + SshClient.cs + + + SshCommand.cs + + + SshMessageFactory.cs + + + SubsystemSession.cs + + + + Properties\CommonAssemblyInfo.cs + + + + + False + ..\..\packages\SshNet.Security.Cryptography.1.0.0\lib\wp8\SshNet.Security.Cryptography.dll + True + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Renci.SshNet/AuthenticationMethod.cs b/src/Renci.SshNet/AuthenticationMethod.cs index 2a7534d2..2b7302ca 100644 --- a/src/Renci.SshNet/AuthenticationMethod.cs +++ b/src/Renci.SshNet/AuthenticationMethod.cs @@ -1,63 +1,63 @@ -using System; -using System.Collections.Generic; - -namespace Renci.SshNet -{ - /// - /// Base class for all supported authentication methods - /// - public abstract class AuthenticationMethod : IAuthenticationMethod - { - /// - /// Gets the name of the authentication method. - /// - /// - /// The name of the authentication method. - /// - public abstract string Name { get; } - - /// - /// Gets connection username. - /// - public string Username { get; private set; } - - /// - /// Gets list of allowed authentications. - /// - public IList AllowedAuthentications { get; protected set; } - - /// - /// Initializes a new instance of the class. - /// - /// The username. - /// is whitespace or null. - protected AuthenticationMethod(string username) - { - if (username.IsNullOrWhiteSpace()) - throw new ArgumentException("username"); - - Username = username; - } - - /// - /// Authenticates the specified session. - /// - /// The session to authenticate. - /// - /// The result of the authentication process. - /// - public abstract AuthenticationResult Authenticate(Session session); - - /// - /// Authenticates the specified session. - /// - /// The session to authenticate. - /// - /// The result of the authentication process. - /// - AuthenticationResult IAuthenticationMethod.Authenticate(ISession session) - { - return Authenticate((Session) session); - } - } -} +using System; +using System.Collections.Generic; + +namespace Renci.SshNet +{ + /// + /// Base class for all supported authentication methods + /// + public abstract class AuthenticationMethod : IAuthenticationMethod + { + /// + /// Gets the name of the authentication method. + /// + /// + /// The name of the authentication method. + /// + public abstract string Name { get; } + + /// + /// Gets connection username. + /// + public string Username { get; private set; } + + /// + /// Gets list of allowed authentications. + /// + public IList AllowedAuthentications { get; protected set; } + + /// + /// Initializes a new instance of the class. + /// + /// The username. + /// is whitespace or null. + protected AuthenticationMethod(string username) + { + if (username.IsNullOrWhiteSpace()) + throw new ArgumentException("username"); + + Username = username; + } + + /// + /// Authenticates the specified session. + /// + /// The session to authenticate. + /// + /// The result of the authentication process. + /// + public abstract AuthenticationResult Authenticate(Session session); + + /// + /// Authenticates the specified session. + /// + /// The session to authenticate. + /// + /// The result of the authentication process. + /// + AuthenticationResult IAuthenticationMethod.Authenticate(ISession session) + { + return Authenticate((Session) session); + } + } +} diff --git a/src/Renci.SshNet/AuthenticationResult.cs b/src/Renci.SshNet/AuthenticationResult.cs index bfc1b019..71414966 100644 --- a/src/Renci.SshNet/AuthenticationResult.cs +++ b/src/Renci.SshNet/AuthenticationResult.cs @@ -1,21 +1,21 @@ -namespace Renci.SshNet -{ - /// - /// Represents possible authentication methods results - /// - public enum AuthenticationResult - { - /// - /// Authentication was successful. - /// - Success, - /// - /// Authentication completed with partial success. - /// - PartialSuccess, - /// - /// Authentication failed. - /// - Failure - } -} +namespace Renci.SshNet +{ + /// + /// Represents possible authentication methods results + /// + public enum AuthenticationResult + { + /// + /// Authentication was successful. + /// + Success, + /// + /// Authentication completed with partial success. + /// + PartialSuccess, + /// + /// Authentication failed. + /// + Failure + } +} diff --git a/src/Renci.SshNet/Channels/Channel.cs b/src/Renci.SshNet/Channels/Channel.cs index bd306eaf..f9e57ced 100644 --- a/src/Renci.SshNet/Channels/Channel.cs +++ b/src/Renci.SshNet/Channels/Channel.cs @@ -1,915 +1,915 @@ -using System; -using System.Net.Sockets; -using System.Threading; -using Renci.SshNet.Common; -using Renci.SshNet.Messages; -using Renci.SshNet.Messages.Connection; -using System.Globalization; - -namespace Renci.SshNet.Channels -{ - /// - /// Represents base class for SSH channel implementations. - /// - internal abstract class Channel : IChannel - { - private const int Initial = 0; - private const int Considered = 1; - private const int Sent = 2; - - private EventWaitHandle _channelClosedWaitHandle = new ManualResetEvent(false); - private EventWaitHandle _channelServerWindowAdjustWaitHandle = new ManualResetEvent(false); - private EventWaitHandle _errorOccuredWaitHandle = new ManualResetEvent(false); - private readonly object _serverWindowSizeLock = new object(); - private readonly uint _initialWindowSize; - private uint? _remoteWindowSize; - private uint? _remoteChannelNumber; - private uint? _remotePacketSize; - private ISession _session; - - /// - /// Holds a value indicating whether the SSH_MSG_CHANNEL_CLOSE has been sent to the remote party. - /// - /// - /// 0 when the SSH_MSG_CHANNEL_CLOSE message has not been sent or considered - /// 1 when sending a SSH_MSG_CHANNEL_CLOSE message to the remote party is under consideration - /// 2 when this message has been sent to the remote party - /// - private int _closeMessageSent; - - /// - /// Holds a value indicating whether a SSH_MSG_CHANNEL_CLOSE has been received from the other - /// party. - /// - /// - /// true when a SSH_MSG_CHANNEL_CLOSE message has been received from the other party; - /// otherwise, false. - /// - private bool _closeMessageReceived; - - /// - /// Holds a value indicating whether the SSH_MSG_CHANNEL_EOF has been received from the other party. - /// - /// - /// true when a SSH_MSG_CHANNEL_EOF message has been received from the other party; - /// otherwise, false. - /// - private bool _eofMessageReceived; - - /// - /// Holds a value indicating whether the SSH_MSG_CHANNEL_EOF has been sent to the remote party. - /// - /// - /// 0 when the SSH_MSG_CHANNEL_EOF message has not been sent or considered - /// 1 when sending a SSH_MSG_CHANNEL_EOF message to the remote party is under consideration - /// 2 when this message has been sent to the remote party - /// - private int _eofMessageSent; - - /// - /// Occurs when an exception is thrown when processing channel messages. - /// - public event EventHandler Exception; - - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - protected Channel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) - { - _session = session; - _initialWindowSize = localWindowSize; - LocalChannelNumber = localChannelNumber; - LocalPacketSize = localPacketSize; - LocalWindowSize = localWindowSize; - - _session.ChannelWindowAdjustReceived += OnChannelWindowAdjust; - _session.ChannelDataReceived += OnChannelData; - _session.ChannelExtendedDataReceived += OnChannelExtendedData; - _session.ChannelEofReceived += OnChannelEof; - _session.ChannelCloseReceived += OnChannelClose; - _session.ChannelRequestReceived += OnChannelRequest; - _session.ChannelSuccessReceived += OnChannelSuccess; - _session.ChannelFailureReceived += OnChannelFailure; - _session.ErrorOccured += Session_ErrorOccured; - _session.Disconnected += Session_Disconnected; - } - - /// - /// Gets the session. - /// - /// - /// Thhe session. - /// - protected ISession Session - { - get { return _session; } - } - - /// - /// Gets the type of the channel. - /// - /// - /// The type of the channel. - /// - public abstract ChannelTypes ChannelType { get; } - - /// - /// Gets the local channel number. - /// - /// - /// The local channel number. - /// - public uint LocalChannelNumber { get; private set; } - - /// - /// Gets the maximum size of a packet. - /// - /// - /// The maximum size of a packet. - /// - public uint LocalPacketSize { get; private set; } - - /// - /// Gets the size of the local window. - /// - /// - /// The size of the local window. - /// - public uint LocalWindowSize { get; private set; } - - /// - /// Gets the remote channel number. - /// - /// - /// The remote channel number. - /// - public uint RemoteChannelNumber - { - get - { - if (!_remoteChannelNumber.HasValue) - throw CreateRemoteChannelInfoNotAvailableException(); - return _remoteChannelNumber.Value; - } - private set - { - _remoteChannelNumber = value; - } - } - - /// - /// Gets the maximum size of a data packet that we can send using the channel. - /// - /// - /// The maximum size of data that can be sent using a - /// on the current channel. - /// - /// The channel has not been opened, or the open has not yet been confirmed. - public uint RemotePacketSize - { - get - { - if (!_remotePacketSize.HasValue) - throw CreateRemoteChannelInfoNotAvailableException(); - return _remotePacketSize.Value; - } - private set - { - _remotePacketSize = value; - } - } - - /// - /// Gets the window size of the remote server. - /// - /// - /// The size of the server window. - /// - public uint RemoteWindowSize - { - get - { - if (!_remoteWindowSize.HasValue) - throw CreateRemoteChannelInfoNotAvailableException(); - return _remoteWindowSize.Value; - } - private set - { - _remoteWindowSize = value; - } - } - - /// - /// Gets a value indicating whether this channel is open. - /// - /// - /// true if this channel is open; otherwise, false. - /// - public bool IsOpen { get; protected set; } - - #region Message events - - /// - /// Occurs when message received - /// - public event EventHandler DataReceived; - - /// - /// Occurs when message received - /// - public event EventHandler ExtendedDataReceived; - - /// - /// Occurs when message received - /// - public event EventHandler EndOfData; - - /// - /// Occurs when message received - /// - public event EventHandler Closed; - - /// - /// Occurs when message received - /// - public event EventHandler RequestReceived; - - /// - /// Occurs when message received - /// - public event EventHandler RequestSucceeded; - - /// - /// Occurs when message received - /// - public event EventHandler RequestFailed; - - #endregion - - /// - /// Gets a value indicating whether the session is connected. - /// - /// - /// true if the session is connected; otherwise, false. - /// - protected bool IsConnected - { - get { return _session.IsConnected; } - } - - /// - /// Gets the connection info. - /// - /// The connection info. - protected IConnectionInfo ConnectionInfo - { - get { return _session.ConnectionInfo; } - } - - /// - /// Gets the session semaphore to control number of session channels - /// - /// The session semaphore. - protected SemaphoreLight SessionSemaphore - { - get { return _session.SessionSemaphore; } - } - - protected void InitializeRemoteInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) - { - RemoteChannelNumber = remoteChannelNumber; - RemoteWindowSize = remoteWindowSize; - RemotePacketSize = remotePacketSize; - } - - /// - /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. - /// - /// The payload to send. - public void SendData(byte[] data) - { - SendData(data, 0, data.Length); - } - - /// - /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. - /// - /// An array of containing the payload to send. - /// The zero-based offset in at which to begin taking data from. - /// The number of bytes of to send. - /// - /// - /// When the size of the data to send exceeds the maximum packet size or the remote window - /// size does not allow the full data to be sent, then this method will send the data in - /// multiple chunks and will wait for the remote window size to be adjusted when it's zero. - /// - /// - /// This is done to support SSH servers will a small window size that do not agressively - /// increase their window size. We need to take into account that there may be SSH servers - /// that only increase their window size when it has reached zero. - /// - /// - public void SendData(byte[] data, int offset, int size) - { - // send channel messages only while channel is open - if (!IsOpen) - return; - - var totalBytesToSend = size; - while (totalBytesToSend > 0) - { - var sizeOfCurrentMessage = GetDataLengthThatCanBeSentInMessage(totalBytesToSend); - - var channelDataMessage = new ChannelDataMessage( - RemoteChannelNumber, - data, - offset, - sizeOfCurrentMessage); - _session.SendMessage(channelDataMessage); - - totalBytesToSend -= sizeOfCurrentMessage; - offset += sizeOfCurrentMessage; - } - } - - /// - /// Closes the channel. - /// - public void Close() - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.Close"); -#endif // DEBUG_GERT - Close(true); - } - - #region Channel virtual methods - - /// - /// Called when channel window need to be adjust. - /// - /// The bytes to add. - protected virtual void OnWindowAdjust(uint bytesToAdd) - { - lock (_serverWindowSizeLock) - { - RemoteWindowSize += bytesToAdd; - } - _channelServerWindowAdjustWaitHandle.Set(); - } - - /// - /// Called when channel data is received. - /// - /// The data. - protected virtual void OnData(byte[] data) - { - AdjustDataWindow(data); - - var dataReceived = DataReceived; - if (dataReceived != null) - dataReceived(this, new ChannelDataEventArgs(LocalChannelNumber, data)); - } - - /// - /// Called when channel extended data is received. - /// - /// The data. - /// The data type code. - protected virtual void OnExtendedData(byte[] data, uint dataTypeCode) - { - AdjustDataWindow(data); - - var extendedDataReceived = ExtendedDataReceived; - if (extendedDataReceived != null) - extendedDataReceived(this, new ChannelExtendedDataEventArgs(LocalChannelNumber, data, dataTypeCode)); - } - - /// - /// Called when channel has no more data to receive. - /// - protected virtual void OnEof() - { - _eofMessageReceived = true; - - var endOfData = EndOfData; - if (endOfData != null) - endOfData(this, new ChannelEventArgs(LocalChannelNumber)); - } - - /// - /// Called when channel is closed by the server. - /// - protected virtual void OnClose() - { - _closeMessageReceived = true; - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.OnClose()"); -#endif // DEBUG_GERT - - // close the channel - Close(false); - - var closed = Closed; - if (closed != null) - closed(this, new ChannelEventArgs(LocalChannelNumber)); - } - - /// - /// Called when channel request received. - /// - /// Channel request information. - protected virtual void OnRequest(RequestInfo info) - { - var requestReceived = RequestReceived; - if (requestReceived != null) - requestReceived(this, new ChannelRequestEventArgs(info)); - } - - /// - /// Called when channel request was successful - /// - protected virtual void OnSuccess() - { - var requestSuccessed = RequestSucceeded; - if (requestSuccessed != null) - requestSuccessed(this, new ChannelEventArgs(LocalChannelNumber)); - } - - /// - /// Called when channel request failed. - /// - protected virtual void OnFailure() - { - var requestFailed = RequestFailed; - if (requestFailed != null) - requestFailed(this, new ChannelEventArgs(LocalChannelNumber)); - } - - #endregion // Channel virtual methods - - /// - /// Raises event. - /// - /// The exception. - protected void RaiseExceptionEvent(Exception exception) - { - var handlers = Exception; - if (handlers != null) - { - handlers(this, new ExceptionEventArgs(exception)); - } - } - - /// - /// Sends a message to the server. - /// - /// The message to send. - /// - /// true if the message was sent to the server; otherwise, false. - /// - /// The size of the packet exceeds the maximum size defined by the protocol. - /// - /// This methods returns false when the attempt to send the message results in a - /// or a . - /// - private bool TrySendMessage(Message message) - { - return _session.TrySendMessage(message); - } - - /// - /// Sends SSH message to the server. - /// - /// The message. - protected void SendMessage(Message message) - { - // send channel messages only while channel is open - if (!IsOpen) - return; - - _session.SendMessage(message); - } - - /// - /// Sends a SSH_MSG_CHANNEL_EOF message to the remote server. - /// - /// The channel is closed. - public void SendEof() - { - if (!IsOpen) - throw CreateChannelClosedException(); - - _session.SendMessage(new ChannelEofMessage(RemoteChannelNumber)); - _eofMessageSent = Sent; - } - - /// - /// Waits for the handle to be signaled or for an error to occurs. - /// - /// The wait handle. - protected void WaitOnHandle(WaitHandle waitHandle) - { - _session.WaitOnHandle(waitHandle); - } - - /// - /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to - /// be received from the server. - /// - /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. - protected virtual void Close(bool wait) - { - // send EOF message first when channel need to be closed, and the remote party has not already sent - // a SSH_MSG_CHANNEL_EOF or SSH_MSG_CHANNEL_CLOSE message - // - // note that we might have had a race condition here when the remote party sends a SSH_MSG_CHANNEL_CLOSE - // immediately after it has sent a SSH_MSG_CHANNEL_EOF message - // - // in that case, we would risk sending a SSH_MSG_CHANNEL_EOF message after the remote party has - // closed its end of the channel - // - // as a solution for this issue we only send a SSH_MSG_CHANNEL_EOF message if we haven't received a - // SSH_MSG_CHANNEL_EOF or SSH_MSG_CHANNEL_CLOSE message from the remote party - if (Interlocked.CompareExchange(ref _eofMessageSent, Considered, Initial) == Initial) - { - if (!_closeMessageReceived && !_eofMessageReceived && IsOpen && IsConnected) - { - if (TrySendMessage(new ChannelEofMessage(RemoteChannelNumber))) - _eofMessageSent = Sent; - } - } - - // send message to close the channel on the server - if (Interlocked.CompareExchange(ref _closeMessageSent, Considered, Initial) == Initial) - { - // ignore sending close message when client is not connected or the channel is closed - if (IsOpen && IsConnected) - { - if (TrySendMessage(new ChannelCloseMessage(RemoteChannelNumber))) - _closeMessageSent = Sent; - } - } - - // mark the channel closed - IsOpen = false; - - // wait for channel to be closed if we actually sent a close message (either to initiate closing - // the channel, or as response to a SSH_MSG_CHANNEL_CLOSE message sent by the server - if (wait && _closeMessageSent == Sent) - { - try - { - WaitOnHandle(_channelClosedWaitHandle); - } - catch (SshConnectionException) - { - // ignore connection failures as we're closing the channel anyway - } - } - - // reset indicators in case we want to reopen the channel; these are safe to reset - // since the channel is marked closed by now - _eofMessageSent = Initial; - _eofMessageReceived = false; - _closeMessageReceived = false; - _closeMessageSent = Initial; - } - - protected virtual void OnDisconnected() - { - } - - protected virtual void OnErrorOccured(Exception exp) - { - } - - private void Session_Disconnected(object sender, EventArgs e) - { - IsOpen = false; - - try - { - OnDisconnected(); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - - /// - /// Called when an occurs while processing a channel message. - /// - /// The . - /// - /// This method will in turn invoke , and - /// raise the event. - /// - protected void OnChannelException(Exception ex) - { - OnErrorOccured(ex); - RaiseExceptionEvent(ex); - } - - private void Session_ErrorOccured(object sender, ExceptionEventArgs e) - { - try - { - OnErrorOccured(e.Exception); - - var errorOccuredWaitHandle = _errorOccuredWaitHandle; - if (errorOccuredWaitHandle != null) - errorOccuredWaitHandle.Set(); - } - catch (Exception ex) - { - RaiseExceptionEvent(ex); - } - } - - #region Channel message event handlers - - private void OnChannelWindowAdjust(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnWindowAdjust(e.Message.BytesToAdd); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelData(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnData(e.Message.Data); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelExtendedData(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnExtendedData(e.Message.Data, e.Message.DataTypeCode); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelEof(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnEof(); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelClose(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnClose(); - } - catch (Exception ex) - { - OnChannelException(ex); - } - - var channelClosedWaitHandle = _channelClosedWaitHandle; - if (channelClosedWaitHandle != null) - channelClosedWaitHandle.Set(); - } - } - - private void OnChannelRequest(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - if (_session.ConnectionInfo.ChannelRequests.ContainsKey(e.Message.RequestName)) - { - // Get request specific class - var requestInfo = _session.ConnectionInfo.ChannelRequests[e.Message.RequestName]; - - // Load request specific data - requestInfo.Load(e.Message.RequestData); - - // Raise request specific event - OnRequest(requestInfo); - } - else - { - // TODO: we should also send a SSH_MSG_CHANNEL_FAILURE message - throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Request '{0}' is not supported.", e.Message.RequestName)); - } - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelSuccess(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnSuccess(); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelFailure(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnFailure(); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - #endregion // Channel message event handlers - - private void AdjustDataWindow(byte[] messageData) - { - LocalWindowSize -= (uint)messageData.Length; - - // Adjust window if window size is too low - if (LocalWindowSize < LocalPacketSize) - { - SendMessage(new ChannelWindowAdjustMessage(RemoteChannelNumber, _initialWindowSize - LocalWindowSize)); - LocalWindowSize = _initialWindowSize; - } - } - - /// - /// Determines the length of data that currently can be sent in a single message. - /// - /// The length of the message that must be sent. - /// - /// The actual data length that currently can be sent. - /// - private int GetDataLengthThatCanBeSentInMessage(int messageLength) - { - do - { - lock (_serverWindowSizeLock) - { - var serverWindowSize = RemoteWindowSize; - if (serverWindowSize == 0) - { - // allow us to be signal when remote window size is adjusted - _channelServerWindowAdjustWaitHandle.Reset(); - } - else - { - var bytesThatCanBeSent = Math.Min(Math.Min(RemotePacketSize, (uint) messageLength), - serverWindowSize); - RemoteWindowSize -= bytesThatCanBeSent; - return (int) bytesThatCanBeSent; - } - } - // wait for remote window size to change - WaitOnHandle(_channelServerWindowAdjustWaitHandle); - } while (true); - } - - private InvalidOperationException CreateRemoteChannelInfoNotAvailableException() - { - throw new InvalidOperationException("The channel has not been opened, or the open has not yet been confirmed."); - } - - private InvalidOperationException CreateChannelClosedException() - { - throw new InvalidOperationException("The channel is closed."); - } - - #region IDisposable Members - - private bool _isDisposed; - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases unmanaged and - optionally - managed resources - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool disposing) - { - if (_isDisposed) - return; - - if (disposing) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.Dipose(bool)"); -#endif // DEBUG_GERT - - Close(false); - - var session = _session; - if (session != null) - { - session.ChannelWindowAdjustReceived -= OnChannelWindowAdjust; - session.ChannelDataReceived -= OnChannelData; - session.ChannelExtendedDataReceived -= OnChannelExtendedData; - session.ChannelEofReceived -= OnChannelEof; - session.ChannelCloseReceived -= OnChannelClose; - session.ChannelRequestReceived -= OnChannelRequest; - session.ChannelSuccessReceived -= OnChannelSuccess; - session.ChannelFailureReceived -= OnChannelFailure; - session.ErrorOccured -= Session_ErrorOccured; - session.Disconnected -= Session_Disconnected; - _session = null; - } - - var channelClosedWaitHandle = _channelClosedWaitHandle; - if (channelClosedWaitHandle != null) - { - channelClosedWaitHandle.Dispose(); - _channelClosedWaitHandle = null; - } - - var channelServerWindowAdjustWaitHandle = _channelServerWindowAdjustWaitHandle; - if (channelServerWindowAdjustWaitHandle != null) - { - channelServerWindowAdjustWaitHandle.Dispose(); - _channelServerWindowAdjustWaitHandle = null; - } - - var errorOccuredWaitHandle = _errorOccuredWaitHandle; - if (errorOccuredWaitHandle != null) - { - errorOccuredWaitHandle.Dispose(); - _errorOccuredWaitHandle = null; - } - - _isDisposed = true; - } - } - - /// - /// Releases unmanaged resources and performs other cleanup operations before the - /// is reclaimed by garbage collection. - /// - ~Channel() - { - Dispose(false); - } - - #endregion // IDisposable Members - } -} +using System; +using System.Net.Sockets; +using System.Threading; +using Renci.SshNet.Common; +using Renci.SshNet.Messages; +using Renci.SshNet.Messages.Connection; +using System.Globalization; + +namespace Renci.SshNet.Channels +{ + /// + /// Represents base class for SSH channel implementations. + /// + internal abstract class Channel : IChannel + { + private const int Initial = 0; + private const int Considered = 1; + private const int Sent = 2; + + private EventWaitHandle _channelClosedWaitHandle = new ManualResetEvent(false); + private EventWaitHandle _channelServerWindowAdjustWaitHandle = new ManualResetEvent(false); + private EventWaitHandle _errorOccuredWaitHandle = new ManualResetEvent(false); + private readonly object _serverWindowSizeLock = new object(); + private readonly uint _initialWindowSize; + private uint? _remoteWindowSize; + private uint? _remoteChannelNumber; + private uint? _remotePacketSize; + private ISession _session; + + /// + /// Holds a value indicating whether the SSH_MSG_CHANNEL_CLOSE has been sent to the remote party. + /// + /// + /// 0 when the SSH_MSG_CHANNEL_CLOSE message has not been sent or considered + /// 1 when sending a SSH_MSG_CHANNEL_CLOSE message to the remote party is under consideration + /// 2 when this message has been sent to the remote party + /// + private int _closeMessageSent; + + /// + /// Holds a value indicating whether a SSH_MSG_CHANNEL_CLOSE has been received from the other + /// party. + /// + /// + /// true when a SSH_MSG_CHANNEL_CLOSE message has been received from the other party; + /// otherwise, false. + /// + private bool _closeMessageReceived; + + /// + /// Holds a value indicating whether the SSH_MSG_CHANNEL_EOF has been received from the other party. + /// + /// + /// true when a SSH_MSG_CHANNEL_EOF message has been received from the other party; + /// otherwise, false. + /// + private bool _eofMessageReceived; + + /// + /// Holds a value indicating whether the SSH_MSG_CHANNEL_EOF has been sent to the remote party. + /// + /// + /// 0 when the SSH_MSG_CHANNEL_EOF message has not been sent or considered + /// 1 when sending a SSH_MSG_CHANNEL_EOF message to the remote party is under consideration + /// 2 when this message has been sent to the remote party + /// + private int _eofMessageSent; + + /// + /// Occurs when an exception is thrown when processing channel messages. + /// + public event EventHandler Exception; + + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + protected Channel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) + { + _session = session; + _initialWindowSize = localWindowSize; + LocalChannelNumber = localChannelNumber; + LocalPacketSize = localPacketSize; + LocalWindowSize = localWindowSize; + + _session.ChannelWindowAdjustReceived += OnChannelWindowAdjust; + _session.ChannelDataReceived += OnChannelData; + _session.ChannelExtendedDataReceived += OnChannelExtendedData; + _session.ChannelEofReceived += OnChannelEof; + _session.ChannelCloseReceived += OnChannelClose; + _session.ChannelRequestReceived += OnChannelRequest; + _session.ChannelSuccessReceived += OnChannelSuccess; + _session.ChannelFailureReceived += OnChannelFailure; + _session.ErrorOccured += Session_ErrorOccured; + _session.Disconnected += Session_Disconnected; + } + + /// + /// Gets the session. + /// + /// + /// Thhe session. + /// + protected ISession Session + { + get { return _session; } + } + + /// + /// Gets the type of the channel. + /// + /// + /// The type of the channel. + /// + public abstract ChannelTypes ChannelType { get; } + + /// + /// Gets the local channel number. + /// + /// + /// The local channel number. + /// + public uint LocalChannelNumber { get; private set; } + + /// + /// Gets the maximum size of a packet. + /// + /// + /// The maximum size of a packet. + /// + public uint LocalPacketSize { get; private set; } + + /// + /// Gets the size of the local window. + /// + /// + /// The size of the local window. + /// + public uint LocalWindowSize { get; private set; } + + /// + /// Gets the remote channel number. + /// + /// + /// The remote channel number. + /// + public uint RemoteChannelNumber + { + get + { + if (!_remoteChannelNumber.HasValue) + throw CreateRemoteChannelInfoNotAvailableException(); + return _remoteChannelNumber.Value; + } + private set + { + _remoteChannelNumber = value; + } + } + + /// + /// Gets the maximum size of a data packet that we can send using the channel. + /// + /// + /// The maximum size of data that can be sent using a + /// on the current channel. + /// + /// The channel has not been opened, or the open has not yet been confirmed. + public uint RemotePacketSize + { + get + { + if (!_remotePacketSize.HasValue) + throw CreateRemoteChannelInfoNotAvailableException(); + return _remotePacketSize.Value; + } + private set + { + _remotePacketSize = value; + } + } + + /// + /// Gets the window size of the remote server. + /// + /// + /// The size of the server window. + /// + public uint RemoteWindowSize + { + get + { + if (!_remoteWindowSize.HasValue) + throw CreateRemoteChannelInfoNotAvailableException(); + return _remoteWindowSize.Value; + } + private set + { + _remoteWindowSize = value; + } + } + + /// + /// Gets a value indicating whether this channel is open. + /// + /// + /// true if this channel is open; otherwise, false. + /// + public bool IsOpen { get; protected set; } + + #region Message events + + /// + /// Occurs when message received + /// + public event EventHandler DataReceived; + + /// + /// Occurs when message received + /// + public event EventHandler ExtendedDataReceived; + + /// + /// Occurs when message received + /// + public event EventHandler EndOfData; + + /// + /// Occurs when message received + /// + public event EventHandler Closed; + + /// + /// Occurs when message received + /// + public event EventHandler RequestReceived; + + /// + /// Occurs when message received + /// + public event EventHandler RequestSucceeded; + + /// + /// Occurs when message received + /// + public event EventHandler RequestFailed; + + #endregion + + /// + /// Gets a value indicating whether the session is connected. + /// + /// + /// true if the session is connected; otherwise, false. + /// + protected bool IsConnected + { + get { return _session.IsConnected; } + } + + /// + /// Gets the connection info. + /// + /// The connection info. + protected IConnectionInfo ConnectionInfo + { + get { return _session.ConnectionInfo; } + } + + /// + /// Gets the session semaphore to control number of session channels + /// + /// The session semaphore. + protected SemaphoreLight SessionSemaphore + { + get { return _session.SessionSemaphore; } + } + + protected void InitializeRemoteInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) + { + RemoteChannelNumber = remoteChannelNumber; + RemoteWindowSize = remoteWindowSize; + RemotePacketSize = remotePacketSize; + } + + /// + /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. + /// + /// The payload to send. + public void SendData(byte[] data) + { + SendData(data, 0, data.Length); + } + + /// + /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. + /// + /// An array of containing the payload to send. + /// The zero-based offset in at which to begin taking data from. + /// The number of bytes of to send. + /// + /// + /// When the size of the data to send exceeds the maximum packet size or the remote window + /// size does not allow the full data to be sent, then this method will send the data in + /// multiple chunks and will wait for the remote window size to be adjusted when it's zero. + /// + /// + /// This is done to support SSH servers will a small window size that do not agressively + /// increase their window size. We need to take into account that there may be SSH servers + /// that only increase their window size when it has reached zero. + /// + /// + public void SendData(byte[] data, int offset, int size) + { + // send channel messages only while channel is open + if (!IsOpen) + return; + + var totalBytesToSend = size; + while (totalBytesToSend > 0) + { + var sizeOfCurrentMessage = GetDataLengthThatCanBeSentInMessage(totalBytesToSend); + + var channelDataMessage = new ChannelDataMessage( + RemoteChannelNumber, + data, + offset, + sizeOfCurrentMessage); + _session.SendMessage(channelDataMessage); + + totalBytesToSend -= sizeOfCurrentMessage; + offset += sizeOfCurrentMessage; + } + } + + /// + /// Closes the channel. + /// + public void Close() + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.Close"); +#endif // DEBUG_GERT + Close(true); + } + + #region Channel virtual methods + + /// + /// Called when channel window need to be adjust. + /// + /// The bytes to add. + protected virtual void OnWindowAdjust(uint bytesToAdd) + { + lock (_serverWindowSizeLock) + { + RemoteWindowSize += bytesToAdd; + } + _channelServerWindowAdjustWaitHandle.Set(); + } + + /// + /// Called when channel data is received. + /// + /// The data. + protected virtual void OnData(byte[] data) + { + AdjustDataWindow(data); + + var dataReceived = DataReceived; + if (dataReceived != null) + dataReceived(this, new ChannelDataEventArgs(LocalChannelNumber, data)); + } + + /// + /// Called when channel extended data is received. + /// + /// The data. + /// The data type code. + protected virtual void OnExtendedData(byte[] data, uint dataTypeCode) + { + AdjustDataWindow(data); + + var extendedDataReceived = ExtendedDataReceived; + if (extendedDataReceived != null) + extendedDataReceived(this, new ChannelExtendedDataEventArgs(LocalChannelNumber, data, dataTypeCode)); + } + + /// + /// Called when channel has no more data to receive. + /// + protected virtual void OnEof() + { + _eofMessageReceived = true; + + var endOfData = EndOfData; + if (endOfData != null) + endOfData(this, new ChannelEventArgs(LocalChannelNumber)); + } + + /// + /// Called when channel is closed by the server. + /// + protected virtual void OnClose() + { + _closeMessageReceived = true; + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.OnClose()"); +#endif // DEBUG_GERT + + // close the channel + Close(false); + + var closed = Closed; + if (closed != null) + closed(this, new ChannelEventArgs(LocalChannelNumber)); + } + + /// + /// Called when channel request received. + /// + /// Channel request information. + protected virtual void OnRequest(RequestInfo info) + { + var requestReceived = RequestReceived; + if (requestReceived != null) + requestReceived(this, new ChannelRequestEventArgs(info)); + } + + /// + /// Called when channel request was successful + /// + protected virtual void OnSuccess() + { + var requestSuccessed = RequestSucceeded; + if (requestSuccessed != null) + requestSuccessed(this, new ChannelEventArgs(LocalChannelNumber)); + } + + /// + /// Called when channel request failed. + /// + protected virtual void OnFailure() + { + var requestFailed = RequestFailed; + if (requestFailed != null) + requestFailed(this, new ChannelEventArgs(LocalChannelNumber)); + } + + #endregion // Channel virtual methods + + /// + /// Raises event. + /// + /// The exception. + protected void RaiseExceptionEvent(Exception exception) + { + var handlers = Exception; + if (handlers != null) + { + handlers(this, new ExceptionEventArgs(exception)); + } + } + + /// + /// Sends a message to the server. + /// + /// The message to send. + /// + /// true if the message was sent to the server; otherwise, false. + /// + /// The size of the packet exceeds the maximum size defined by the protocol. + /// + /// This methods returns false when the attempt to send the message results in a + /// or a . + /// + private bool TrySendMessage(Message message) + { + return _session.TrySendMessage(message); + } + + /// + /// Sends SSH message to the server. + /// + /// The message. + protected void SendMessage(Message message) + { + // send channel messages only while channel is open + if (!IsOpen) + return; + + _session.SendMessage(message); + } + + /// + /// Sends a SSH_MSG_CHANNEL_EOF message to the remote server. + /// + /// The channel is closed. + public void SendEof() + { + if (!IsOpen) + throw CreateChannelClosedException(); + + _session.SendMessage(new ChannelEofMessage(RemoteChannelNumber)); + _eofMessageSent = Sent; + } + + /// + /// Waits for the handle to be signaled or for an error to occurs. + /// + /// The wait handle. + protected void WaitOnHandle(WaitHandle waitHandle) + { + _session.WaitOnHandle(waitHandle); + } + + /// + /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to + /// be received from the server. + /// + /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. + protected virtual void Close(bool wait) + { + // send EOF message first when channel need to be closed, and the remote party has not already sent + // a SSH_MSG_CHANNEL_EOF or SSH_MSG_CHANNEL_CLOSE message + // + // note that we might have had a race condition here when the remote party sends a SSH_MSG_CHANNEL_CLOSE + // immediately after it has sent a SSH_MSG_CHANNEL_EOF message + // + // in that case, we would risk sending a SSH_MSG_CHANNEL_EOF message after the remote party has + // closed its end of the channel + // + // as a solution for this issue we only send a SSH_MSG_CHANNEL_EOF message if we haven't received a + // SSH_MSG_CHANNEL_EOF or SSH_MSG_CHANNEL_CLOSE message from the remote party + if (Interlocked.CompareExchange(ref _eofMessageSent, Considered, Initial) == Initial) + { + if (!_closeMessageReceived && !_eofMessageReceived && IsOpen && IsConnected) + { + if (TrySendMessage(new ChannelEofMessage(RemoteChannelNumber))) + _eofMessageSent = Sent; + } + } + + // send message to close the channel on the server + if (Interlocked.CompareExchange(ref _closeMessageSent, Considered, Initial) == Initial) + { + // ignore sending close message when client is not connected or the channel is closed + if (IsOpen && IsConnected) + { + if (TrySendMessage(new ChannelCloseMessage(RemoteChannelNumber))) + _closeMessageSent = Sent; + } + } + + // mark the channel closed + IsOpen = false; + + // wait for channel to be closed if we actually sent a close message (either to initiate closing + // the channel, or as response to a SSH_MSG_CHANNEL_CLOSE message sent by the server + if (wait && _closeMessageSent == Sent) + { + try + { + WaitOnHandle(_channelClosedWaitHandle); + } + catch (SshConnectionException) + { + // ignore connection failures as we're closing the channel anyway + } + } + + // reset indicators in case we want to reopen the channel; these are safe to reset + // since the channel is marked closed by now + _eofMessageSent = Initial; + _eofMessageReceived = false; + _closeMessageReceived = false; + _closeMessageSent = Initial; + } + + protected virtual void OnDisconnected() + { + } + + protected virtual void OnErrorOccured(Exception exp) + { + } + + private void Session_Disconnected(object sender, EventArgs e) + { + IsOpen = false; + + try + { + OnDisconnected(); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + + /// + /// Called when an occurs while processing a channel message. + /// + /// The . + /// + /// This method will in turn invoke , and + /// raise the event. + /// + protected void OnChannelException(Exception ex) + { + OnErrorOccured(ex); + RaiseExceptionEvent(ex); + } + + private void Session_ErrorOccured(object sender, ExceptionEventArgs e) + { + try + { + OnErrorOccured(e.Exception); + + var errorOccuredWaitHandle = _errorOccuredWaitHandle; + if (errorOccuredWaitHandle != null) + errorOccuredWaitHandle.Set(); + } + catch (Exception ex) + { + RaiseExceptionEvent(ex); + } + } + + #region Channel message event handlers + + private void OnChannelWindowAdjust(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnWindowAdjust(e.Message.BytesToAdd); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelData(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnData(e.Message.Data); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelExtendedData(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnExtendedData(e.Message.Data, e.Message.DataTypeCode); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelEof(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnEof(); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelClose(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnClose(); + } + catch (Exception ex) + { + OnChannelException(ex); + } + + var channelClosedWaitHandle = _channelClosedWaitHandle; + if (channelClosedWaitHandle != null) + channelClosedWaitHandle.Set(); + } + } + + private void OnChannelRequest(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + if (_session.ConnectionInfo.ChannelRequests.ContainsKey(e.Message.RequestName)) + { + // Get request specific class + var requestInfo = _session.ConnectionInfo.ChannelRequests[e.Message.RequestName]; + + // Load request specific data + requestInfo.Load(e.Message.RequestData); + + // Raise request specific event + OnRequest(requestInfo); + } + else + { + // TODO: we should also send a SSH_MSG_CHANNEL_FAILURE message + throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Request '{0}' is not supported.", e.Message.RequestName)); + } + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelSuccess(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnSuccess(); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelFailure(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnFailure(); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + #endregion // Channel message event handlers + + private void AdjustDataWindow(byte[] messageData) + { + LocalWindowSize -= (uint)messageData.Length; + + // Adjust window if window size is too low + if (LocalWindowSize < LocalPacketSize) + { + SendMessage(new ChannelWindowAdjustMessage(RemoteChannelNumber, _initialWindowSize - LocalWindowSize)); + LocalWindowSize = _initialWindowSize; + } + } + + /// + /// Determines the length of data that currently can be sent in a single message. + /// + /// The length of the message that must be sent. + /// + /// The actual data length that currently can be sent. + /// + private int GetDataLengthThatCanBeSentInMessage(int messageLength) + { + do + { + lock (_serverWindowSizeLock) + { + var serverWindowSize = RemoteWindowSize; + if (serverWindowSize == 0) + { + // allow us to be signal when remote window size is adjusted + _channelServerWindowAdjustWaitHandle.Reset(); + } + else + { + var bytesThatCanBeSent = Math.Min(Math.Min(RemotePacketSize, (uint) messageLength), + serverWindowSize); + RemoteWindowSize -= bytesThatCanBeSent; + return (int) bytesThatCanBeSent; + } + } + // wait for remote window size to change + WaitOnHandle(_channelServerWindowAdjustWaitHandle); + } while (true); + } + + private InvalidOperationException CreateRemoteChannelInfoNotAvailableException() + { + throw new InvalidOperationException("The channel has not been opened, or the open has not yet been confirmed."); + } + + private InvalidOperationException CreateChannelClosedException() + { + throw new InvalidOperationException("The channel is closed."); + } + + #region IDisposable Members + + private bool _isDisposed; + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Releases unmanaged and - optionally - managed resources + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool disposing) + { + if (_isDisposed) + return; + + if (disposing) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.Dipose(bool)"); +#endif // DEBUG_GERT + + Close(false); + + var session = _session; + if (session != null) + { + session.ChannelWindowAdjustReceived -= OnChannelWindowAdjust; + session.ChannelDataReceived -= OnChannelData; + session.ChannelExtendedDataReceived -= OnChannelExtendedData; + session.ChannelEofReceived -= OnChannelEof; + session.ChannelCloseReceived -= OnChannelClose; + session.ChannelRequestReceived -= OnChannelRequest; + session.ChannelSuccessReceived -= OnChannelSuccess; + session.ChannelFailureReceived -= OnChannelFailure; + session.ErrorOccured -= Session_ErrorOccured; + session.Disconnected -= Session_Disconnected; + _session = null; + } + + var channelClosedWaitHandle = _channelClosedWaitHandle; + if (channelClosedWaitHandle != null) + { + channelClosedWaitHandle.Dispose(); + _channelClosedWaitHandle = null; + } + + var channelServerWindowAdjustWaitHandle = _channelServerWindowAdjustWaitHandle; + if (channelServerWindowAdjustWaitHandle != null) + { + channelServerWindowAdjustWaitHandle.Dispose(); + _channelServerWindowAdjustWaitHandle = null; + } + + var errorOccuredWaitHandle = _errorOccuredWaitHandle; + if (errorOccuredWaitHandle != null) + { + errorOccuredWaitHandle.Dispose(); + _errorOccuredWaitHandle = null; + } + + _isDisposed = true; + } + } + + /// + /// Releases unmanaged resources and performs other cleanup operations before the + /// is reclaimed by garbage collection. + /// + ~Channel() + { + Dispose(false); + } + + #endregion // IDisposable Members + } +} diff --git a/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs b/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs index 98a245ee..b5eae832 100644 --- a/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs +++ b/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs @@ -1,345 +1,345 @@ -using System; -using System.Net; -using System.Net.Sockets; -using System.Threading; -using Renci.SshNet.Abstractions; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - /// - /// Implements "direct-tcpip" SSH channel. - /// - internal class ChannelDirectTcpip : ClientChannel, IChannelDirectTcpip - { - private readonly object _socketLock = new object(); - - private EventWaitHandle _channelOpen = new AutoResetEvent(false); - private EventWaitHandle _channelData = new AutoResetEvent(false); - private IForwardedPort _forwardedPort; - private Socket _socket; - - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - public ChannelDirectTcpip(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize) - { - } - - /// - /// Gets the type of the channel. - /// - /// - /// The type of the channel. - /// - public override ChannelTypes ChannelType - { - get { return ChannelTypes.DirectTcpip; } - } - - public void Open(string remoteHost, uint port, IForwardedPort forwardedPort, Socket socket) - { - if (IsOpen) - throw new SshException("Channel is already open."); - if (!IsConnected) - throw new SshException("Session is not connected."); - - _socket = socket; - _forwardedPort = forwardedPort; - _forwardedPort.Closing += ForwardedPort_Closing; - - var ep = (IPEndPoint) socket.RemoteEndPoint; - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage send '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - // open channel - SendMessage(new ChannelOpenMessage(LocalChannelNumber, LocalWindowSize, LocalPacketSize, - new DirectTcpipChannelInfo(remoteHost, port, ep.Address.ToString(), (uint) ep.Port))); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage sent '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - // Wait for channel to open - WaitOnHandle(_channelOpen); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage flagged '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - } - - /// - /// Occurs as the forwarded port is being stopped. - /// - private void ForwardedPort_Closing(object sender, EventArgs eventArgs) - { - // signal to the client that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the client sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) - ShutdownSocket(SocketShutdown.Send); - } - - /// - /// Binds channel to remote host. - /// - public void Bind() - { - // Cannot bind if channel is not open - if (!IsOpen) - return; - - var buffer = new byte[RemotePacketSize]; - - SocketAbstraction.ReadContinuous(_socket, buffer, 0, buffer.Length, SendData); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.Bind (after) '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - // even though the client has disconnected, we still want to properly close the - // channel - // - // we'll do this in in Close(bool) that way we have a single place from which we - // send an SSH_MSG_CHANNEL_EOF message and wait for the SSH_MSG_CHANNEL_CLOSE - // message - } - - /// - /// Closes the socket, hereby interrupting the blocking receive in . - /// - private void CloseSocket() - { - if (_socket == null) - return; - - lock (_socketLock) - { - if (_socket == null) - return; - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.CloseSocket '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - // closing a socket actually disposes the socket, so we can safely dereference - // the field to avoid entering the lock again later - _socket.Dispose(); - _socket = null; - } - } - - /// - /// Shuts down the socket. - /// - /// One of the values that specifies the operation that will no longer be allowed. - private void ShutdownSocket(SocketShutdown how) - { - if (_socket == null) - return; - - lock (_socketLock) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.ShutdownSocket '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - if (_socket == null || !_socket.Connected) - return; - - _socket.Shutdown(how); - } - } - - /// - /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to - /// be received from the server. - /// - /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. - protected override void Close(bool wait) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.Close(bool) '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - var forwardedPort = _forwardedPort; - if (forwardedPort != null) - { - forwardedPort.Closing -= ForwardedPort_Closing; - _forwardedPort = null; - } - - // signal to the client that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the client sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed after the channel is closed - ShutdownSocket(SocketShutdown.Send); - - // close the SSH channel, and mark the channel closed - base.Close(wait); - - // close the socket - CloseSocket(); - } - - /// - /// Called when channel data is received. - /// - /// The data. - protected override void OnData(byte[] data) - { - base.OnData(data); - - if (_socket != null && _socket.Connected) - { - lock (_socketLock) - { - if (_socket != null && _socket.Connected) - { - SocketAbstraction.Send(_socket, data, 0, data.Length); - } - } - } - } - - /// - /// Called when channel is opened by the server. - /// - /// The remote channel number. - /// Initial size of the window. - /// Maximum size of the packet. - protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) - { - base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize); - - _channelOpen.Set(); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage confirmed '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - } - - protected override void OnOpenFailure(uint reasonCode, string description, string language) - { - base.OnOpenFailure(reasonCode, description, language); - - _channelOpen.Set(); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage failure '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - } - - /// - /// Called when channel has no more data to receive. - /// - protected override void OnEof() - { - base.OnEof(); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnEof '" + LocalChannelNumber + "' | " + - DateTime.Now.ToString("hh:mm:ss")); -#endif // DEBUG_GERT - - // the channel will send no more data, and hence it does not make sense to receive - // any more data from the client to send to the remote party (and we surely won't - // send anything anymore) - // - // this will also interrupt the blocking receive in Bind() - ShutdownSocket(SocketShutdown.Send); - } - - /// - /// Called whenever an unhandled occurs in causing - /// the message loop to be interrupted, or when an exception occurred processing a channel message. - /// - protected override void OnErrorOccured(Exception exp) - { - base.OnErrorOccured(exp); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnErrorOccured '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); -#endif // DEBUG_GERT - - // signal to the client that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the client sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) - ShutdownSocket(SocketShutdown.Send); - } - - /// - /// Called when the server wants to terminate the connection immmediately. - /// - /// - /// The sender MUST NOT send or receive any data after this message, and - /// the recipient MUST NOT accept any data after receiving this message. - /// - protected override void OnDisconnected() - { - base.OnDisconnected(); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnDisconnected '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); -#endif // DEBUG_GERT - - // the channel will accept or send no more data, and hence it does not make sense - // to accept any more data from the client (and we surely won't send anything - // anymore) - // - // - // so lets signal to the client that we will not send or receive anything anymore - // this will also interrupt the blocking receive in Bind() - ShutdownSocket(SocketShutdown.Both); - } - - protected override void Dispose(bool disposing) - { - // make sure we've unsubscribed from all session events and closed the channel - // before we starting disposing - base.Dispose(disposing); - - if (disposing) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Dispose '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); -#endif // DEBUG_GERT - - if (_socket != null) - { - lock (_socketLock) - { - if (_socket != null) - { - _socket.Dispose(); - _socket = null; - } - } - } - - var channelOpen = _channelOpen; - if (channelOpen != null) - { - channelOpen.Dispose(); - _channelOpen = null; - } - - var channelData = _channelData; - if (channelData != null) - { - channelData.Dispose(); - _channelData = null; - } - } - } - } -} +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using Renci.SshNet.Abstractions; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + /// + /// Implements "direct-tcpip" SSH channel. + /// + internal class ChannelDirectTcpip : ClientChannel, IChannelDirectTcpip + { + private readonly object _socketLock = new object(); + + private EventWaitHandle _channelOpen = new AutoResetEvent(false); + private EventWaitHandle _channelData = new AutoResetEvent(false); + private IForwardedPort _forwardedPort; + private Socket _socket; + + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + public ChannelDirectTcpip(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize) + { + } + + /// + /// Gets the type of the channel. + /// + /// + /// The type of the channel. + /// + public override ChannelTypes ChannelType + { + get { return ChannelTypes.DirectTcpip; } + } + + public void Open(string remoteHost, uint port, IForwardedPort forwardedPort, Socket socket) + { + if (IsOpen) + throw new SshException("Channel is already open."); + if (!IsConnected) + throw new SshException("Session is not connected."); + + _socket = socket; + _forwardedPort = forwardedPort; + _forwardedPort.Closing += ForwardedPort_Closing; + + var ep = (IPEndPoint) socket.RemoteEndPoint; + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage send '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + // open channel + SendMessage(new ChannelOpenMessage(LocalChannelNumber, LocalWindowSize, LocalPacketSize, + new DirectTcpipChannelInfo(remoteHost, port, ep.Address.ToString(), (uint) ep.Port))); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage sent '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + // Wait for channel to open + WaitOnHandle(_channelOpen); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage flagged '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + } + + /// + /// Occurs as the forwarded port is being stopped. + /// + private void ForwardedPort_Closing(object sender, EventArgs eventArgs) + { + // signal to the client that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the client sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) + ShutdownSocket(SocketShutdown.Send); + } + + /// + /// Binds channel to remote host. + /// + public void Bind() + { + // Cannot bind if channel is not open + if (!IsOpen) + return; + + var buffer = new byte[RemotePacketSize]; + + SocketAbstraction.ReadContinuous(_socket, buffer, 0, buffer.Length, SendData); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.Bind (after) '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + // even though the client has disconnected, we still want to properly close the + // channel + // + // we'll do this in in Close(bool) that way we have a single place from which we + // send an SSH_MSG_CHANNEL_EOF message and wait for the SSH_MSG_CHANNEL_CLOSE + // message + } + + /// + /// Closes the socket, hereby interrupting the blocking receive in . + /// + private void CloseSocket() + { + if (_socket == null) + return; + + lock (_socketLock) + { + if (_socket == null) + return; + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.CloseSocket '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + // closing a socket actually disposes the socket, so we can safely dereference + // the field to avoid entering the lock again later + _socket.Dispose(); + _socket = null; + } + } + + /// + /// Shuts down the socket. + /// + /// One of the values that specifies the operation that will no longer be allowed. + private void ShutdownSocket(SocketShutdown how) + { + if (_socket == null) + return; + + lock (_socketLock) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.ShutdownSocket '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + if (_socket == null || !_socket.Connected) + return; + + _socket.Shutdown(how); + } + } + + /// + /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to + /// be received from the server. + /// + /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. + protected override void Close(bool wait) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.Close(bool) '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + var forwardedPort = _forwardedPort; + if (forwardedPort != null) + { + forwardedPort.Closing -= ForwardedPort_Closing; + _forwardedPort = null; + } + + // signal to the client that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the client sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed after the channel is closed + ShutdownSocket(SocketShutdown.Send); + + // close the SSH channel, and mark the channel closed + base.Close(wait); + + // close the socket + CloseSocket(); + } + + /// + /// Called when channel data is received. + /// + /// The data. + protected override void OnData(byte[] data) + { + base.OnData(data); + + if (_socket != null && _socket.Connected) + { + lock (_socketLock) + { + if (_socket != null && _socket.Connected) + { + SocketAbstraction.Send(_socket, data, 0, data.Length); + } + } + } + } + + /// + /// Called when channel is opened by the server. + /// + /// The remote channel number. + /// Initial size of the window. + /// Maximum size of the packet. + protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) + { + base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize); + + _channelOpen.Set(); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage confirmed '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + } + + protected override void OnOpenFailure(uint reasonCode, string description, string language) + { + base.OnOpenFailure(reasonCode, description, language); + + _channelOpen.Set(); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage failure '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + } + + /// + /// Called when channel has no more data to receive. + /// + protected override void OnEof() + { + base.OnEof(); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnEof '" + LocalChannelNumber + "' | " + + DateTime.Now.ToString("hh:mm:ss")); +#endif // DEBUG_GERT + + // the channel will send no more data, and hence it does not make sense to receive + // any more data from the client to send to the remote party (and we surely won't + // send anything anymore) + // + // this will also interrupt the blocking receive in Bind() + ShutdownSocket(SocketShutdown.Send); + } + + /// + /// Called whenever an unhandled occurs in causing + /// the message loop to be interrupted, or when an exception occurred processing a channel message. + /// + protected override void OnErrorOccured(Exception exp) + { + base.OnErrorOccured(exp); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnErrorOccured '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); +#endif // DEBUG_GERT + + // signal to the client that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the client sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) + ShutdownSocket(SocketShutdown.Send); + } + + /// + /// Called when the server wants to terminate the connection immmediately. + /// + /// + /// The sender MUST NOT send or receive any data after this message, and + /// the recipient MUST NOT accept any data after receiving this message. + /// + protected override void OnDisconnected() + { + base.OnDisconnected(); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnDisconnected '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); +#endif // DEBUG_GERT + + // the channel will accept or send no more data, and hence it does not make sense + // to accept any more data from the client (and we surely won't send anything + // anymore) + // + // + // so lets signal to the client that we will not send or receive anything anymore + // this will also interrupt the blocking receive in Bind() + ShutdownSocket(SocketShutdown.Both); + } + + protected override void Dispose(bool disposing) + { + // make sure we've unsubscribed from all session events and closed the channel + // before we starting disposing + base.Dispose(disposing); + + if (disposing) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Dispose '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); +#endif // DEBUG_GERT + + if (_socket != null) + { + lock (_socketLock) + { + if (_socket != null) + { + _socket.Dispose(); + _socket = null; + } + } + } + + var channelOpen = _channelOpen; + if (channelOpen != null) + { + channelOpen.Dispose(); + _channelOpen = null; + } + + var channelData = _channelData; + if (channelData != null) + { + channelData.Dispose(); + _channelData = null; + } + } + } + } +} diff --git a/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs b/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs index fac2a90d..ff76166e 100644 --- a/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs +++ b/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs @@ -1,212 +1,212 @@ -using System; -using System.Net; -using System.Net.Sockets; -using System.Threading; -using Renci.SshNet.Abstractions; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - /// - /// Implements "forwarded-tcpip" SSH channel. - /// - internal class ChannelForwardedTcpip : ServerChannel, IChannelForwardedTcpip - { - private readonly object _socketShutdownAndCloseLock = new object(); - private Socket _socket; - private IForwardedPort _forwardedPort; - - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - /// The remote channel number. - /// The window size of the remote party. - /// The maximum size of a data packet that we can send to the remote party. - internal ChannelForwardedTcpip(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize, uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize, remoteChannelNumber, remoteWindowSize, remotePacketSize) - { - } - - /// - /// Gets the type of the channel. - /// - /// - /// The type of the channel. - /// - public override ChannelTypes ChannelType - { - get { return ChannelTypes.ForwardedTcpip; } - } - - /// - /// Binds the channel to the specified endpoint. - /// - /// The endpoint to connect to. - /// The forwarded port for which the channel is opened. - public void Bind(IPEndPoint remoteEndpoint, IForwardedPort forwardedPort) - { - if (!IsConnected) - { - throw new SshException("Session is not connected."); - } - - _forwardedPort = forwardedPort; - _forwardedPort.Closing += ForwardedPort_Closing; - - // Try to connect to the socket - try - { - _socket = SocketAbstraction.Connect(remoteEndpoint, ConnectionInfo.Timeout); - - // send channel open confirmation message - SendMessage(new ChannelOpenConfirmationMessage(RemoteChannelNumber, LocalWindowSize, LocalPacketSize, LocalChannelNumber)); - } - catch (Exception exp) - { - // send channel open failure message - SendMessage(new ChannelOpenFailureMessage(RemoteChannelNumber, exp.ToString(), ChannelOpenFailureMessage.ConnectFailed, "en")); - - throw; - } - - var buffer = new byte[RemotePacketSize]; - - SocketAbstraction.ReadContinuous(_socket, buffer, 0, buffer.Length, SendData); - } - - protected override void OnErrorOccured(Exception exp) - { - base.OnErrorOccured(exp); - - // signal to the server that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the server sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) - ShutdownSocket(SocketShutdown.Send); - } - - /// - /// Occurs as the forwarded port is being stopped. - /// - private void ForwardedPort_Closing(object sender, EventArgs eventArgs) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.ForwardedPort_Closing"); -#endif // DEBUG_GERT - - // signal to the server that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the server sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) - ShutdownSocket(SocketShutdown.Send); - } - - /// - /// Shuts down the socket. - /// - /// One of the values that specifies the operation that will no longer be allowed. - private void ShutdownSocket(SocketShutdown how) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.ShutdownSocket"); -#endif // DEBUG_GERT - - if (_socket == null || !_socket.Connected) - return; - - lock (_socketShutdownAndCloseLock) - { - var socket = _socket; - if (socket == null || !socket.Connected) - return; - - socket.Shutdown(how); - } - } - - /// - /// Closes the socket, hereby interrupting the blocking receive in . - /// - private void CloseSocket() - { - if (_socket == null) - return; - - lock (_socketShutdownAndCloseLock) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.CloseSocket"); -#endif // DEBUG_GERT - - var socket = _socket; - if (socket != null) - { - // closing a socket actually disposes the socket, so we can safely dereference - // the field to avoid entering the lock again later - socket.Dispose(); - _socket = null; - } - } - } - - /// - /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to - /// be received from the server. - /// - /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. - protected override void Close(bool wait) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.Close"); -#endif // DEBUG_GERT - - var forwardedPort = _forwardedPort; - if (forwardedPort != null) - { - forwardedPort.Closing -= ForwardedPort_Closing; - _forwardedPort = null; - } - - // signal to the server that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the server sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed after the channel is closed - ShutdownSocket(SocketShutdown.Send); - - // close the SSH channel, and mark the channel closed - base.Close(wait); - - // close the socket - CloseSocket(); - } - -#if DEBUG_GERT - protected override void OnClose() - { - base.OnClose(); - - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | OnClose"); - } -#endif // DEBUG_GERT - - /// - /// Called when channel data is received. - /// - /// The data. - protected override void OnData(byte[] data) - { - base.OnData(data); - - var socket = _socket; - if (socket != null && socket.Connected) - { - SocketAbstraction.Send(socket, data, 0, data.Length); - } - } - } -} +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using Renci.SshNet.Abstractions; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + /// + /// Implements "forwarded-tcpip" SSH channel. + /// + internal class ChannelForwardedTcpip : ServerChannel, IChannelForwardedTcpip + { + private readonly object _socketShutdownAndCloseLock = new object(); + private Socket _socket; + private IForwardedPort _forwardedPort; + + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + /// The remote channel number. + /// The window size of the remote party. + /// The maximum size of a data packet that we can send to the remote party. + internal ChannelForwardedTcpip(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize, uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize, remoteChannelNumber, remoteWindowSize, remotePacketSize) + { + } + + /// + /// Gets the type of the channel. + /// + /// + /// The type of the channel. + /// + public override ChannelTypes ChannelType + { + get { return ChannelTypes.ForwardedTcpip; } + } + + /// + /// Binds the channel to the specified endpoint. + /// + /// The endpoint to connect to. + /// The forwarded port for which the channel is opened. + public void Bind(IPEndPoint remoteEndpoint, IForwardedPort forwardedPort) + { + if (!IsConnected) + { + throw new SshException("Session is not connected."); + } + + _forwardedPort = forwardedPort; + _forwardedPort.Closing += ForwardedPort_Closing; + + // Try to connect to the socket + try + { + _socket = SocketAbstraction.Connect(remoteEndpoint, ConnectionInfo.Timeout); + + // send channel open confirmation message + SendMessage(new ChannelOpenConfirmationMessage(RemoteChannelNumber, LocalWindowSize, LocalPacketSize, LocalChannelNumber)); + } + catch (Exception exp) + { + // send channel open failure message + SendMessage(new ChannelOpenFailureMessage(RemoteChannelNumber, exp.ToString(), ChannelOpenFailureMessage.ConnectFailed, "en")); + + throw; + } + + var buffer = new byte[RemotePacketSize]; + + SocketAbstraction.ReadContinuous(_socket, buffer, 0, buffer.Length, SendData); + } + + protected override void OnErrorOccured(Exception exp) + { + base.OnErrorOccured(exp); + + // signal to the server that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the server sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) + ShutdownSocket(SocketShutdown.Send); + } + + /// + /// Occurs as the forwarded port is being stopped. + /// + private void ForwardedPort_Closing(object sender, EventArgs eventArgs) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.ForwardedPort_Closing"); +#endif // DEBUG_GERT + + // signal to the server that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the server sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) + ShutdownSocket(SocketShutdown.Send); + } + + /// + /// Shuts down the socket. + /// + /// One of the values that specifies the operation that will no longer be allowed. + private void ShutdownSocket(SocketShutdown how) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.ShutdownSocket"); +#endif // DEBUG_GERT + + if (_socket == null || !_socket.Connected) + return; + + lock (_socketShutdownAndCloseLock) + { + var socket = _socket; + if (socket == null || !socket.Connected) + return; + + socket.Shutdown(how); + } + } + + /// + /// Closes the socket, hereby interrupting the blocking receive in . + /// + private void CloseSocket() + { + if (_socket == null) + return; + + lock (_socketShutdownAndCloseLock) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.CloseSocket"); +#endif // DEBUG_GERT + + var socket = _socket; + if (socket != null) + { + // closing a socket actually disposes the socket, so we can safely dereference + // the field to avoid entering the lock again later + socket.Dispose(); + _socket = null; + } + } + } + + /// + /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to + /// be received from the server. + /// + /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. + protected override void Close(bool wait) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.Close"); +#endif // DEBUG_GERT + + var forwardedPort = _forwardedPort; + if (forwardedPort != null) + { + forwardedPort.Closing -= ForwardedPort_Closing; + _forwardedPort = null; + } + + // signal to the server that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the server sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed after the channel is closed + ShutdownSocket(SocketShutdown.Send); + + // close the SSH channel, and mark the channel closed + base.Close(wait); + + // close the socket + CloseSocket(); + } + +#if DEBUG_GERT + protected override void OnClose() + { + base.OnClose(); + + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | OnClose"); + } +#endif // DEBUG_GERT + + /// + /// Called when channel data is received. + /// + /// The data. + protected override void OnData(byte[] data) + { + base.OnData(data); + + var socket = _socket; + if (socket != null && socket.Connected) + { + SocketAbstraction.Send(socket, data, 0, data.Length); + } + } + } +} diff --git a/src/Renci.SshNet/Channels/ChannelSession.cs b/src/Renci.SshNet/Channels/ChannelSession.cs index c268c2ad..580cbb4d 100644 --- a/src/Renci.SshNet/Channels/ChannelSession.cs +++ b/src/Renci.SshNet/Channels/ChannelSession.cs @@ -1,429 +1,429 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Threading; -using Renci.SshNet.Abstractions; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - /// - /// Implements Session SSH channel. - /// - internal class ChannelSession : ClientChannel, IChannelSession - { - /// - /// Counts failed channel open attempts - /// - private int _failedOpenAttempts; - - /// - /// Holds a value indicating whether the session semaphore has been obtained by the current - /// channel. - /// - /// - /// 0 when the session semaphore has not been obtained or has already been released, - /// and 1 when the session has been obtained and still needs to be released. - /// - private int _sessionSemaphoreObtained; - - /// - /// Wait handle to signal when response was received to open the channel - /// - private EventWaitHandle _channelOpenResponseWaitHandle = new AutoResetEvent(false); - - private EventWaitHandle _channelRequestResponse = new ManualResetEvent(false); - - private bool _channelRequestSucces; - - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - public ChannelSession(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize) - { - } - - /// - /// Gets the type of the channel. - /// - /// - /// The type of the channel. - /// - public override ChannelTypes ChannelType - { - get { return ChannelTypes.Session; } - } - - /// - /// Opens the channel. - /// - public virtual void Open() - { - if (!IsOpen) - { - // Try to open channel several times - while (!IsOpen && _failedOpenAttempts < ConnectionInfo.RetryAttempts) - { - SendChannelOpenMessage(); - try - { - WaitOnHandle(_channelOpenResponseWaitHandle); - } - catch (Exception) - { - // avoid leaking session semaphore - ReleaseSemaphore(); - throw; - } - } - - if (!IsOpen) - throw new SshException(string.Format(CultureInfo.CurrentCulture, "Failed to open a channel after {0} attempts.", _failedOpenAttempts)); - } - } - - /// - /// Called when channel is opened by the server. - /// - /// The remote channel number. - /// Initial size of the window. - /// Maximum size of the packet. - protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) - { - base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize); - _channelOpenResponseWaitHandle.Set(); - } - - /// - /// Called when channel failed to open. - /// - /// The reason code. - /// The description. - /// The language. - protected override void OnOpenFailure(uint reasonCode, string description, string language) - { - _failedOpenAttempts++; - ReleaseSemaphore(); - _channelOpenResponseWaitHandle.Set(); - } - - /// - /// Called when channel is closed by the server. - /// - protected override void OnClose() - { - base.OnClose(); - - // This timeout needed since when channel is closed it does not immediately becomes available - // but it takes time for the server to clean up resource and allow new channels to be created. - ThreadAbstraction.Sleep(100); - } - - protected override void Close(bool wait) - { - base.Close(wait); - - ReleaseSemaphore(); - } - - /// - /// Sends the pseudo terminal request. - /// - /// The environment variable. - /// The columns. - /// The rows. - /// The width. - /// The height. - /// The terminal mode values. - /// - /// true if request was successful; otherwise false. - /// - public bool SendPseudoTerminalRequest(string environmentVariable, uint columns, uint rows, uint width, uint height, IDictionary terminalModeValues) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new PseudoTerminalRequestInfo(environmentVariable, columns, rows, width, height, terminalModeValues))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the X11 forwarding request. - /// - /// if set to true the it is single connection. - /// The protocol. - /// The cookie. - /// The screen number. - /// - /// true if request was successful; otherwise false. - /// - public bool SendX11ForwardingRequest(bool isSingleConnection, string protocol, byte[] cookie, uint screenNumber) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new X11ForwardingRequestInfo(isSingleConnection, protocol, cookie, screenNumber))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the environment variable request. - /// - /// Name of the variable. - /// The variable value. - /// - /// true if request was successful; otherwise false. - /// - public bool SendEnvironmentVariableRequest(string variableName, string variableValue) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new EnvironmentVariableRequestInfo(variableName, variableValue))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the shell request. - /// - /// - /// true if request was successful; otherwise false. - /// - public bool SendShellRequest() - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ShellRequestInfo())); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the exec request. - /// - /// The command. - /// - /// true if request was successful; otherwise false. - /// - public bool SendExecRequest(string command) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExecRequestInfo(command, ConnectionInfo.Encoding))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the exec request. - /// - /// Length of the break. - /// - /// true if request was successful; otherwise false. - /// - public bool SendBreakRequest(uint breakLength) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new BreakRequestInfo(breakLength))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the subsystem request. - /// - /// The subsystem. - /// - /// true if request was successful; otherwise false. - /// - public bool SendSubsystemRequest(string subsystem) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new SubsystemRequestInfo(subsystem))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the window change request. - /// - /// The columns. - /// The rows. - /// The width. - /// The height. - /// - /// true if request was successful; otherwise false. - /// - public bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height) - { - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new WindowChangeRequestInfo(columns, rows, width, height))); - return true; - } - - /// - /// Sends the local flow request. - /// - /// if set to true [client can do]. - /// - /// true if request was successful; otherwise false. - /// - public bool SendLocalFlowRequest(bool clientCanDo) - { - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new XonXoffRequestInfo(clientCanDo))); - return true; - } - - /// - /// Sends the signal request. - /// - /// Name of the signal. - /// - /// true if request was successful; otherwise false. - /// - public bool SendSignalRequest(string signalName) - { - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new SignalRequestInfo(signalName))); - return true; - } - - /// - /// Sends the exit status request. - /// - /// The exit status. - /// - /// true if request was successful; otherwise false. - /// - public bool SendExitStatusRequest(uint exitStatus) - { - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExitStatusRequestInfo(exitStatus))); - return true; - } - - /// - /// Sends the exit signal request. - /// - /// Name of the signal. - /// if set to true [core dumped]. - /// The error message. - /// The language. - /// - /// true if request was successful; otherwise false. - /// - public bool SendExitSignalRequest(string signalName, bool coreDumped, string errorMessage, string language) - { - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExitSignalRequestInfo(signalName, coreDumped, errorMessage, language))); - return true; - } - - /// - /// Sends eow@openssh.com request. - /// - /// - /// true if request was successful; otherwise false. - /// - public bool SendEndOfWriteRequest() - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new EndOfWriteRequestInfo())); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends keepalive@openssh.com request. - /// - /// - /// true if request was successful; otherwise false. - /// - public bool SendKeepAliveRequest() - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new KeepAliveRequestInfo())); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Called when channel request was successful - /// - protected override void OnSuccess() - { - base.OnSuccess(); - _channelRequestSucces = true; - - var channelRequestResponse = _channelRequestResponse; - if (channelRequestResponse != null) - channelRequestResponse.Set(); - } - - /// - /// Called when channel request failed. - /// - protected override void OnFailure() - { - base.OnFailure(); - _channelRequestSucces = false; - - var channelRequestResponse = _channelRequestResponse; - if (channelRequestResponse != null) - channelRequestResponse.Set(); - } - - /// - /// Sends the channel open message. - /// - protected void SendChannelOpenMessage() - { - // do not allow open to be ChannelOpenMessage to be sent again until we've - // had a response on the previous attempt for the current channel - if (Interlocked.CompareExchange(ref _sessionSemaphoreObtained, 1, 0) == 0) - { - SessionSemaphore.Wait(); - SendMessage( - new ChannelOpenMessage( - LocalChannelNumber, - LocalWindowSize, - LocalPacketSize, - new SessionChannelOpenInfo())); - } - } - - /// - /// Releases unmanaged and - optionally - managed resources - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - - if (disposing) - { - if (_channelOpenResponseWaitHandle != null) - { - _channelOpenResponseWaitHandle.Dispose(); - _channelOpenResponseWaitHandle = null; - } - - if (_channelRequestResponse != null) - { - _channelRequestResponse.Dispose(); - _channelRequestResponse = null; - } - } - } - - /// - /// Releases the session semaphore. - /// - /// - /// When the session semaphore has already been released, or was never obtained by - /// this instance, then this method does nothing. - /// - private void ReleaseSemaphore() - { - if (Interlocked.CompareExchange(ref _sessionSemaphoreObtained, 0, 1) == 1) - SessionSemaphore.Release(); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Threading; +using Renci.SshNet.Abstractions; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + /// + /// Implements Session SSH channel. + /// + internal class ChannelSession : ClientChannel, IChannelSession + { + /// + /// Counts failed channel open attempts + /// + private int _failedOpenAttempts; + + /// + /// Holds a value indicating whether the session semaphore has been obtained by the current + /// channel. + /// + /// + /// 0 when the session semaphore has not been obtained or has already been released, + /// and 1 when the session has been obtained and still needs to be released. + /// + private int _sessionSemaphoreObtained; + + /// + /// Wait handle to signal when response was received to open the channel + /// + private EventWaitHandle _channelOpenResponseWaitHandle = new AutoResetEvent(false); + + private EventWaitHandle _channelRequestResponse = new ManualResetEvent(false); + + private bool _channelRequestSucces; + + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + public ChannelSession(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize) + { + } + + /// + /// Gets the type of the channel. + /// + /// + /// The type of the channel. + /// + public override ChannelTypes ChannelType + { + get { return ChannelTypes.Session; } + } + + /// + /// Opens the channel. + /// + public virtual void Open() + { + if (!IsOpen) + { + // Try to open channel several times + while (!IsOpen && _failedOpenAttempts < ConnectionInfo.RetryAttempts) + { + SendChannelOpenMessage(); + try + { + WaitOnHandle(_channelOpenResponseWaitHandle); + } + catch (Exception) + { + // avoid leaking session semaphore + ReleaseSemaphore(); + throw; + } + } + + if (!IsOpen) + throw new SshException(string.Format(CultureInfo.CurrentCulture, "Failed to open a channel after {0} attempts.", _failedOpenAttempts)); + } + } + + /// + /// Called when channel is opened by the server. + /// + /// The remote channel number. + /// Initial size of the window. + /// Maximum size of the packet. + protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) + { + base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize); + _channelOpenResponseWaitHandle.Set(); + } + + /// + /// Called when channel failed to open. + /// + /// The reason code. + /// The description. + /// The language. + protected override void OnOpenFailure(uint reasonCode, string description, string language) + { + _failedOpenAttempts++; + ReleaseSemaphore(); + _channelOpenResponseWaitHandle.Set(); + } + + /// + /// Called when channel is closed by the server. + /// + protected override void OnClose() + { + base.OnClose(); + + // This timeout needed since when channel is closed it does not immediately becomes available + // but it takes time for the server to clean up resource and allow new channels to be created. + ThreadAbstraction.Sleep(100); + } + + protected override void Close(bool wait) + { + base.Close(wait); + + ReleaseSemaphore(); + } + + /// + /// Sends the pseudo terminal request. + /// + /// The environment variable. + /// The columns. + /// The rows. + /// The width. + /// The height. + /// The terminal mode values. + /// + /// true if request was successful; otherwise false. + /// + public bool SendPseudoTerminalRequest(string environmentVariable, uint columns, uint rows, uint width, uint height, IDictionary terminalModeValues) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new PseudoTerminalRequestInfo(environmentVariable, columns, rows, width, height, terminalModeValues))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the X11 forwarding request. + /// + /// if set to true the it is single connection. + /// The protocol. + /// The cookie. + /// The screen number. + /// + /// true if request was successful; otherwise false. + /// + public bool SendX11ForwardingRequest(bool isSingleConnection, string protocol, byte[] cookie, uint screenNumber) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new X11ForwardingRequestInfo(isSingleConnection, protocol, cookie, screenNumber))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the environment variable request. + /// + /// Name of the variable. + /// The variable value. + /// + /// true if request was successful; otherwise false. + /// + public bool SendEnvironmentVariableRequest(string variableName, string variableValue) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new EnvironmentVariableRequestInfo(variableName, variableValue))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the shell request. + /// + /// + /// true if request was successful; otherwise false. + /// + public bool SendShellRequest() + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ShellRequestInfo())); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the exec request. + /// + /// The command. + /// + /// true if request was successful; otherwise false. + /// + public bool SendExecRequest(string command) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExecRequestInfo(command, ConnectionInfo.Encoding))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the exec request. + /// + /// Length of the break. + /// + /// true if request was successful; otherwise false. + /// + public bool SendBreakRequest(uint breakLength) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new BreakRequestInfo(breakLength))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the subsystem request. + /// + /// The subsystem. + /// + /// true if request was successful; otherwise false. + /// + public bool SendSubsystemRequest(string subsystem) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new SubsystemRequestInfo(subsystem))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the window change request. + /// + /// The columns. + /// The rows. + /// The width. + /// The height. + /// + /// true if request was successful; otherwise false. + /// + public bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height) + { + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new WindowChangeRequestInfo(columns, rows, width, height))); + return true; + } + + /// + /// Sends the local flow request. + /// + /// if set to true [client can do]. + /// + /// true if request was successful; otherwise false. + /// + public bool SendLocalFlowRequest(bool clientCanDo) + { + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new XonXoffRequestInfo(clientCanDo))); + return true; + } + + /// + /// Sends the signal request. + /// + /// Name of the signal. + /// + /// true if request was successful; otherwise false. + /// + public bool SendSignalRequest(string signalName) + { + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new SignalRequestInfo(signalName))); + return true; + } + + /// + /// Sends the exit status request. + /// + /// The exit status. + /// + /// true if request was successful; otherwise false. + /// + public bool SendExitStatusRequest(uint exitStatus) + { + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExitStatusRequestInfo(exitStatus))); + return true; + } + + /// + /// Sends the exit signal request. + /// + /// Name of the signal. + /// if set to true [core dumped]. + /// The error message. + /// The language. + /// + /// true if request was successful; otherwise false. + /// + public bool SendExitSignalRequest(string signalName, bool coreDumped, string errorMessage, string language) + { + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExitSignalRequestInfo(signalName, coreDumped, errorMessage, language))); + return true; + } + + /// + /// Sends eow@openssh.com request. + /// + /// + /// true if request was successful; otherwise false. + /// + public bool SendEndOfWriteRequest() + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new EndOfWriteRequestInfo())); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends keepalive@openssh.com request. + /// + /// + /// true if request was successful; otherwise false. + /// + public bool SendKeepAliveRequest() + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new KeepAliveRequestInfo())); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Called when channel request was successful + /// + protected override void OnSuccess() + { + base.OnSuccess(); + _channelRequestSucces = true; + + var channelRequestResponse = _channelRequestResponse; + if (channelRequestResponse != null) + channelRequestResponse.Set(); + } + + /// + /// Called when channel request failed. + /// + protected override void OnFailure() + { + base.OnFailure(); + _channelRequestSucces = false; + + var channelRequestResponse = _channelRequestResponse; + if (channelRequestResponse != null) + channelRequestResponse.Set(); + } + + /// + /// Sends the channel open message. + /// + protected void SendChannelOpenMessage() + { + // do not allow open to be ChannelOpenMessage to be sent again until we've + // had a response on the previous attempt for the current channel + if (Interlocked.CompareExchange(ref _sessionSemaphoreObtained, 1, 0) == 0) + { + SessionSemaphore.Wait(); + SendMessage( + new ChannelOpenMessage( + LocalChannelNumber, + LocalWindowSize, + LocalPacketSize, + new SessionChannelOpenInfo())); + } + } + + /// + /// Releases unmanaged and - optionally - managed resources + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + if (disposing) + { + if (_channelOpenResponseWaitHandle != null) + { + _channelOpenResponseWaitHandle.Dispose(); + _channelOpenResponseWaitHandle = null; + } + + if (_channelRequestResponse != null) + { + _channelRequestResponse.Dispose(); + _channelRequestResponse = null; + } + } + } + + /// + /// Releases the session semaphore. + /// + /// + /// When the session semaphore has already been released, or was never obtained by + /// this instance, then this method does nothing. + /// + private void ReleaseSemaphore() + { + if (Interlocked.CompareExchange(ref _sessionSemaphoreObtained, 0, 1) == 1) + SessionSemaphore.Release(); + } + } +} diff --git a/src/Renci.SshNet/Channels/ChannelTypes.cs b/src/Renci.SshNet/Channels/ChannelTypes.cs index 7b257675..23042023 100644 --- a/src/Renci.SshNet/Channels/ChannelTypes.cs +++ b/src/Renci.SshNet/Channels/ChannelTypes.cs @@ -1,26 +1,26 @@ - -namespace Renci.SshNet.Channels -{ - /// - /// Lists channel types as defined by the protocol. - /// - internal enum ChannelTypes - { - /// - /// session - /// - Session, - /// - /// x11 - /// - X11, - /// - /// forwarded-tcpip - /// - ForwardedTcpip, - /// - /// direct-tcpip - /// - DirectTcpip - } -} + +namespace Renci.SshNet.Channels +{ + /// + /// Lists channel types as defined by the protocol. + /// + internal enum ChannelTypes + { + /// + /// session + /// + Session, + /// + /// x11 + /// + X11, + /// + /// forwarded-tcpip + /// + ForwardedTcpip, + /// + /// direct-tcpip + /// + DirectTcpip + } +} diff --git a/src/Renci.SshNet/Channels/ClientChannel.cs b/src/Renci.SshNet/Channels/ClientChannel.cs index d84c3e98..0d1704ea 100644 --- a/src/Renci.SshNet/Channels/ClientChannel.cs +++ b/src/Renci.SshNet/Channels/ClientChannel.cs @@ -1,127 +1,127 @@ -using System; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - internal abstract class ClientChannel : Channel - { - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - protected ClientChannel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize) - { - session.ChannelOpenConfirmationReceived += OnChannelOpenConfirmation; - session.ChannelOpenFailureReceived += OnChannelOpenFailure; - } - - /// - /// Occurs when message is received. - /// - public event EventHandler OpenConfirmed; - - /// - /// Occurs when message is received. - /// - public event EventHandler OpenFailed; - - /// - /// Called when channel is opened by the server. - /// - /// The remote channel number. - /// Initial size of the window. - /// Maximum size of the packet. - protected virtual void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) - { - InitializeRemoteInfo(remoteChannelNumber, initialWindowSize, maximumPacketSize); - - // Channel is consider to be open when confirmation message was received - IsOpen = true; - - var openConfirmed = OpenConfirmed; - if (openConfirmed != null) - openConfirmed(this, new ChannelOpenConfirmedEventArgs(remoteChannelNumber, initialWindowSize, maximumPacketSize)); - } - - /// - /// Send message to open a channel. - /// - /// Message to send - protected void SendMessage(ChannelOpenMessage message) - { - Session.SendMessage(message); - } - - /// - /// Called when channel failed to open. - /// - /// The reason code. - /// The description. - /// The language. - protected virtual void OnOpenFailure(uint reasonCode, string description, string language) - { - var openFailed = OpenFailed; - if (openFailed != null) - openFailed(this, new ChannelOpenFailedEventArgs(LocalChannelNumber, reasonCode, description, language)); - } - - private void OnChannelOpenConfirmation(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnOpenConfirmation(e.Message.RemoteChannelNumber, e.Message.InitialWindowSize, - e.Message.MaximumPacketSize); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelOpenFailure(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnOpenFailure(e.Message.ReasonCode, e.Message.Description, e.Message.Language); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - protected override void Dispose(bool disposing) - { - UnsubscribeFromSessionEvents(Session); - - base.Dispose(disposing); - } - - /// - /// Unsubscribes the current from session events. - /// - /// The session. - /// - /// Does nothing when is null. - /// - private void UnsubscribeFromSessionEvents(ISession session) - { - if (session == null) - return; - - session.ChannelOpenConfirmationReceived -= OnChannelOpenConfirmation; - session.ChannelOpenFailureReceived -= OnChannelOpenFailure; - } - } -} +using System; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + internal abstract class ClientChannel : Channel + { + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + protected ClientChannel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize) + { + session.ChannelOpenConfirmationReceived += OnChannelOpenConfirmation; + session.ChannelOpenFailureReceived += OnChannelOpenFailure; + } + + /// + /// Occurs when message is received. + /// + public event EventHandler OpenConfirmed; + + /// + /// Occurs when message is received. + /// + public event EventHandler OpenFailed; + + /// + /// Called when channel is opened by the server. + /// + /// The remote channel number. + /// Initial size of the window. + /// Maximum size of the packet. + protected virtual void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) + { + InitializeRemoteInfo(remoteChannelNumber, initialWindowSize, maximumPacketSize); + + // Channel is consider to be open when confirmation message was received + IsOpen = true; + + var openConfirmed = OpenConfirmed; + if (openConfirmed != null) + openConfirmed(this, new ChannelOpenConfirmedEventArgs(remoteChannelNumber, initialWindowSize, maximumPacketSize)); + } + + /// + /// Send message to open a channel. + /// + /// Message to send + protected void SendMessage(ChannelOpenMessage message) + { + Session.SendMessage(message); + } + + /// + /// Called when channel failed to open. + /// + /// The reason code. + /// The description. + /// The language. + protected virtual void OnOpenFailure(uint reasonCode, string description, string language) + { + var openFailed = OpenFailed; + if (openFailed != null) + openFailed(this, new ChannelOpenFailedEventArgs(LocalChannelNumber, reasonCode, description, language)); + } + + private void OnChannelOpenConfirmation(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnOpenConfirmation(e.Message.RemoteChannelNumber, e.Message.InitialWindowSize, + e.Message.MaximumPacketSize); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelOpenFailure(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnOpenFailure(e.Message.ReasonCode, e.Message.Description, e.Message.Language); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + protected override void Dispose(bool disposing) + { + UnsubscribeFromSessionEvents(Session); + + base.Dispose(disposing); + } + + /// + /// Unsubscribes the current from session events. + /// + /// The session. + /// + /// Does nothing when is null. + /// + private void UnsubscribeFromSessionEvents(ISession session) + { + if (session == null) + return; + + session.ChannelOpenConfirmationReceived -= OnChannelOpenConfirmation; + session.ChannelOpenFailureReceived -= OnChannelOpenFailure; + } + } +} diff --git a/src/Renci.SshNet/Channels/IChannel.cs b/src/Renci.SshNet/Channels/IChannel.cs index 49a237a4..0a89066d 100644 --- a/src/Renci.SshNet/Channels/IChannel.cs +++ b/src/Renci.SshNet/Channels/IChannel.cs @@ -1,108 +1,108 @@ -using System; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - /// - /// Represents SSH channel. - /// - internal interface IChannel : IDisposable - { - /// - /// Occurs when message received - /// - event EventHandler DataReceived; - - /// - /// Occurs when an exception is thrown when processing channel messages. - /// - event EventHandler Exception; - - /// - /// Occurs when message received - /// - event EventHandler ExtendedDataReceived; - - /// - /// Occurs when message received - /// - event EventHandler RequestReceived; - - /// - /// Occurs when message received - /// - event EventHandler Closed; - - /// - /// Gets the local channel number. - /// - /// - /// The local channel number. - /// - uint LocalChannelNumber { get; } - - /// - /// Gets the maximum size of a packet. - /// - /// - /// The maximum size of a packet. - /// - uint LocalPacketSize { get; } - - /// - /// Gets the maximum size of a data packet that can be sent using the channel. - /// - /// - /// The maximum size of data that can be sent using a - /// on the current channel. - /// - /// The channel has not been opened, or the open has not yet been confirmed. - uint RemotePacketSize { get; } - - /// - /// Closes the channel. - /// - void Close(); - - /// - /// Gets a value indicating whether this channel is open. - /// - /// - /// true if this channel is open; otherwise, false. - /// - bool IsOpen { get; } - - /// - /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. - /// - /// The payload to send. - void SendData(byte[] data); - - /// - /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. - /// - /// An array of containing the payload to send. - /// The zero-based offset in at which to begin taking data from. - /// The number of bytes of to send. - /// - /// - /// When the size of the data to send exceeds the maximum packet size or the remote window - /// size does not allow the full data to be sent, then this method will send the data in - /// multiple chunks and will wait for the remote window size to be adjusted when it's zero. - /// - /// - /// This is done to support SSH servers will a small window size that do not agressively - /// increase their window size. We need to take into account that there may be SSH servers - /// that only increase their window size when it has reached zero. - /// - /// - void SendData(byte[] data, int offset, int size); - - /// - /// Sends a SSH_MSG_CHANNEL_EOF message to the remote server. - /// - /// The channel is closed. - void SendEof(); - } -} +using System; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + /// + /// Represents SSH channel. + /// + internal interface IChannel : IDisposable + { + /// + /// Occurs when message received + /// + event EventHandler DataReceived; + + /// + /// Occurs when an exception is thrown when processing channel messages. + /// + event EventHandler Exception; + + /// + /// Occurs when message received + /// + event EventHandler ExtendedDataReceived; + + /// + /// Occurs when message received + /// + event EventHandler RequestReceived; + + /// + /// Occurs when message received + /// + event EventHandler Closed; + + /// + /// Gets the local channel number. + /// + /// + /// The local channel number. + /// + uint LocalChannelNumber { get; } + + /// + /// Gets the maximum size of a packet. + /// + /// + /// The maximum size of a packet. + /// + uint LocalPacketSize { get; } + + /// + /// Gets the maximum size of a data packet that can be sent using the channel. + /// + /// + /// The maximum size of data that can be sent using a + /// on the current channel. + /// + /// The channel has not been opened, or the open has not yet been confirmed. + uint RemotePacketSize { get; } + + /// + /// Closes the channel. + /// + void Close(); + + /// + /// Gets a value indicating whether this channel is open. + /// + /// + /// true if this channel is open; otherwise, false. + /// + bool IsOpen { get; } + + /// + /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. + /// + /// The payload to send. + void SendData(byte[] data); + + /// + /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. + /// + /// An array of containing the payload to send. + /// The zero-based offset in at which to begin taking data from. + /// The number of bytes of to send. + /// + /// + /// When the size of the data to send exceeds the maximum packet size or the remote window + /// size does not allow the full data to be sent, then this method will send the data in + /// multiple chunks and will wait for the remote window size to be adjusted when it's zero. + /// + /// + /// This is done to support SSH servers will a small window size that do not agressively + /// increase their window size. We need to take into account that there may be SSH servers + /// that only increase their window size when it has reached zero. + /// + /// + void SendData(byte[] data, int offset, int size); + + /// + /// Sends a SSH_MSG_CHANNEL_EOF message to the remote server. + /// + /// The channel is closed. + void SendEof(); + } +} diff --git a/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs b/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs index 9aff0db6..051fc77c 100644 --- a/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs +++ b/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs @@ -1,52 +1,52 @@ -using System; -using System.Net.Sockets; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Channels -{ - /// - /// A "direct-tcpip" SSH channel. - /// - internal interface IChannelDirectTcpip : IDisposable - { - /// - /// Occurs when an exception is thrown while processing channel messages. - /// - event EventHandler Exception; - - /// - /// Gets a value indicating whether this channel is open. - /// - /// - /// true if this channel is open; otherwise, false. - /// - bool IsOpen { get; } - - /// - /// Gets the local channel number. - /// - /// - /// The local channel number. - /// - uint LocalChannelNumber { get; } - - /// - /// Opens a channel for a locally forwarded TCP/IP port. - /// - /// The name of the remote host to forward to. - /// The port of the remote hosts to forward to. - /// The forwarded port for which the channel is opened. - /// The socket to receive requests from, and send responses from the remote host to. - void Open(string remoteHost, uint port, IForwardedPort forwardedPort, Socket socket); - - /// - /// Binds the channel to the remote host. - /// - void Bind(); - - /// - /// Closes the channel. - /// - void Close(); - } -} +using System; +using System.Net.Sockets; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Channels +{ + /// + /// A "direct-tcpip" SSH channel. + /// + internal interface IChannelDirectTcpip : IDisposable + { + /// + /// Occurs when an exception is thrown while processing channel messages. + /// + event EventHandler Exception; + + /// + /// Gets a value indicating whether this channel is open. + /// + /// + /// true if this channel is open; otherwise, false. + /// + bool IsOpen { get; } + + /// + /// Gets the local channel number. + /// + /// + /// The local channel number. + /// + uint LocalChannelNumber { get; } + + /// + /// Opens a channel for a locally forwarded TCP/IP port. + /// + /// The name of the remote host to forward to. + /// The port of the remote hosts to forward to. + /// The forwarded port for which the channel is opened. + /// The socket to receive requests from, and send responses from the remote host to. + void Open(string remoteHost, uint port, IForwardedPort forwardedPort, Socket socket); + + /// + /// Binds the channel to the remote host. + /// + void Bind(); + + /// + /// Closes the channel. + /// + void Close(); + } +} diff --git a/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs b/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs index 8ebc5b4e..f97fd1a4 100644 --- a/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs +++ b/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs @@ -1,29 +1,29 @@ -using System; -using System.Net; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Channels -{ - /// - /// A "forwarded-tcpip" SSH channel. - /// - internal interface IChannelForwardedTcpip : IDisposable - { - /// - /// Occurs when an exception is thrown while processing channel messages. - /// - event EventHandler Exception; - - /// - /// Binds the channel to the specified endpoint. - /// - /// The endpoint to connect to. - /// The forwarded port for which the channel is opened. - void Bind(IPEndPoint remoteEndpoint, IForwardedPort forwardedPort); - - /// - /// Closes the channel. - /// - void Close(); - } -} +using System; +using System.Net; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Channels +{ + /// + /// A "forwarded-tcpip" SSH channel. + /// + internal interface IChannelForwardedTcpip : IDisposable + { + /// + /// Occurs when an exception is thrown while processing channel messages. + /// + event EventHandler Exception; + + /// + /// Binds the channel to the specified endpoint. + /// + /// The endpoint to connect to. + /// The forwarded port for which the channel is opened. + void Bind(IPEndPoint remoteEndpoint, IForwardedPort forwardedPort); + + /// + /// Closes the channel. + /// + void Close(); + } +} diff --git a/src/Renci.SshNet/Channels/IChannelSession.cs b/src/Renci.SshNet/Channels/IChannelSession.cs index 2b4d7c76..1599ce22 100644 --- a/src/Renci.SshNet/Channels/IChannelSession.cs +++ b/src/Renci.SshNet/Channels/IChannelSession.cs @@ -1,155 +1,155 @@ -using System.Collections.Generic; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Channels -{ - /// - /// Session SSH channel. - /// - internal interface IChannelSession : IChannel - { - /// - /// Opens the channel. - /// - void Open(); - - /// - /// Sends the pseudo terminal request. - /// - /// The environment variable. - /// The columns. - /// The rows. - /// The width. - /// The height. - /// The terminal mode values. - /// - /// true if request was successful; otherwise false. - /// - bool SendPseudoTerminalRequest(string environmentVariable, uint columns, uint rows, uint width, uint height, - IDictionary terminalModeValues); - - /// - /// Sends the X11 forwarding request. - /// - /// if set to true the it is single connection. - /// The protocol. - /// The cookie. - /// The screen number. - /// - /// true if request was successful; otherwise false. - /// - bool SendX11ForwardingRequest(bool isSingleConnection, string protocol, byte[] cookie, uint screenNumber); - - /// - /// Sends the environment variable request. - /// - /// Name of the variable. - /// The variable value. - /// - /// true if request was successful; otherwise false. - /// - bool SendEnvironmentVariableRequest(string variableName, string variableValue); - - /// - /// Sends the shell request. - /// - /// - /// true if request was successful; otherwise false. - /// - bool SendShellRequest(); - - /// - /// Sends the exec request. - /// - /// The command. - /// - /// true if request was successful; otherwise false. - /// - bool SendExecRequest(string command); - - /// - /// Sends the exec request. - /// - /// Length of the break. - /// - /// true if request was successful; otherwise false. - /// - bool SendBreakRequest(uint breakLength); - - /// - /// Sends the subsystem request. - /// - /// The subsystem. - /// - /// true if request was successful; otherwise false. - /// - bool SendSubsystemRequest(string subsystem); - - /// - /// Sends the window change request. - /// - /// The columns. - /// The rows. - /// The width. - /// The height. - /// - /// true if request was successful; otherwise false. - /// - bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height); - - /// - /// Sends the local flow request. - /// - /// if set to true [client can do]. - /// - /// true if request was successful; otherwise false. - /// - bool SendLocalFlowRequest(bool clientCanDo); - - /// - /// Sends the signal request. - /// - /// Name of the signal. - /// - /// true if request was successful; otherwise false. - /// - bool SendSignalRequest(string signalName); - - /// - /// Sends the exit status request. - /// - /// The exit status. - /// - /// true if request was successful; otherwise false. - /// - bool SendExitStatusRequest(uint exitStatus); - - /// - /// Sends the exit signal request. - /// - /// Name of the signal. - /// if set to true [core dumped]. - /// The error message. - /// The language. - /// - /// true if request was successful; otherwise false. - /// - bool SendExitSignalRequest(string signalName, bool coreDumped, string errorMessage, string language); - - /// - /// Sends eow@openssh.com request. - /// - /// - /// true if request was successful; otherwise false. - /// - bool SendEndOfWriteRequest(); - - /// - /// Sends keepalive@openssh.com request. - /// - /// - /// true if request was successful; otherwise false. - /// - bool SendKeepAliveRequest(); - } -} +using System.Collections.Generic; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Channels +{ + /// + /// Session SSH channel. + /// + internal interface IChannelSession : IChannel + { + /// + /// Opens the channel. + /// + void Open(); + + /// + /// Sends the pseudo terminal request. + /// + /// The environment variable. + /// The columns. + /// The rows. + /// The width. + /// The height. + /// The terminal mode values. + /// + /// true if request was successful; otherwise false. + /// + bool SendPseudoTerminalRequest(string environmentVariable, uint columns, uint rows, uint width, uint height, + IDictionary terminalModeValues); + + /// + /// Sends the X11 forwarding request. + /// + /// if set to true the it is single connection. + /// The protocol. + /// The cookie. + /// The screen number. + /// + /// true if request was successful; otherwise false. + /// + bool SendX11ForwardingRequest(bool isSingleConnection, string protocol, byte[] cookie, uint screenNumber); + + /// + /// Sends the environment variable request. + /// + /// Name of the variable. + /// The variable value. + /// + /// true if request was successful; otherwise false. + /// + bool SendEnvironmentVariableRequest(string variableName, string variableValue); + + /// + /// Sends the shell request. + /// + /// + /// true if request was successful; otherwise false. + /// + bool SendShellRequest(); + + /// + /// Sends the exec request. + /// + /// The command. + /// + /// true if request was successful; otherwise false. + /// + bool SendExecRequest(string command); + + /// + /// Sends the exec request. + /// + /// Length of the break. + /// + /// true if request was successful; otherwise false. + /// + bool SendBreakRequest(uint breakLength); + + /// + /// Sends the subsystem request. + /// + /// The subsystem. + /// + /// true if request was successful; otherwise false. + /// + bool SendSubsystemRequest(string subsystem); + + /// + /// Sends the window change request. + /// + /// The columns. + /// The rows. + /// The width. + /// The height. + /// + /// true if request was successful; otherwise false. + /// + bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height); + + /// + /// Sends the local flow request. + /// + /// if set to true [client can do]. + /// + /// true if request was successful; otherwise false. + /// + bool SendLocalFlowRequest(bool clientCanDo); + + /// + /// Sends the signal request. + /// + /// Name of the signal. + /// + /// true if request was successful; otherwise false. + /// + bool SendSignalRequest(string signalName); + + /// + /// Sends the exit status request. + /// + /// The exit status. + /// + /// true if request was successful; otherwise false. + /// + bool SendExitStatusRequest(uint exitStatus); + + /// + /// Sends the exit signal request. + /// + /// Name of the signal. + /// if set to true [core dumped]. + /// The error message. + /// The language. + /// + /// true if request was successful; otherwise false. + /// + bool SendExitSignalRequest(string signalName, bool coreDumped, string errorMessage, string language); + + /// + /// Sends eow@openssh.com request. + /// + /// + /// true if request was successful; otherwise false. + /// + bool SendEndOfWriteRequest(); + + /// + /// Sends keepalive@openssh.com request. + /// + /// + /// true if request was successful; otherwise false. + /// + bool SendKeepAliveRequest(); + } +} diff --git a/src/Renci.SshNet/Channels/ServerChannel.cs b/src/Renci.SshNet/Channels/ServerChannel.cs index 8c55248b..dc5378b3 100644 --- a/src/Renci.SshNet/Channels/ServerChannel.cs +++ b/src/Renci.SshNet/Channels/ServerChannel.cs @@ -1,33 +1,33 @@ -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - internal abstract class ServerChannel : Channel - { - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - /// The remote channel number. - /// The window size of the remote party. - /// The maximum size of a data packet that we can send to the remote party. - protected ServerChannel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize, uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize) - { - InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize); - } - - protected void SendMessage(ChannelOpenConfirmationMessage message) - { - // No need to check whether channel is open when trying to open a channel - Session.SendMessage(message); - - // When we act as server, consider the channel open when we've sent the - // confirmation message to the peer - IsOpen = true; - } - } -} +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + internal abstract class ServerChannel : Channel + { + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + /// The remote channel number. + /// The window size of the remote party. + /// The maximum size of a data packet that we can send to the remote party. + protected ServerChannel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize, uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize) + { + InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize); + } + + protected void SendMessage(ChannelOpenConfirmationMessage message) + { + // No need to check whether channel is open when trying to open a channel + Session.SendMessage(message); + + // When we act as server, consider the channel open when we've sent the + // confirmation message to the peer + IsOpen = true; + } + } +} diff --git a/src/Renci.SshNet/CipherInfo.cs b/src/Renci.SshNet/CipherInfo.cs index 77eafdd2..e68497cd 100644 --- a/src/Renci.SshNet/CipherInfo.cs +++ b/src/Renci.SshNet/CipherInfo.cs @@ -1,35 +1,35 @@ -using System; -using Renci.SshNet.Security.Cryptography; - -namespace Renci.SshNet -{ - /// - /// Holds information about key size and cipher to use - /// - public class CipherInfo - { - /// - /// Gets the size of the key. - /// - /// - /// The size of the key. - /// - public int KeySize { get; private set; } - - /// - /// Gets the cipher. - /// - public Func Cipher { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// Size of the key. - /// The cipher. - public CipherInfo(int keySize, Func cipher) - { - KeySize = keySize; - Cipher = (key, iv) => (cipher(key.Take(KeySize / 8), iv)); - } - } -} +using System; +using Renci.SshNet.Security.Cryptography; + +namespace Renci.SshNet +{ + /// + /// Holds information about key size and cipher to use + /// + public class CipherInfo + { + /// + /// Gets the size of the key. + /// + /// + /// The size of the key. + /// + public int KeySize { get; private set; } + + /// + /// Gets the cipher. + /// + public Func Cipher { get; private set; } + + /// + /// Initializes a new instance of the class. + /// + /// Size of the key. + /// The cipher. + public CipherInfo(int keySize, Func cipher) + { + KeySize = keySize; + Cipher = (key, iv) => (cipher(key.Take(KeySize / 8), iv)); + } + } +}