浏览代码

Merge pull request #88 from sshnet/master

Move back to use develop branch.
Gert Driesen 9 年之前
父节点
当前提交
939325ee64
共有 100 个文件被更改,包括 1356 次插入667 次删除
  1. 2 2
      build/nuget/SSH.NET.nuspec
  2. 6 4
      src/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj
  3. 0 62
      src/Renci.SshNet.NET35/Session.NET35.cs
  4. 7 7
      src/Renci.SshNet.Silverlight5/Renci.SshNet.Silverlight5.csproj
  5. 46 40
      src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj
  6. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs
  7. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
  8. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
  9. 3 3
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_Disposed.cs
  10. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs
  11. 8 4
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs
  12. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs
  13. 8 4
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs
  14. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs
  15. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs
  16. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs
  17. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs
  18. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs
  19. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs
  20. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs
  21. 1 1
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Disposed_Closed.cs
  22. 6 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs
  23. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsNotOpen.cs
  24. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs
  25. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs
  26. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs
  27. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsNotOpen.cs
  28. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsOpen.cs
  29. 2 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs
  30. 11 5
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs
  31. 11 5
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs
  32. 0 31
      src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_ToGlobalRequestName.cs
  33. 208 2
      src/Renci.SshNet.Tests/Classes/Common/SshDataTest.cs
  34. 2 20
      src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs
  35. 0 7
      src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs
  36. 4 10
      src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs
  37. 2 22
      src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs
  38. 2 22
      src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs
  39. 0 7
      src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs
  40. 0 7
      src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs
  41. 0 7
      src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs
  42. 0 1
      src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs
  43. 4 5
      src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs
  44. 0 1
      src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs
  45. 0 7
      src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs
  46. 2 11
      src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs
  47. 4 5
      src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStopped.cs
  48. 4 7
      src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortNeverStarted.cs
  49. 4 7
      src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStarted.cs
  50. 10 13
      src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStopped.cs
  51. 3 8
      src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Started.cs
  52. 4 5
      src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortNeverStarted.cs
  53. 2 2
      src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelDataMessageTest.cs
  54. 5 5
      src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/ChannelOpenMessageTest.cs
  55. 14 18
      src/Renci.SshNet.Tests/Classes/Messages/Connection/GlobalRequestMessageTest.cs
  56. 42 2
      src/Renci.SshNet.Tests/Classes/Messages/Transport/IgnoreMessageTest.cs
  57. 0 0
      src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeReplyTest.cs
  58. 1 1
      src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeRequestTest.cs
  59. 0 0
      src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeInitMessageTest.cs
  60. 2 3
      src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Connected.cs
  61. 2 3
      src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disconnected.cs
  62. 2 3
      src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disposed.cs
  63. 14 14
      src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs
  64. 0 6
      src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs
  65. 0 7
      src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs
  66. 41 15
      src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs
  67. 34 17
      src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs
  68. 1 1
      src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CastCipherTest.cs
  69. 45 26
      src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs
  70. 46 27
      src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs
  71. 1 1
      src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TripleDesCipherTest.cs
  72. 2 2
      src/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs
  73. 59 36
      src/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs
  74. 2 1
      src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs
  75. 11 2
      src/Renci.SshNet.Tests/Classes/SessionTest_Connected_GlobalRequestMessageAfterAuthenticationRace.cs
  76. 210 0
      src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerAndClientDisconnectRace.cs
  77. 2 1
      src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs
  78. 4 6
      src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessage.cs
  79. 4 4
      src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket.cs
  80. 167 0
      src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSendAfterSendingIncompletePacket.cs
  81. 3 3
      src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs
  82. 17 12
      src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpWriteRequestTest.cs
  83. 0 2
      src/Renci.SshNet.Tests/Classes/Sftp/Responses/ExtendedReplies/StatVfsReplyInfoTest.cs
  84. 1 4
      src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpAttrsResponseTest.cs
  85. 4 4
      src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpDataResponseTest.cs
  86. 5 5
      src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpExtendedReplyResponseTest.cs
  87. 1 3
      src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpHandleResponseTest.cs
  88. 187 0
      src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs
  89. 4 6
      src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Connected.cs
  90. 4 6
      src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disconnected.cs
  91. 4 6
      src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disposed.cs
  92. 1 1
      src/Renci.SshNet.Tests/Classes/SshClientTest.cs
  93. 2 3
      src/Renci.SshNet.Tests/Classes/SshClientTest_Disconnect_ForwardedPortStarted.cs
  94. 2 3
      src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Connected.cs
  95. 2 3
      src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disconnected.cs
  96. 2 3
      src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disposed.cs
  97. 3 4
      src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_ForwardedPortStarted.cs
  98. 0 2
      src/Renci.SshNet.Tests/Classes/SshCommandTest_BeginExecute_EndExecuteInvokedOnAsyncResultFromPreviousInvocation.cs
  99. 1 4
      src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs
  100. 0 8
      src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute_ChannelOpen.cs

+ 2 - 2
build/nuget/SSH.NET.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
     <metadata>
         <id>SSH.NET</id>
-        <version>2016.0.0-beta3</version>
+        <version>2016.0.0</version>
         <title>SSH.NET</title>
         <authors>Renci</authors>
         <owners>olegkap,drieseng</owners>
@@ -10,7 +10,7 @@
         <projectUrl>https://github.com/sshnet/SSH.NET/</projectUrl>
         <requireLicenseAcceptance>false</requireLicenseAcceptance>
         <description>SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism and with broad framework support.</description>
-        <releaseNotes>https://github.com/sshnet/SSH.NET/releases/tag/2016.0.0-beta3</releaseNotes>
+        <releaseNotes>https://github.com/sshnet/SSH.NET/releases/tag/2016.0.0</releaseNotes>
         <summary>A Secure Shell (SSH) library for .NET, optimized for parallelism.</summary>
         <copyright>2012-2016, RENCI</copyright>
         <language>en-US</language>

+ 6 - 4
src/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj

@@ -360,6 +360,9 @@
     <Compile Include="..\Renci.SshNet\Messages\Authentication\SuccessMessage.cs">
       <Link>Messages\Authentication\SuccessMessage.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Connection\CancelTcpIpForwardGlobalRequestMessage.cs">
+      <Link>Messages\Connection\CancelTcpIpForwardGlobalRequestMessage.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Messages\Connection\ChannelCloseMessage.cs">
       <Link>Messages\Connection\ChannelCloseMessage.cs</Link>
     </Compile>
@@ -471,6 +474,9 @@
     <Compile Include="..\Renci.SshNet\Messages\Connection\RequestSuccessMessage.cs">
       <Link>Messages\Connection\RequestSuccessMessage.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Connection\TcpIpForwardGlobalRequestMessage.cs">
+      <Link>Messages\Connection\TcpIpForwardGlobalRequestMessage.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Messages\Message.cs">
       <Link>Messages\Message.cs</Link>
     </Compile>
@@ -723,9 +729,6 @@
     <Compile Include="..\Renci.SshNet\Session.cs">
       <Link>Session.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet\Session.NET.cs">
-      <Link>Session.NET.cs</Link>
-    </Compile>
     <Compile Include="..\Renci.SshNet\SftpClient.cs">
       <Link>SftpClient.cs</Link>
     </Compile>
@@ -908,7 +911,6 @@
     <Compile Include="..\Renci.SshNet\Properties\CommonAssemblyInfo.cs">
       <Link>Properties\CommonAssemblyInfo.cs</Link>
     </Compile>
-    <Compile Include="Session.NET35.cs" />
   </ItemGroup>
   <ItemGroup />
   <ItemGroup>

+ 0 - 62
src/Renci.SshNet.NET35/Session.NET35.cs

@@ -1,62 +0,0 @@
-using System.Linq;
-using System;
-using Renci.SshNet.Messages;
-using System.Reflection;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace Renci.SshNet
-{
-    /// <summary>
-    /// Provides functionality to connect and interact with SSH server.
-    /// </summary>
-    public partial class Session
-    {
-        private static readonly Dictionary<Type, MethodInfo> _handlers;
-
-        static Session()
-        {
-            _handlers = new Dictionary<Type, MethodInfo>();
-
-            foreach (var method in typeof(Session).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).Where(x => x.Name == "HandleMessage"))
-            {
-                if (method.IsGenericMethod) continue;
-
-                var args = method.GetParameters();
-                if (args.Length != 1) continue;
-
-                var argType = args[0].ParameterType;
-                if (!argType.IsSubclassOf(typeof(Message))) continue;
-
-                _handlers.Add(argType, method);
-            }
-        }
-
-        /// <summary>
-        /// Handles SSH messages.
-        /// </summary>
-        /// <param name="message">The message.</param>
-        partial void HandleMessageCore(Message message)
-        {
-            Debug.Assert(message != null);
-
-            MethodInfo method;
-
-            if (_handlers.TryGetValue(message.GetType(), out method))
-            {
-                try
-                {
-                    method.Invoke(this, new object[] { message });
-                }
-                catch (TargetInvocationException ex)
-                {
-                    throw ex.InnerException ?? ex;
-                }
-            }
-            else
-            {
-                HandleMessage(message);
-            }
-        }
-    }
-}

+ 7 - 7
src/Renci.SshNet.Silverlight5/Renci.SshNet.Silverlight5.csproj

@@ -72,12 +72,6 @@
     <Reference Include="System.Net" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="..\Renci.SshNet.Silverlight\Session.SilverlightBrowser.cs">
-      <Link>Session.SilverlightBrowser.cs</Link>
-    </Compile>
-    <Compile Include="..\Renci.SshNet.Silverlight\Session.SilverlightShared.cs">
-      <Link>Session.SilverlightShared.cs</Link>
-    </Compile>
     <Compile Include="..\Renci.SshNet\Abstractions\CryptoAbstraction.cs">
       <Link>Abstractions\CryptoAbstraction.cs</Link>
     </Compile>
@@ -381,6 +375,9 @@
     <Compile Include="..\Renci.SshNet\Messages\Authentication\SuccessMessage.cs">
       <Link>Messages\Authentication\SuccessMessage.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Connection\CancelTcpIpForwardGlobalRequestMessage.cs">
+      <Link>Messages\Connection\CancelTcpIpForwardGlobalRequestMessage.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Messages\Connection\ChannelCloseMessage.cs">
       <Link>Messages\Connection\ChannelCloseMessage.cs</Link>
     </Compile>
@@ -492,6 +489,9 @@
     <Compile Include="..\Renci.SshNet\Messages\Connection\RequestSuccessMessage.cs">
       <Link>Messages\Connection\RequestSuccessMessage.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet\Messages\Connection\TcpIpForwardGlobalRequestMessage.cs">
+      <Link>Messages\Connection\TcpIpForwardGlobalRequestMessage.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet\Messages\Message.cs">
       <Link>Messages\Message.cs</Link>
     </Compile>
@@ -923,7 +923,7 @@
       <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
         <SilverlightProjectProperties />
       </FlavorProperties>
-      <UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
+      <UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
     </VisualStudio>
   </ProjectExtensions>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 46 - 40
src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj

@@ -80,50 +80,50 @@
     <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelDirectTcpipTest.cs">
       <Link>Classes\Channels\ChannelDirectTcpipTest.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelDirectTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs">
-      <Link>Classes\Channels\ChannelDirectTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs">
+      <Link>Classes\Channels\ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs">
-      <Link>Classes\Channels\ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs">
+      <Link>Classes\Channels\ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_Closed.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_Closed.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Disposed_Closed.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Disposed_Closed.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_Disposed.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_Disposed.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Disposed_Closed.cs">
-      <Link>Classes\Channels\ChannelSessionTest_Disposed_Closed.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs">
+      <Link>Classes\Channels\ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs</Link>
     </Compile>
     <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs">
       <Link>Classes\Channels\ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs</Link>
@@ -140,20 +140,23 @@
     <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelStub.cs">
       <Link>Classes\Channels\ChannelStub.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs">
-      <Link>Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_Dispose_SessionIsConnectedAndChannelIsNotOpen.cs">
+      <Link>Classes\Channels\ChannelTest_Dispose_SessionIsConnectedAndChannelIsNotOpen.cs</Link>
+    </Compile>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs">
+      <Link>Classes\Channels\ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs">
-      <Link>Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs">
+      <Link>Classes\Channels\ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs">
-      <Link>Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs">
+      <Link>Classes\Channels\ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs">
-      <Link>Classes\Channels\ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsNotOpen.cs">
+      <Link>Classes\Channels\ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsNotOpen.cs</Link>
     </Compile>
-    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs">
-      <Link>Classes\Channels\ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs</Link>
+    <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsOpen.cs">
+      <Link>Classes\Channels\ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsOpen.cs</Link>
     </Compile>
     <Compile Include="..\Renci.SshNet.Tests\Classes\Channels\ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs">
       <Link>Classes\Channels\ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs</Link>
@@ -1217,6 +1220,9 @@
     <Compile Include="..\Renci.SshNet.Tests\Common\AsyncSocketListener.cs">
       <Link>Common\AsyncSocketListener.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet.Tests\Common\Extensions.cs">
+      <Link>Common\Extensions.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet.Tests\Common\HttpProxyStub.cs">
       <Link>Common\HttpProxyStub.cs</Link>
     </Compile>

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs

@@ -195,7 +195,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
                             _localPacketSize);
                         channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket);
                         channel.Bind();
-                        channel.Close();
+                        channel.Dispose();
 
                         handler = socket;
 
@@ -215,7 +215,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
                 _sessionMock.Verify(p => p.TrySendMessage(It.IsAny<ChannelEofMessage>()), Times.Once);
                 _sessionMock.Verify(p => p.TrySendMessage(It.IsAny<ChannelCloseMessage>()), Times.Once);
 
-                channel.Close();
+                channel.Dispose();
 
                 _sessionMock.Verify(p => p.TrySendMessage(It.IsAny<ChannelEofMessage>()), Times.Once);
                 _sessionMock.Verify(p => p.TrySendMessage(It.IsAny<ChannelCloseMessage>()), Times.Once);

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs

@@ -12,7 +12,7 @@ using Renci.SshNet.Tests.Common;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelDirectTcpipTest_Close_SessionIsConnectedAndChannelIsOpen
+    public class ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen
     {
         private Mock<ISession> _sessionMock;
         private Mock<IForwardedPort> _forwardedPortMock;
@@ -165,7 +165,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
         {
             if (_channel != null)
             {
-                _channel.Close();
+                _channel.Dispose();
             }
         }
 

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs

@@ -13,7 +13,7 @@ using Renci.SshNet.Tests.Common;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen
+    public class ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen
     {
         private Mock<ISession> _sessionMock;
         private Mock<IForwardedPort> _forwardedPortMock;
@@ -157,7 +157,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 3 - 3
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_Closed.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_Disposed.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_Closed
+    public class ChannelSessionTest_Dispose_Disposed
     {
         private Mock<ISession> _sessionMock;
         private Mock<IConnectionInfo> _connectionInfoMock;
@@ -97,12 +97,12 @@ namespace Renci.SshNet.Tests.Classes.Channels
             _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
             _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
             _channel.Open();
-            _channel.Close();
+            _channel.Dispose();
         }
 
         protected virtual void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         internal ChannelSession Channel

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure
+    public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -100,7 +100,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 8 - 4
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs

@@ -6,11 +6,12 @@ using Moq;
 using Renci.SshNet.Channels;
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess
+    public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -79,11 +80,14 @@ namespace Renci.SshNet.Tests.Classes.Channels
                                     _remoteChannelNumber)));
                         w.WaitOne();
                     });
-            _sessionMock.Setup(p => p.IsConnected).Returns(true);
+            _sessionMock.InSequence(_sequence).Setup(p => p.IsConnected).Returns(true);
             _sessionMock.InSequence(_sequence)
                 .Setup(
                     p => p.TrySendMessage(It.Is<ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber)))
                 .Returns(true);
+            _sessionMock.InSequence(_sequence)
+                .Setup(s => s.WaitOnHandle(It.IsNotNull<EventWaitHandle>()))
+                .Callback<WaitHandle>(w => w.WaitOne());
 
             _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
             _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
@@ -100,7 +104,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]
@@ -112,7 +116,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
         [TestMethod]
         public void ExceptionShouldNeverHaveFired()
         {
-            Assert.AreEqual(0, _channelExceptionRegister.Count);
+            Assert.AreEqual(0, _channelExceptionRegister.Count, _channelExceptionRegister.AsString());
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure
+    public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -97,7 +97,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 8 - 4
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs

@@ -6,11 +6,12 @@ using Moq;
 using Renci.SshNet.Channels;
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess
+    public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -79,11 +80,14 @@ namespace Renci.SshNet.Tests.Classes.Channels
                                     _remoteChannelNumber)));
                         w.WaitOne();
                     });
-            _sessionMock.Setup(p => p.IsConnected).Returns(true);
+            _sessionMock.InSequence(_sequence).Setup(p => p.IsConnected).Returns(true);
             _sessionMock.InSequence(_sequence)
                 .Setup(
                     p => p.TrySendMessage(It.Is<ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber)))
                 .Returns(true);
+            _sessionMock.InSequence(_sequence)
+                .Setup(s => s.WaitOnHandle(It.IsNotNull<EventWaitHandle>()))
+                .Callback<WaitHandle>(w => w.WaitOne());
 
             _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
             _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
@@ -97,7 +101,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]
@@ -109,7 +113,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
         [TestMethod]
         public void ExceptionShouldNeverHaveFired()
         {
-            Assert.AreEqual(0, _channelExceptionRegister.Count);
+            Assert.AreEqual(0, _channelExceptionRegister.Count, _channelExceptionRegister.AsString());
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure
+    public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -97,7 +97,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess
+    public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -107,7 +107,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived
+    public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived
     {
         private Mock<ISession> _sessionMock;
         private Mock<IConnectionInfo> _connectionInfoMock;
@@ -105,7 +105,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure
+    public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure
     {
         private Mock<ISession> _sessionMock;
         private Mock<IConnectionInfo> _connectionInfoMock;
@@ -105,7 +105,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived
+    public class ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -96,7 +96,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived
+    public class ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -93,7 +93,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived
+    public class ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -89,7 +89,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 1 - 1
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Disposed_Closed.cs

@@ -3,7 +3,7 @@
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelSessionTest_Disposed_Closed : ChannelSessionTest_Close_Closed
+    public class ChannelSessionTest_Disposed_Closed : ChannelSessionTest_Dispose_Disposed
     {
         protected override void Act()
         {

+ 6 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs

@@ -6,6 +6,7 @@ using Moq;
 using Renci.SshNet.Channels;
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Channels
 {
@@ -79,11 +80,14 @@ namespace Renci.SshNet.Tests.Classes.Channels
                                     _remoteChannelNumber)));
                         w.WaitOne();
                     });
-            _sessionMock.Setup(p => p.IsConnected).Returns(true);
+            _sessionMock.InSequence(_sequence).Setup(p => p.IsConnected).Returns(true);
             _sessionMock.InSequence(_sequence)
                 .Setup(
                     p => p.TrySendMessage(It.Is<ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber)))
                 .Returns(true);
+            _sessionMock.InSequence(_sequence)
+                .Setup(s => s.WaitOnHandle(It.IsNotNull<EventWaitHandle>()))
+                .Callback<WaitHandle>(w => w.WaitOne());
 
             _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
             _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
@@ -107,7 +111,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
         [TestMethod]
         public void ExceptionShouldNeverHaveFired()
         {
-            Assert.AreEqual(0, _channelExceptionRegister.Count);
+            Assert.AreEqual(0, _channelExceptionRegister.Count, _channelExceptionRegister.AsString());
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsNotOpen.cs

@@ -9,7 +9,7 @@ using Renci.SshNet.Messages;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen
+    public class ChannelTest_Dispose_SessionIsConnectedAndChannelIsNotOpen
     {
         private Mock<ISession> _sessionMock;
         private uint _localWindowSize;
@@ -46,7 +46,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived
+    public class ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -84,7 +84,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked
+    public class ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -84,7 +84,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs

@@ -10,7 +10,7 @@ using Renci.SshNet.Messages.Connection;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived
+    public class ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived
     {
         private Mock<ISession> _sessionMock;
         private uint _localChannelNumber;
@@ -93,7 +93,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsNotOpen.cs

@@ -9,7 +9,7 @@ using Renci.SshNet.Messages;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen
+    public class ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsNotOpen
     {
         private Mock<ISession> _sessionMock;
         private uint _localWindowSize;
@@ -46,7 +46,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs → src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsOpen.cs

@@ -8,7 +8,7 @@ using Renci.SshNet.Messages;
 namespace Renci.SshNet.Tests.Classes.Channels
 {
     [TestClass]
-    public class ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen
+    public class ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsOpen
     {
         private Mock<ISession> _sessionMock;
         private uint _localWindowSize;
@@ -46,7 +46,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            _channel.Close();
+            _channel.Dispose();
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs

@@ -28,9 +28,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
         private void Arrange()
         {
             var random = new Random();
-            _localWindowSize = (uint)random.Next(1000, int.MaxValue);
+            _localWindowSize = (uint) random.Next(1000, int.MaxValue);
             _localPacketSize = _localWindowSize - 1;
-            _localChannelNumber = (uint)random.Next(0, int.MaxValue);
+            _localChannelNumber = (uint) random.Next(0, int.MaxValue);
             _onCloseException = new SystemException();
             _channelExceptionRegister = new List<ExceptionEventArgs>();
 

+ 11 - 5
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs

@@ -5,6 +5,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Channels
 {
@@ -43,8 +44,13 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
             _sessionMock = new Mock<ISession>(MockBehavior.Strict);
 
-            _sessionMock.Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.Setup(p => p.TrySendMessage(It.Is<ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true);
+            var sequence = new MockSequence();
+
+            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
+            _sessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is<ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true);
+            _sessionMock.InSequence(sequence)
+                .Setup(s => s.WaitOnHandle(It.IsNotNull<EventWaitHandle>()))
+                .Callback<WaitHandle>(w => w.WaitOne());
 
             _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
             _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
@@ -82,9 +88,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
         }
 
         [TestMethod]
-        public void WaitOnHandleOnSessionShouldNeverBeInvoked()
+        public void WaitOnHandleOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny<EventWaitHandle>()), Times.Never);
+            _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny<EventWaitHandle>()), Times.Once);
         }
 
         [TestMethod]
@@ -97,7 +103,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
         [TestMethod]
         public void ExceptionShouldNeverHaveFired()
         {
-            Assert.AreEqual(0, _channelExceptionRegister.Count);
+            Assert.AreEqual(0, _channelExceptionRegister.Count, _channelExceptionRegister.AsString());
         }
     }
 }

+ 11 - 5
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs

@@ -5,6 +5,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Moq;
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Channels
 {
@@ -43,10 +44,15 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
             _sessionMock = new Mock<ISession>(MockBehavior.Strict);
 
-            _sessionMock.Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.Setup(
+            var sequence = new MockSequence();
+
+            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
+            _sessionMock.InSequence(sequence).Setup(
                 p => p.TrySendMessage(It.Is<ChannelCloseMessage>(c => c.LocalChannelNumber == _remoteChannelNumber)))
                 .Returns(true);
+            _sessionMock.InSequence(sequence)
+                .Setup(s => s.WaitOnHandle(It.IsNotNull<EventWaitHandle>()))
+                .Callback<WaitHandle>(w => w.WaitOne());
 
             _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
             _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
@@ -87,9 +93,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
         }
 
         [TestMethod]
-        public void WaitOnHandleOnSessionShouldNeverBeInvoked()
+        public void WaitOnHandleOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny<EventWaitHandle>()), Times.Never);
+            _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny<EventWaitHandle>()), Times.Once);
         }
 
         [TestMethod]
@@ -102,7 +108,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
         [TestMethod]
         public void ExceptionShouldNeverHaveFired()
         {
-            Assert.AreEqual(0, _channelExceptionRegister.Count);
+            Assert.AreEqual(0, _channelExceptionRegister.Count, _channelExceptionRegister.AsString());
         }
     }
 }

+ 0 - 31
src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_ToGlobalRequestName.cs

@@ -1,31 +0,0 @@
-using System.Text;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Renci.SshNet.Messages.Connection;
-
-namespace Renci.SshNet.Tests.Classes.Common
-{
-    [TestClass]
-    public class ExtensionsTest_ToGlobalRequestName
-    {
-        [TestMethod]
-        public void TcpipForward()
-        {
-            var data = Encoding.ASCII.GetBytes("tcpip-forward");
-
-            var actual = data.ToGlobalRequestName();
-
-            Assert.AreEqual(GlobalRequestName.TcpIpForward, actual);
-        }
-
-        [TestMethod]
-        public void CancelTcpipForward()
-        {
-            var data = Encoding.ASCII.GetBytes("cancel-tcpip-forward");
-
-            var actual = data.ToGlobalRequestName();
-
-            Assert.AreEqual(GlobalRequestName.CancelTcpIpForward, actual);
-        }
-
-    }
-}

+ 208 - 2
src/Renci.SshNet.Tests/Classes/Common/SshDataTest.cs

@@ -1,4 +1,5 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
 
 namespace Renci.SshNet.Tests.Classes.Common
@@ -10,7 +11,7 @@ namespace Renci.SshNet.Tests.Classes.Common
         public void Write_Boolean_False()
         {
             var sshData = new BoolSshData(false);
-            
+
             var bytes = sshData.GetBytes();
 
             Assert.AreEqual((byte) 0, bytes[0]);
@@ -26,6 +27,125 @@ namespace Renci.SshNet.Tests.Classes.Common
             Assert.AreEqual((byte) 1, bytes[0]);
         }
 
+        [TestMethod]
+        public void Load_Data()
+        {
+            const uint one = 123456u;
+            const uint two = 456789u;
+
+            var sshDataStream = new SshDataStream(8);
+            sshDataStream.Write(one);
+            sshDataStream.Write(two);
+
+            var sshData = sshDataStream.ToArray();
+
+            var request = new RequestSshData();
+            request.Load(sshData);
+
+            Assert.AreEqual(one, request.ValueOne);
+            Assert.AreEqual(two, request.ValueTwo);
+        }
+
+        [TestMethod]
+        public void Load_Data_ShouldThrowArgumentNullExceptionWhenDataIsNull()
+        {
+            const byte[] sshData = null;
+            var request = new RequestSshData();
+
+            try
+            {
+                request.Load(sshData);
+                Assert.Fail();
+            }
+            catch (ArgumentNullException ex)
+            {
+                Assert.IsNull(ex.InnerException);
+                Assert.AreEqual("data", ex.ParamName);
+            }
+        }
+
+        [TestMethod]
+        public void Load_DataAndOffsetAndCount()
+        {
+            const uint one = 123456u;
+            const uint two = 456789u;
+
+            var sshDataStream = new SshDataStream(11);
+            sshDataStream.WriteByte(0x05);
+            sshDataStream.WriteByte(0x07);
+            sshDataStream.WriteByte(0x0f);
+            sshDataStream.Write(one);
+            sshDataStream.Write(two);
+
+            var sshData = sshDataStream.ToArray();
+
+            var request = new RequestSshData();
+            request.Load(sshData, 3, sshData.Length - 3);
+
+            Assert.AreEqual(one, request.ValueOne);
+            Assert.AreEqual(two, request.ValueTwo);
+        }
+
+
+        [TestMethod]
+        public void OfType()
+        {
+            const uint one = 123456u;
+            const uint two = 456789u;
+
+            var sshDataStream = new SshDataStream(8);
+            sshDataStream.Write(one);
+            sshDataStream.Write(two);
+
+            var sshData = sshDataStream.ToArray();
+
+            var request = new RequestSshData();
+            request.Load(sshData);
+
+            var reply = request.OfType<ReplySshData>();
+            Assert.IsNotNull(reply);
+            Assert.AreEqual(one, reply.ValueOne);
+        }
+
+        [TestMethod]
+        public void OfType_LoadWithOffset()
+        {
+            const uint one = 123456u;
+            const uint two = 456789u;
+
+            var sshDataStream = new SshDataStream(11);
+            sshDataStream.WriteByte(0x05);
+            sshDataStream.WriteByte(0x07);
+            sshDataStream.WriteByte(0x0f);
+            sshDataStream.Write(one);
+            sshDataStream.Write(two);
+
+            var sshData = sshDataStream.ToArray();
+
+            var request = new RequestSshData();
+            request.Load(sshData, 3, sshData.Length - 3);
+            var reply = request.OfType<ReplySshData>();
+            Assert.IsNotNull(reply);
+            Assert.AreEqual(one, reply.ValueOne);
+        }
+
+        [TestMethod]
+        public void OfType_ShouldThrowArgumentNullExceptionWhenNoDataIsLoaded()
+        {
+            var request = new RequestSshData();
+
+            try
+            {
+                request.OfType<ReplySshData>();
+                Assert.Fail();
+            }
+            catch (ArgumentNullException ex)
+            {
+                Assert.IsNull(ex.InnerException);
+                Assert.AreEqual("data", ex.ParamName);
+            }
+        }
+
         private class BoolSshData : SshData
         {
             private readonly bool _value;
@@ -54,5 +174,91 @@ namespace Renci.SshNet.Tests.Classes.Common
                 Write(_value);
             }
         }
+
+        private class RequestSshData : SshData
+        {
+            private uint _valueOne;
+            private uint _valueTwo;
+
+            public RequestSshData()
+            {
+            }
+
+            public RequestSshData(uint one, uint two)
+            {
+                _valueOne = one;
+                _valueTwo = two;
+            }
+
+            protected override int BufferCapacity
+            {
+                get
+                {
+                    var capacity = base.BufferCapacity;
+                    capacity += 4; // ValueOne
+                    capacity += 4; // ValueTwo
+                    return capacity;
+                }
+            }
+
+            public uint ValueOne
+            {
+                get { return _valueOne; }
+                set { _valueOne = value; }
+            }
+
+            public uint ValueTwo
+            {
+                get { return _valueTwo; }
+                set { _valueTwo = value; }
+            }
+
+            protected override void LoadData()
+            {
+                _valueOne = ReadUInt32();
+                _valueTwo = ReadUInt32();
+            }
+
+            protected override void SaveData()
+            {
+                Write(ValueOne);
+                Write(ValueTwo);
+            }
+        }
+
+        private class ReplySshData : SshData
+        {
+            private uint _valueOne;
+
+            public ReplySshData()
+            {
+            }
+
+            protected override int BufferCapacity
+            {
+                get
+                {
+                    var capacity = base.BufferCapacity;
+                    capacity += 4; // ValueOne
+                    return capacity;
+                }
+            }
+
+            public uint ValueOne
+            {
+                get { return _valueOne; }
+                set { _valueOne = value; }
+            }
+
+            protected override void LoadData()
+            {
+                _valueOne = ReadUInt32();
+            }
+
+            protected override void SaveData()
+            {
+                Write(ValueOne);
+            }
+        }
     }
 }

+ 2 - 20
src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs

@@ -11,6 +11,7 @@ using Moq;
 using Renci.SshNet.Abstractions;
 using Renci.SshNet.Channels;
 using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes
 {
@@ -110,7 +111,6 @@ namespace Renci.SshNet.Tests.Classes
                     Thread.Sleep(_bindSleepTime);
                     _channelBindCompleted.Set();
                 });
-            _channelMock.Setup(p => p.Close());
             _channelMock.Setup(p => p.Dispose());
         }
 
@@ -190,7 +190,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void ExceptionShouldNotHaveFired()
         {
-            Assert.AreEqual(0, _exceptionRegister.Count, GetReportedExceptions());
+            Assert.AreEqual(0, _exceptionRegister.Count, _exceptionRegister.AsString());
         }
 
         [TestMethod]
@@ -208,12 +208,6 @@ namespace Renci.SshNet.Tests.Classes
             _channelMock.Verify(p => p.Bind(), Times.Once);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldBeInvokedOnce()
-        {
-            _channelMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {
@@ -248,17 +242,5 @@ namespace Renci.SshNet.Tests.Classes
             // wait until SOCKS client is bound to channel
             Assert.IsTrue(_channelBindStarted.WaitOne(TimeSpan.FromMilliseconds(200)));
         }
-
-        private string GetReportedExceptions()
-        {
-            if (_exceptionRegister.Count == 0)
-                return string.Empty;
-
-            string reportedExceptions = string.Empty;
-            foreach (var exceptionEvent in _exceptionRegister)
-                reportedExceptions += exceptionEvent.Exception.ToString();
-
-            return reportedExceptions;
-        }
     }
 }

+ 0 - 7
src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs

@@ -59,7 +59,6 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(p => p.IsConnected).Returns(true);
             _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
             _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);
-            _channelMock.Setup(p => p.Close());
             _channelMock.Setup(p => p.Dispose());
 
             _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port);
@@ -134,12 +133,6 @@ namespace Renci.SshNet.Tests.Classes
             Assert.AreEqual(0, _exceptionRegister.Count);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldBeInvokedOnce()
-        {
-            _channelMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {

+ 4 - 10
src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs

@@ -11,6 +11,7 @@ using Moq;
 using Renci.SshNet.Abstractions;
 using Renci.SshNet.Channels;
 using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes
 {
@@ -112,7 +113,6 @@ namespace Renci.SshNet.Tests.Classes
                     Thread.Sleep(_bindSleepTime);
                     _channelBindCompleted.Set();
                 });
-            _channelMock.Setup(p => p.Close());
             _channelMock.Setup(p => p.Dispose());
         }
 
@@ -195,9 +195,9 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void ExceptionShouldHaveFiredOne()
         {
-            Assert.AreEqual(1, _exceptionRegister.Count);
-            Assert.IsNotNull(_exceptionRegister[0]);
-            Assert.AreSame(_sessionException, _exceptionRegister[0].Exception);
+            Assert.AreEqual(1, _exceptionRegister.Count, _exceptionRegister.AsString());
+            Assert.IsNotNull(_exceptionRegister[0], _exceptionRegister.AsString());
+            Assert.AreSame(_sessionException, _exceptionRegister[0].Exception, _exceptionRegister.AsString());
         }
 
         [TestMethod]
@@ -215,12 +215,6 @@ namespace Renci.SshNet.Tests.Classes
             _channelMock.Verify(p => p.Bind(), Times.Once);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldBeInvokedOnce()
-        {
-            _channelMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {

+ 2 - 22
src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs

@@ -8,6 +8,7 @@ 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
 {
@@ -90,7 +91,6 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.InSequence(seq).Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);
             _sessionMock.InSequence(seq).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
             _connectionInfoMock.InSequence(seq).Setup(p => p.Timeout).Returns(_connectionTimeout);
-            _channelMock.InSequence(seq).Setup(p => p.Close());
             _channelMock.InSequence(seq).Setup(p => p.Dispose()).Callback(() => _channelDisposed.Set());
         }
 
@@ -138,7 +138,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void ExceptionShouldNeverBeFired()
         {
-            Assert.AreEqual(0, _exceptionRegister.Count, GetExceptions());
+            Assert.AreEqual(0, _exceptionRegister.Count, _exceptionRegister.AsString());
         }
 
         [TestMethod]
@@ -147,30 +147,10 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Verify(p => p.CreateChannelDirectTcpip(), Times.Once);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldBeInvokedOnce()
-        {
-            _channelMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {
             _channelMock.Verify(p => p.Dispose(), Times.Once);
         }
-
-        private string GetExceptions()
-        {
-            var sb = new StringBuilder();
-
-            foreach (var exceptionEventArgs in _exceptionRegister)
-            {
-                if (sb.Length > 0)
-                    sb.AppendLine();
-                sb.Append(exceptionEventArgs.Exception);
-            }
-
-            return sb.ToString();
-        }
     }
 }

+ 2 - 22
src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs

@@ -8,6 +8,7 @@ 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
 {
@@ -77,7 +78,6 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.InSequence(seq).Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);
             _sessionMock.InSequence(seq).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
             _connectionInfoMock.InSequence(seq).Setup(p => p.Timeout).Returns(_connectionTimeout);
-            _channelMock.InSequence(seq).Setup(p => p.Close());
             _channelMock.InSequence(seq).Setup(p => p.Dispose());
         }
 
@@ -138,7 +138,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void ExceptionShouldHaveFiredOnce()
         {
-            Assert.AreEqual(1, _exceptionRegister.Count, GetExceptions());
+            Assert.AreEqual(1, _exceptionRegister.Count, _exceptionRegister.AsString());
 
             var exception = _exceptionRegister[0].Exception;
             Assert.IsNotNull(exception);
@@ -153,30 +153,10 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Verify(p => p.CreateChannelDirectTcpip(), Times.Once);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldBeInvokedOnce()
-        {
-            _channelMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {
             _channelMock.Verify(p => p.Dispose(), Times.Once);
         }
-
-        private string GetExceptions()
-        {
-            var sb = new StringBuilder();
-
-            foreach (var exceptionEventArgs in _exceptionRegister)
-            {
-                if (sb.Length > 0)
-                    sb.AppendLine();
-                sb.Append(exceptionEventArgs.Exception);
-            }
-
-            return sb.ToString();
-        }
     }
 }

+ 0 - 7
src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs

@@ -110,7 +110,6 @@ namespace Renci.SshNet.Tests.Classes
                     Thread.Sleep(_bindSleepTime);
                     _channelBindCompleted.Set();
                 });
-            _channelMock.Setup(p => p.Close());
             _channelMock.Setup(p => p.Dispose());
         }
 
@@ -196,12 +195,6 @@ namespace Renci.SshNet.Tests.Classes
             Assert.AreEqual(0, _exceptionRegister.Count);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldBeInvokedOnce()
-        {
-            _channelMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {

+ 0 - 7
src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs

@@ -59,7 +59,6 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(p => p.IsConnected).Returns(true);
             _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
             _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);
-            _channelMock.Setup(p => p.Close());
             _channelMock.Setup(p => p.Dispose());
 
             _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port);
@@ -134,12 +133,6 @@ namespace Renci.SshNet.Tests.Classes
             Assert.AreEqual(0, _exceptionRegister.Count);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldBeInvokedOnce()
-        {
-            _channelMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {

+ 0 - 7
src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs

@@ -85,7 +85,6 @@ namespace Renci.SshNet.Tests.Classes
                     Thread.Sleep(_bindSleepTime);
                     _channelBindCompleted.Set();
                 });
-            _channelMock.Setup(p => p.Close());
             _channelMock.Setup(p => p.Dispose());
 
             _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
@@ -186,12 +185,6 @@ namespace Renci.SshNet.Tests.Classes
             _channelMock.Verify(p => p.Bind(), Times.Once);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldBeInvokedOnce()
-        {
-            _channelMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {

+ 0 - 1
src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs

@@ -85,7 +85,6 @@ namespace Renci.SshNet.Tests.Classes
                     if (handlerSocket != null && handlerSocket.Connected)
                         handlerSocket.Shutdown(SocketShutdown.Both);
                 });
-            _channelMock.Setup(p => p.Close());
             _channelMock.Setup(p => p.Dispose());
 
             using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp))

+ 4 - 5
src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs

@@ -98,11 +98,10 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object);
             _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny<Socket>())).Callback<string, uint, IForwardedPort, Socket>((address, port, forwardedPort, socket) => handlerSocket = socket);
             _channelMock.Setup(p => p.Bind()).Callback(() =>
-            {
-                if (handlerSocket != null && handlerSocket.Connected)
-                    handlerSocket.Shutdown(SocketShutdown.Both);
-            });
-            _channelMock.Setup(p => p.Close());
+                {
+                    if (handlerSocket != null && handlerSocket.Connected)
+                        handlerSocket.Shutdown(SocketShutdown.Both);
+                });
             _channelMock.Setup(p => p.Dispose());
 
             using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp))

+ 0 - 1
src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs

@@ -89,7 +89,6 @@ namespace Renci.SshNet.Tests.Classes
                 if (handlerSocket != null && handlerSocket.Connected)
                     handlerSocket.Shutdown(SocketShutdown.Both);
             });
-            _channelMock.Setup(p => p.Close());
             _channelMock.Setup(p => p.Dispose());
 
             using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp))

+ 0 - 7
src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs

@@ -103,7 +103,6 @@ namespace Renci.SshNet.Tests.Classes
                     Thread.Sleep(_bindSleepTime);
                     _channelBindCompleted.Set();
                 });
-            _channelMock.Setup(p => p.Close());
             _channelMock.Setup(p => p.Dispose());
         }
 
@@ -201,12 +200,6 @@ namespace Renci.SshNet.Tests.Classes
             _channelMock.Verify(p => p.Bind(), Times.Once);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldBeInvokedOnce()
-        {
-            _channelMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {

+ 2 - 11
src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs

@@ -112,9 +112,8 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(
                 p =>
                     p.SendMessage(
-                        It.Is<GlobalRequestMessage>(
+                        It.Is<TcpIpForwardGlobalRequestMessage>(
                             g =>
-                                g.RequestName == GlobalRequestName.TcpIpForward &&
                                 g.AddressToBind == ForwardedPort.BoundHost &&
                                 g.PortToBind == ForwardedPort.BoundPort)))
                 .Callback(
@@ -135,14 +134,12 @@ namespace Renci.SshNet.Tests.Classes
                                 Thread.Sleep(_bindSleepTime);
                                 _channelBindCompleted.Set();
                             });
-            _channelMock.Setup(p => p.Close());
             _channelMock.Setup(p => p.Dispose());
             _sessionMock.Setup(
                 p =>
                     p.SendMessage(
-                        It.Is<GlobalRequestMessage>(
+                        It.Is<CancelTcpIpForwardGlobalRequestMessage>(
                             g =>
-                                g.RequestName == GlobalRequestName.CancelTcpIpForward &&
                                 g.AddressToBind == ForwardedPort.BoundHost && g.PortToBind == ForwardedPort.BoundPort))).Callback(
                                     () =>
                                         {
@@ -241,12 +238,6 @@ namespace Renci.SshNet.Tests.Classes
                         ForwardedPort), Times.Once);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldBeInvokedOnce()
-        {
-            _channelMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {

+ 4 - 5
src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStopped.cs

@@ -61,9 +61,8 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(
                 p =>
                     p.SendMessage(
-                        It.Is<GlobalRequestMessage>(
+                        It.Is<TcpIpForwardGlobalRequestMessage>(
                             g =>
-                                g.RequestName == GlobalRequestName.TcpIpForward &&
                                 g.AddressToBind == ForwardedPort.BoundHost &&
                                 g.PortToBind == ForwardedPort.BoundPort)))
                 .Callback(
@@ -74,10 +73,10 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(
                 p =>
                     p.SendMessage(
-                        It.Is<GlobalRequestMessage>(
+                        It.Is<CancelTcpIpForwardGlobalRequestMessage>(
                             g =>
-                                g.RequestName == GlobalRequestName.CancelTcpIpForward &&
-                                g.AddressToBind == ForwardedPort.BoundHost && g.PortToBind == ForwardedPort.BoundPort)))
+                                g.AddressToBind == ForwardedPort.BoundHost &&
+                                g.PortToBind == ForwardedPort.BoundPort)))
                 .Callback(
                     () =>
                         _sessionMock.Raise(s => s.RequestSuccessReceived += null,

+ 4 - 7
src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortNeverStarted.cs

@@ -37,10 +37,10 @@ namespace Renci.SshNet.Tests.Classes
                 _sessionMock.Setup(
                     p =>
                         p.SendMessage(
-                            It.Is<GlobalRequestMessage>(
+                            It.Is<CancelTcpIpForwardGlobalRequestMessage>(
                                 g =>
-                                    g.RequestName == GlobalRequestName.CancelTcpIpForward &&
-                                    g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort)));
+                                    g.AddressToBind == _forwardedPort.BoundHost &&
+                                    g.PortToBind == _forwardedPort.BoundPort)));
                 _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true));
                 _forwardedPort.Dispose();
                 _forwardedPort = null;
@@ -68,9 +68,8 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(
                 p =>
                     p.SendMessage(
-                        It.Is<GlobalRequestMessage>(
+                        It.Is<TcpIpForwardGlobalRequestMessage>(
                             g =>
-                                g.RequestName == GlobalRequestName.TcpIpForward &&
                                 g.AddressToBind == _forwardedPort.BoundHost &&
                                 g.PortToBind == _forwardedPort.BoundPort)))
                 .Callback(
@@ -115,7 +114,6 @@ namespace Renci.SshNet.Tests.Classes
                         It.Is<IPEndPoint>(
                             ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port),
                         _forwardedPort));
-            channelMock.Setup(p => p.Close());
             channelMock.Setup(p => p.Dispose());
 
             _sessionMock.Raise(p => p.ChannelOpenReceived += null,
@@ -126,7 +124,6 @@ namespace Renci.SshNet.Tests.Classes
 
             _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once);
             channelMock.Verify(p => p.Bind(It.Is<IPEndPoint>(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once);
-            channelMock.Verify(p => p.Close(), Times.Once);
             channelMock.Verify(p => p.Dispose(), Times.Once);
         }
 

+ 4 - 7
src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStarted.cs

@@ -38,10 +38,10 @@ namespace Renci.SshNet.Tests.Classes
                 _sessionMock.Setup(
                     p =>
                         p.SendMessage(
-                            It.Is<GlobalRequestMessage>(
+                            It.Is<CancelTcpIpForwardGlobalRequestMessage>(
                                 g =>
-                                    g.RequestName == GlobalRequestName.CancelTcpIpForward &&
-                                    g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort)));
+                                    g.AddressToBind == _forwardedPort.BoundHost &&
+                                    g.PortToBind == _forwardedPort.BoundPort)));
                 _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true));
                 _forwardedPort.Dispose();
                 _forwardedPort = null;
@@ -69,9 +69,8 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(
                 p =>
                     p.SendMessage(
-                        It.Is<GlobalRequestMessage>(
+                        It.Is<TcpIpForwardGlobalRequestMessage>(
                             g =>
-                                g.RequestName == GlobalRequestName.TcpIpForward &&
                                 g.AddressToBind == _forwardedPort.BoundHost &&
                                 g.PortToBind == _forwardedPort.BoundPort)))
                 .Callback(
@@ -132,7 +131,6 @@ namespace Renci.SshNet.Tests.Classes
                         It.Is<IPEndPoint>(
                             ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port),
                         _forwardedPort));
-            channelMock.Setup(p => p.Close());
             channelMock.Setup(p => p.Dispose());
 
             _sessionMock.Raise(p => p.ChannelOpenReceived += null,
@@ -143,7 +141,6 @@ namespace Renci.SshNet.Tests.Classes
 
             _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once);
             channelMock.Verify(p => p.Bind(It.Is<IPEndPoint>(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once);
-            channelMock.Verify(p => p.Close(), Times.Once);
             channelMock.Verify(p => p.Dispose(), Times.Once);
         }
 

+ 10 - 13
src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStopped.cs

@@ -37,10 +37,10 @@ namespace Renci.SshNet.Tests.Classes
                 _sessionMock.Setup(
                     p =>
                         p.SendMessage(
-                            It.Is<GlobalRequestMessage>(
+                            It.Is<CancelTcpIpForwardGlobalRequestMessage>(
                                 g =>
-                                    g.RequestName == GlobalRequestName.CancelTcpIpForward &&
-                                    g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort)));
+                                    g.AddressToBind == _forwardedPort.BoundHost &&
+                                    g.PortToBind == _forwardedPort.BoundPort)));
                 _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true));
                 _forwardedPort.Dispose();
                 _forwardedPort = null;
@@ -68,9 +68,8 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(
                 p =>
                     p.SendMessage(
-                        It.Is<GlobalRequestMessage>(
+                        It.Is<TcpIpForwardGlobalRequestMessage>(
                             g =>
-                                g.RequestName == GlobalRequestName.TcpIpForward &&
                                 g.AddressToBind == _forwardedPort.BoundHost &&
                                 g.PortToBind == _forwardedPort.BoundPort)))
                 .Callback(
@@ -82,10 +81,10 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(
                 p =>
                     p.SendMessage(
-                        It.Is<GlobalRequestMessage>(
+                        It.Is<CancelTcpIpForwardGlobalRequestMessage>(
                             g =>
-                                g.RequestName == GlobalRequestName.CancelTcpIpForward &&
-                                g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort)))
+                                g.AddressToBind == _forwardedPort.BoundHost &&
+                                g.PortToBind == _forwardedPort.BoundPort)))
                 .Callback(
                     () =>
                         _sessionMock.Raise(s => s.RequestSuccessReceived += null,
@@ -121,7 +120,7 @@ namespace Renci.SshNet.Tests.Classes
             var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture);
             var originatorPort = (uint)new Random().Next(0, int.MaxValue);
             var channelMock = new Mock<IChannelForwardedTcpip>(MockBehavior.Strict);
-            var channelDiposed = new ManualResetEvent(false);
+            var channelDisposed = new ManualResetEvent(false);
 
             _sessionMock.Setup(
                 p =>
@@ -132,8 +131,7 @@ namespace Renci.SshNet.Tests.Classes
                         It.Is<IPEndPoint>(
                             ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port),
                         _forwardedPort));
-            channelMock.Setup(p => p.Close());
-            channelMock.Setup(p => p.Dispose()).Callback(() => channelDiposed.Set());
+            channelMock.Setup(p => p.Dispose()).Callback(() => channelDisposed.Set());
 
             _sessionMock.Raise(p => p.ChannelOpenReceived += null,
                 new MessageEventArgs<ChannelOpenMessage>(new ChannelOpenMessage(channelNumber, initialWindowSize,
@@ -142,11 +140,10 @@ namespace Renci.SshNet.Tests.Classes
                         originatorPort))));
 
             // wait for channel to be disposed
-            channelDiposed.WaitOne(TimeSpan.FromMilliseconds(200));
+            channelDisposed.WaitOne(TimeSpan.FromMilliseconds(200));
 
             _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once);
             channelMock.Verify(p => p.Bind(It.Is<IPEndPoint>(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once);
-            channelMock.Verify(p => p.Close(), Times.Once);
             channelMock.Verify(p => p.Dispose(), Times.Once);
         }
 

+ 3 - 8
src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Started.cs

@@ -37,10 +37,8 @@ namespace Renci.SshNet.Tests.Classes
                 _sessionMock.Setup(
                     p =>
                         p.SendMessage(
-                            It.Is<GlobalRequestMessage>(
-                                g =>
-                                    g.RequestName == GlobalRequestName.CancelTcpIpForward &&
-                                    g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort)));
+                            It.Is<CancelTcpIpForwardGlobalRequestMessage>(
+                                g => g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort)));
                 _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true));
                 _forwardedPort.Dispose();
                 _forwardedPort = null;
@@ -68,9 +66,8 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(
                 p =>
                     p.SendMessage(
-                        It.Is<GlobalRequestMessage>(
+                        It.Is<TcpIpForwardGlobalRequestMessage>(
                             g =>
-                                g.RequestName == GlobalRequestName.TcpIpForward &&
                                 g.AddressToBind == _forwardedPort.BoundHost &&
                                 g.PortToBind == _forwardedPort.BoundPort)))
                 .Callback(
@@ -110,7 +107,6 @@ namespace Renci.SshNet.Tests.Classes
                         It.Is<IPEndPoint>(
                             ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port),
                         _forwardedPort));
-            channelMock.Setup(p => p.Close());
             channelMock.Setup(p => p.Dispose()).Callback(() => channelDisposed.Set());
 
             _sessionMock.Raise(p => p.ChannelOpenReceived += null,
@@ -124,7 +120,6 @@ namespace Renci.SshNet.Tests.Classes
 
             _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once);
             channelMock.Verify(p => p.Bind(It.Is<IPEndPoint>(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once);
-            channelMock.Verify(p => p.Close(), Times.Once);
             channelMock.Verify(p => p.Dispose(), Times.Once);
 
             Assert.AreEqual(0, _closingRegister.Count);

+ 4 - 5
src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortNeverStarted.cs

@@ -37,10 +37,10 @@ namespace Renci.SshNet.Tests.Classes
                 _sessionMock.Setup(
                     p =>
                         p.SendMessage(
-                            It.Is<GlobalRequestMessage>(
+                            It.Is<CancelTcpIpForwardGlobalRequestMessage>(
                                 g =>
-                                    g.RequestName == GlobalRequestName.CancelTcpIpForward &&
-                                    g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort)));
+                                    g.AddressToBind == _forwardedPort.BoundHost &&
+                                    g.PortToBind == _forwardedPort.BoundPort)));
                 _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true));
                 _forwardedPort.Dispose();
                 _forwardedPort = null;
@@ -68,9 +68,8 @@ namespace Renci.SshNet.Tests.Classes
             _sessionMock.Setup(
                 p =>
                     p.SendMessage(
-                        It.Is<GlobalRequestMessage>(
+                        It.Is<TcpIpForwardGlobalRequestMessage>(
                             g =>
-                                g.RequestName == GlobalRequestName.TcpIpForward &&
                                 g.AddressToBind == _forwardedPort.BoundHost &&
                                 g.PortToBind == _forwardedPort.BoundPort)))
                 .Callback(

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelDataMessageTest.cs

@@ -43,7 +43,7 @@ namespace Renci.SshNet.Tests.Classes.Messages.Connection
         public void Constructor_LocalChannelNumberAndData_ShouldThrowArgumentNullExceptionWhenDataIsNull()
         {
             var localChannelNumber = (uint) new Random().Next(0, int.MaxValue);
-            byte[] data = null;
+            const byte[] data = null;
 
             try
             {
@@ -142,7 +142,7 @@ namespace Renci.SshNet.Tests.Classes.Messages.Connection
             var bytes = channelDataMessage.GetBytes();
             var target = new ChannelDataMessage();
 
-            target.Load(bytes);
+            target.Load(bytes, 1, bytes.Length - 1); // skip message type
 
             Assert.IsTrue(target.Data.SequenceEqual(data.Take(offset, size)));
             Assert.AreEqual(0, target.Offset);

+ 5 - 5
src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/ChannelOpenMessageTest.cs

@@ -124,7 +124,7 @@ namespace Renci.SshNet.Tests.Classes.Messages.Connection
             var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info);
             var bytes = target.GetBytes();
 
-            target.Load(bytes);
+            target.Load(bytes, 1, bytes.Length - 1); // skip message type
 
             Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType));
             Assert.IsNotNull(target.Info);
@@ -151,7 +151,7 @@ namespace Renci.SshNet.Tests.Classes.Messages.Connection
             var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info);
             var bytes = target.GetBytes();
 
-            target.Load(bytes);
+            target.Load(bytes, 1, bytes.Length - 1); // skip message type
 
             Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType));
             Assert.IsNotNull(target.Info);
@@ -178,7 +178,7 @@ namespace Renci.SshNet.Tests.Classes.Messages.Connection
             var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info);
             var bytes = target.GetBytes();
 
-            target.Load(bytes);
+            target.Load(bytes, 1, bytes.Length - 1); // skip message type
 
             Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType));
             Assert.IsNotNull(target.Info);
@@ -202,7 +202,7 @@ namespace Renci.SshNet.Tests.Classes.Messages.Connection
             var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info);
             var bytes = target.GetBytes();
 
-            target.Load(bytes);
+            target.Load(bytes, 1, bytes.Length - 1); // skip message type
 
             Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType));
             Assert.IsNotNull(target.Info);
@@ -238,7 +238,7 @@ namespace Renci.SshNet.Tests.Classes.Messages.Connection
 
             try
             {
-                target.Load(bytes);
+                target.Load(bytes, 1, bytes.Length - 1); // skip message type
                 Assert.Fail();
             }
             catch (NotSupportedException ex)

+ 14 - 18
src/Renci.SshNet.Tests/Classes/Messages/Connection/GlobalRequestMessageTest.cs

@@ -1,6 +1,8 @@
 using Renci.SshNet.Messages.Connection;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using System;
+using System.Globalization;
+using System.Text;
 using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Messages.Connection
@@ -12,30 +14,24 @@ namespace Renci.SshNet.Tests.Classes.Messages.Connection
     [TestClass]
     public class GlobalRequestMessageTest : TestBase
     {
-        /// <summary>
-        ///A test for GlobalRequestMessage Constructor
-        ///</summary>
         [TestMethod]
-        [Ignore] // placeholder
-        public void GlobalRequestMessageConstructorTest()
+        public void DefaultCtor()
         {
-            GlobalRequestMessage target = new GlobalRequestMessage();
-            Assert.Inconclusive("TODO: Implement code to verify target");
+            new GlobalRequestMessage();
         }
 
-        /// <summary>
-        ///A test for GlobalRequestMessage Constructor
-        ///</summary>
         [TestMethod]
-        [Ignore] // placeholder
-        public void GlobalRequestMessageConstructorTest2()
+        public void Ctor_RequestNameAndWantReply()
         {
-            GlobalRequestName requestName = new GlobalRequestName(); // TODO: Initialize to an appropriate value
-            bool wantReply = false; // TODO: Initialize to an appropriate value
-            string addressToBind = string.Empty; // TODO: Initialize to an appropriate value
-            uint portToBind = 0; // TODO: Initialize to an appropriate value
-            GlobalRequestMessage target = new GlobalRequestMessage(requestName, wantReply, addressToBind, portToBind);
-            Assert.Inconclusive("TODO: Implement code to verify target");
+            var requestName = new Random().Next().ToString(CultureInfo.InvariantCulture);
+
+            var target = new GlobalRequestMessage(Encoding.ASCII.GetBytes(requestName), true);
+            Assert.AreEqual(requestName, target.RequestName);
+            Assert.IsTrue(target.WantReply);
+
+            target = new GlobalRequestMessage(Encoding.ASCII.GetBytes(requestName), false);
+            Assert.AreEqual(requestName, target.RequestName);
+            Assert.IsFalse(target.WantReply);
         }
     }
 }

+ 42 - 2
src/Renci.SshNet.Tests/Classes/Messages/Transport/IgnoreMessageTest.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Globalization;
 using System.Linq;
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Transport;
@@ -38,7 +39,7 @@ namespace Renci.SshNet.Tests.Classes.Messages.Transport
         [TestMethod]
         public void Constructor_Data_ShouldThrowArgumentNullExceptionWhenDataIsNull()
         {
-            byte[] data = null;
+            const byte[] data = null;
 
             try
             {
@@ -85,11 +86,50 @@ namespace Renci.SshNet.Tests.Classes.Messages.Transport
             var bytes = ignoreMessage.GetBytes();
             var target = new IgnoreMessage();
 
-            target.Load(bytes);
+            target.Load(bytes, 1, bytes.Length - 1);
 
             Assert.IsNotNull(target.Data);
             Assert.AreEqual(_data.Length, target.Data.Length);
             Assert.IsTrue(target.Data.SequenceEqual(_data));
         }
+
+        [TestMethod]
+        public void Load_ShouldIgnoreDataWhenItsLengthIsGreatherThanItsActualBytes()
+        {
+            var ssh = new SshDataStream(1);
+            ssh.WriteByte(2); // Type
+            ssh.Write(5u); // Data length
+            ssh.Write(new byte[3]); // Data
+
+            var ignoreMessageBytes = ssh.ToArray();
+
+            var ignoreMessage = new IgnoreMessage();
+            ignoreMessage.Load(ignoreMessageBytes, 1, ignoreMessageBytes.Length - 1);
+            Assert.IsNotNull(ignoreMessage.Data);
+            Assert.AreEqual(0, ignoreMessage.Data.Length);
+        }
+
+        [TestMethod]
+        public void Load_ShouldThrowNotSupportedExceptionWhenDataLengthIsGreaterThanInt32MaxValue()
+        {
+            var ssh = new SshDataStream(1);
+            ssh.WriteByte(2); // Type
+            ssh.Write(uint.MaxValue); // Data length
+            ssh.Write(new byte[3]);
+
+            var ignoreMessageBytes = ssh.ToArray();
+            var ignoreMessage = new IgnoreMessage();
+
+            try
+            {
+                ignoreMessage.Load(ignoreMessageBytes, 1, ignoreMessageBytes.Length - 1);
+                Assert.Fail();
+            }
+            catch (NotSupportedException ex)
+            {
+                Assert.IsNull(ex.InnerException);
+                Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "Data longer than {0} is not supported.", int.MaxValue), ex.Message);
+            }
+        }
     }
 }

文件差异内容过多而无法显示
+ 0 - 0
src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeReplyTest.cs


+ 1 - 1
src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeRequestTest.cs

@@ -60,7 +60,7 @@ namespace Renci.SshNet.Tests.Classes.Messages.Transport
             var bytes = request.GetBytes();
             var target = new KeyExchangeDhGroupExchangeRequest(0, 0, 0);
 
-            target.Load(bytes);
+            target.Load(bytes, 1, bytes.Length - 1);
 
             Assert.AreEqual(_minimum, target.Minimum);
             Assert.AreEqual(_preferred, target.Preferred);

文件差异内容过多而无法显示
+ 0 - 0
src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeInitMessageTest.cs


+ 2 - 3
src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Connected.cs

@@ -45,7 +45,6 @@ namespace Renci.SshNet.Tests.Classes
             _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect());
             _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting());
             _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect());
-            _sessionMock.InSequence(sequence).Setup(p => p.Disconnect());
             _sessionMock.InSequence(sequence).Setup(p => p.Dispose());
             _netConfSessionMock.InSequence(sequence).Setup(p => p.Dispose());
 
@@ -76,9 +75,9 @@ namespace Renci.SshNet.Tests.Classes
         }
 
         [TestMethod]
-        public void DisconnectOnSessionShouldBeInvokedOnce()
+        public void DisconnectOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]

+ 2 - 3
src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disconnected.cs

@@ -45,7 +45,6 @@ namespace Renci.SshNet.Tests.Classes
             _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect());
             _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting());
             _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect());
-            _sessionMock.InSequence(sequence).Setup(p => p.Disconnect());
             _sessionMock.InSequence(sequence).Setup(p => p.Dispose());
             _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect());
             _netConfSessionMock.InSequence(sequence).Setup(p => p.Dispose());
@@ -78,9 +77,9 @@ namespace Renci.SshNet.Tests.Classes
         }
 
         [TestMethod]
-        public void DisconnectOnSessionShouldBeInvokedOnce()
+        public void DisconnectOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]

+ 2 - 3
src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disposed.cs

@@ -45,7 +45,6 @@ namespace Renci.SshNet.Tests.Classes
             _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect());
             _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting());
             _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect());
-            _sessionMock.InSequence(sequence).Setup(p => p.Disconnect());
             _sessionMock.InSequence(sequence).Setup(p => p.Dispose());
             _netConfSessionMock.InSequence(sequence).Setup(p => p.Dispose());
 
@@ -77,9 +76,9 @@ namespace Renci.SshNet.Tests.Classes
         }
 
         [TestMethod]
-        public void DisconnectOnSessionShouldBeInvokedOnce()
+        public void DisconnectOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]

+ 14 - 14
src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs

@@ -140,7 +140,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_RSA()
         {
-            using (var stream = this.GetData("Key.RSA.txt"))
+            using (var stream = GetData("Key.RSA.txt"))
             {
                 new PrivateKeyFile(stream);
             }
@@ -151,7 +151,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_SSH2_DSA()
         {
-            using (var stream = this.GetData("Key.SSH2.DSA.txt"))
+            using (var stream = GetData("Key.SSH2.DSA.txt"))
             {
                 new PrivateKeyFile(stream);
             }
@@ -162,7 +162,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_SSH2_RSA()
         {
-            using (var stream = this.GetData("Key.SSH2.RSA.txt"))
+            using (var stream = GetData("Key.SSH2.RSA.txt"))
             {
                 new PrivateKeyFile(stream);
             }
@@ -173,7 +173,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_SSH2_Encrypted_DSA_DES_CBC()
         {
-            using (var stream = this.GetData("Key.SSH2.DSA.Encrypted.Des.CBC.12345.txt"))
+            using (var stream = GetData("Key.SSH2.DSA.Encrypted.Des.CBC.12345.txt"))
             {
                 new PrivateKeyFile(stream, "12345");
             }
@@ -184,7 +184,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_SSH2_Encrypted_RSA_DES_CBC()
         {
-            using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt"))
+            using (var stream = GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt"))
             {
                 new PrivateKeyFile(stream, "12345");
             }
@@ -195,7 +195,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshExceptionWhenPassphraseIsWrong()
         {
-            using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt"))
+            using (var stream = GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt"))
             {
                 try
                 {
@@ -216,7 +216,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsNull()
         {
-            using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt"))
+            using (var stream = GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt"))
             {
                 try
                 {
@@ -237,7 +237,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsEmpty()
         {
-            using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt"))
+            using (var stream = GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt"))
             {
                 try
                 {
@@ -258,7 +258,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_RSA_DES_CBC()
         {
-            using (var stream = this.GetData("Key.RSA.Encrypted.Des.CBC.12345.txt"))
+            using (var stream = GetData("Key.RSA.Encrypted.Des.CBC.12345.txt"))
             {
                 new PrivateKeyFile(stream, "12345");
             }
@@ -269,7 +269,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_RSA_DES_EDE3_CBC()
         {
-            using (var stream = this.GetData("Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt"))
+            using (var stream = GetData("Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt"))
             {
                 new PrivateKeyFile(stream, "12345");
             }
@@ -280,7 +280,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_RSA_AES_128_CBC()
         {
-            using (var stream = this.GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt"))
+            using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt"))
             {
                 new PrivateKeyFile(stream, "12345");
             }
@@ -291,7 +291,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_RSA_AES_192_CBC()
         {
-            using (var stream = this.GetData("Key.RSA.Encrypted.Aes.192.CBC.12345.txt"))
+            using (var stream = GetData("Key.RSA.Encrypted.Aes.192.CBC.12345.txt"))
             {
                 new PrivateKeyFile(stream, "12345");
             }
@@ -302,7 +302,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_RSA_AES_256_CBC()
         {
-            using (var stream = this.GetData("Key.RSA.Encrypted.Aes.256.CBC.12345.txt"))
+            using (var stream = GetData("Key.RSA.Encrypted.Aes.256.CBC.12345.txt"))
             {
                 new PrivateKeyFile(stream, "12345");
             }
@@ -313,7 +313,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("PrivateKey")]
         public void Test_PrivateKey_RSA_DES_EDE3_CFB()
         {
-            using (var stream = this.GetData("Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt"))
+            using (var stream = GetData("Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt"))
             {
                 new PrivateKeyFile(stream, "1234567890");
             }

+ 0 - 6
src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs

@@ -101,12 +101,6 @@ namespace Renci.SshNet.Tests.Classes
             _channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t \"{0}\"", _path)), Times.Once);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldNeverBeInvoked()
-        {
-            _channelSessionMock.Verify(p => p.Close(), Times.Never);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {

+ 0 - 7
src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs

@@ -101,7 +101,6 @@ namespace Renci.SshNet.Tests.Classes
                 .Setup(
                     p => p.SendData(It.Is<byte[]>(b => b.SequenceEqual(new byte[] {0}))));
             _pipeStreamMock.InSequence(sequence).Setup(p => p.ReadByte()).Returns(0);
-            _channelSessionMock.InSequence(sequence).Setup(p => p.Close());
             _channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
             _pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose());
         }
@@ -131,12 +130,6 @@ namespace Renci.SshNet.Tests.Classes
             _channelSessionMock.Verify(p => p.SendExecRequest(string.Format("scp -t \"{0}\"", _path)), Times.Once);
         }
 
-        [TestMethod]
-        public void CloseOnChannelShouldBeInvokedOnce()
-        {
-            _channelSessionMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void DisposeOnChannelShouldBeInvokedOnce()
         {

+ 41 - 15
src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs

@@ -1,11 +1,8 @@
-using System;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+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
 {
@@ -16,21 +13,36 @@ namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers
     public class AesCipherTest : TestBase
     {
         [TestMethod]
-        public void Test_Cipher_AES_128_CBC()
+        public void Encrypt_Input_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 expected = 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");
+            var actual = testCipher.Encrypt(input);
+
+            Assert.IsTrue(actual.IsEqualTo(expected));
         }
 
         [TestMethod]
-        public void Test_Cipher_AES_128_CTR()
+        public void Encrypt_InputAndOffsetAndLength_128_CBC()
+        {
+            // 2 dummy bytes before and 3 after the input from test case above
+            var input = new byte[] { 0x05, 0x07, 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, 0x0f, 0x0d, 0x03 };
+            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 expected = 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 actual = testCipher.Encrypt(input, 2, input.Length - 5);
+
+            Assert.IsTrue(actual.IsEqualTo(expected));
+        }
+
+        [TestMethod]
+        public void Encrypt_Input_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 };
@@ -44,17 +56,31 @@ namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers
         }
 
         [TestMethod]
-        public void Decrypt_AES_128_CTR()
+        public void Decrypt_Input_128_CTR()
+        {
+            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 input = 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 expected = 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 testCipher = new AesCipher(key, new CtrCipherMode(iv), null);
+
+            var actual = testCipher.Decrypt(input);
+
+            Assert.IsTrue(expected.IsEqualTo(actual));
+        }
+
+        [TestMethod]
+        public void Decrypt_InputAndOffsetAndLength_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 input = new byte[] { 0x0a, 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, 0x0a, 0x05 };
+            var expected = 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 testCipher = new AesCipher(key, new CtrCipherMode(iv), null);
 
-            var actual = testCipher.Decrypt(output);
+            var actual = testCipher.Decrypt(input, 1, input.Length - 3);
 
-            Assert.IsTrue(input.IsEqualTo(actual));
+            Assert.IsTrue(expected.IsEqualTo(actual));
         }
 
         [TestMethod]

+ 34 - 17
src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs

@@ -1,6 +1,5 @@
 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;
@@ -53,6 +52,20 @@ namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers
             Assert.AreEqual(expectedPlainText, encoding.GetString(actualPlainText));
         }
 
+        [TestMethod]
+        public void Decrypt_InputAndOffsetAndLength()
+        {
+            const string key = "Key";
+            const string expectedPlainText = "Plaintext";
+            var encoding = Encoding.ASCII;
+            var cipher = new Arc4Cipher(encoding.GetBytes(key), false);
+            var cipherText = new byte[] { 0x0A, 0x0f, 0xBB, 0xF3, 0x16, 0xE8, 0xD9, 0x40, 0xAF, 0x0A, 0xD3, 0x0d, 0x05 };
+
+            var actualPlainText = cipher.Decrypt(cipherText, 2, cipherText.Length - 4);
+
+            Assert.AreEqual(expectedPlainText, encoding.GetString(actualPlainText));
+        }
+
         /// <summary>
         ///A test for DecryptBlock
         ///</summary>
@@ -86,16 +99,7 @@ namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers
             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]);
+            Assert.IsTrue(expectedCipherText.IsEqualTo(actualCipherText));
         }
 
         [TestMethod]
@@ -110,12 +114,25 @@ namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers
             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.IsTrue(expectedCipherText.IsEqualTo(actualCipherText));
+        }
+
+        [TestMethod]
+        public void Encrypt_InputAndOffsetAndLength()
+        {
+            const string key = "Wiki";
+            const string plainText = "NOpediaNO";
+            var encoding = Encoding.ASCII;
+            var cipher = new Arc4Cipher(encoding.GetBytes(key), false);
+            var plainTextBytes = encoding.GetBytes(plainText);
+            var expectedCipherText = new byte[] { 0x10, 0X21, 0xBF, 0x04, 0x20 };
+
+            var actualCipherText = cipher.Encrypt(plainTextBytes, 2, plainTextBytes.Length - 4);
+
+            Assert.IsNotNull(actualCipherText);
+            Assert.IsTrue(expectedCipherText.IsEqualTo(actualCipherText));
+
+            Assert.IsTrue(plainTextBytes.IsEqualTo(encoding.GetBytes(plainText)));
         }
 
         /// <summary>

+ 1 - 1
src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CastCipherTest.cs

@@ -20,7 +20,7 @@ namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers
             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 testCipher = new CastCipher(key, new CbcCipherMode(iv), null);
             var r = testCipher.Encrypt(input);
 
             if (!r.SequenceEqual(output))

+ 45 - 26
src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs

@@ -1,42 +1,61 @@
 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
 {
-    /// <summary>
-    ///This is a test class for PKCS5PaddingTest and is intended
-    ///to contain all PKCS5PaddingTest Unit Tests
-    ///</summary>
     [TestClass]
-    public class PKCS5PaddingTest : TestBase
+    public class PKCS5PaddingTest
     {
-        /// <summary>
-        ///A test for Pad
-        ///</summary>
+        private PKCS5Padding _padding;
+
+        [TestInitialize]
+        public void SetUp()
+        {
+            _padding = new PKCS5Padding();
+        }
+
+        [TestMethod]
+        public void Pad_BlockSizeAndInput_LessThanBlockSize()
+        {
+            var input = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05};
+            var expected = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x03, 0x03, 0x03};
+
+            var actual = _padding.Pad(8, input);
+
+            Assert.IsTrue(expected.IsEqualTo(actual));
+        }
+
         [TestMethod]
-        [Ignore] // placeholder for actual test
-        public void PadTest()
+        public void Pad_BlockSizeAndInput_MoreThanBlockSizeButNoMultipleOfBlockSize()
         {
-            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.");
+            var input = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
+            var expected = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07 };
+
+            var actual = _padding.Pad(8, input);
+
+            Assert.IsTrue(expected.IsEqualTo(actual));
+        }
+
+        [TestMethod]
+        public void Pad_BlockSizeAndInputAndOffsetAndLength_LessThanBlockSize()
+        {
+            var input = new byte[] { 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+            var expected = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x03, 0x03, 0x03 };
+
+            var actual = _padding.Pad(8, input, 1, input.Length - 2);
+
+            Assert.IsTrue(expected.IsEqualTo(actual));
         }
 
-        /// <summary>
-        ///A test for PKCS5Padding Constructor
-        ///</summary>
         [TestMethod]
-        [Ignore] // placeholder
-        public void PKCS5PaddingConstructorTest()
+        public void Pad_BlockSizeAndInputAndOffsetAndLength_MoreThanBlockSizeButNoMultipleOfBlockSize()
         {
-            PKCS5Padding target = new PKCS5Padding();
-            Assert.Inconclusive("TODO: Implement code to verify target");
+            var input = new byte[] { 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10 };
+            var expected = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07 };
+
+            var actual = _padding.Pad(8, input, 1, input.Length - 2);
+
+            Assert.IsTrue(expected.IsEqualTo(actual));
         }
     }
 }

+ 46 - 27
src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs

@@ -1,42 +1,61 @@
 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
 {
-    /// <summary>
-    ///This is a test class for PKCS7PaddingTest and is intended
-    ///to contain all PKCS7PaddingTest Unit Tests
-    ///</summary>
-    [TestClass()]
-    public class PKCS7PaddingTest : TestBase
+    [TestClass]
+    public class PKCS7PaddingTest
     {
-        /// <summary>
-        ///A test for Pad
-        ///</summary>
+        private PKCS7Padding _padding;
+
+        [TestInitialize]
+        public void SetUp()
+        {
+            _padding = new PKCS7Padding();
+        }
+
+        [TestMethod]
+        public void Pad_BlockSizeAndInput_LessThanBlockSize()
+        {
+            var input = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
+            var expected = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x03, 0x03, 0x03 };
+
+            var actual = _padding.Pad(8, input);
+
+            Assert.IsTrue(expected.IsEqualTo(actual));
+        }
+
         [TestMethod]
-        [Ignore] // placeholder for actual test
-        public void PadTest()
+        public void Pad_BlockSizeAndInput_MoreThanBlockSizeButNoMultipleOfBlockSize()
         {
-            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.");
+            var input = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
+            var expected = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07 };
+
+            var actual = _padding.Pad(8, input);
+
+            Assert.IsTrue(expected.IsEqualTo(actual));
+        }
+
+        [TestMethod]
+        public void Pad_BlockSizeAndInputAndOffsetAndLength_LessThanBlockSize()
+        {
+            var input = new byte[] { 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+            var expected = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x03, 0x03, 0x03 };
+
+            var actual = _padding.Pad(8, input, 1, input.Length - 2);
+
+            Assert.IsTrue(expected.IsEqualTo(actual));
         }
 
-        /// <summary>
-        ///A test for PKCS7Padding Constructor
-        ///</summary>
         [TestMethod]
-        [Ignore] // placeholder
-        public void PKCS7PaddingConstructorTest()
+        public void Pad_BlockSizeAndInputAndOffsetAndLength_MoreThanBlockSizeButNoMultipleOfBlockSize()
         {
-            PKCS7Padding target = new PKCS7Padding();
-            Assert.Inconclusive("TODO: Implement code to verify target");
+            var input = new byte[] { 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10 };
+            var expected = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07 };
+
+            var actual = _padding.Pad(8, input, 1, input.Length - 2);
+
+            Assert.IsTrue(expected.IsEqualTo(actual));
         }
     }
 }

+ 1 - 1
src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TripleDesCipherTest.cs

@@ -20,7 +20,7 @@ namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers
             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 testCipher = new TripleDesCipher(key, new CbcCipherMode(iv), null);
             var r = testCipher.Encrypt(input);
 
             if (!r.SequenceEqual(output))

+ 2 - 2
src/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs

@@ -10,9 +10,9 @@ namespace Renci.SshNet.Tests.Classes
     {
         private IgnoreMessage _ignoreMessage;
 
-        protected override void Arrange()
+        protected override void SetupData()
         {
-            base.Arrange();
+            base.SetupData();
 
             var data = new byte[10];
             Random.NextBytes(data);

+ 59 - 36
src/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs

@@ -47,18 +47,26 @@ namespace Renci.SshNet.Tests.Classes
         [TestCleanup]
         public void TearDown()
         {
+            if (ServerSocket != null)
+            {
+                ServerSocket.Dispose();
+                ServerSocket = null;
+            }
+
             if (ServerListener != null)
             {
                 ServerListener.Dispose();
+                ServerListener = null;
             }
 
             if (Session != null)
             {
                 Session.Dispose();
+                Session = null;
             }
         }
 
-        protected virtual void Arrange()
+        protected virtual void SetupData()
         {
             Random = new Random();
 
@@ -67,8 +75,8 @@ namespace Renci.SshNet.Tests.Classes
                 _serverEndPoint.Address.ToString(),
                 _serverEndPoint.Port,
                 "user",
-                new PasswordAuthenticationMethod("user", "password"));
-            ConnectionInfo.Timeout = TimeSpan.FromSeconds(20);
+                new PasswordAuthenticationMethod("user", "password"))
+            {Timeout = TimeSpan.FromSeconds(20)};
             _keyExchangeAlgorithm = Random.Next().ToString(CultureInfo.InvariantCulture);
             SessionId = new byte[10];
             Random.NextBytes(SessionId);
@@ -77,10 +85,6 @@ namespace Renci.SshNet.Tests.Classes
             ErrorOccurredRegister = new List<ExceptionEventArgs>();
             ServerBytesReceivedRegister = new List<byte[]>();
 
-            _serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
-            _keyExchangeMock = new Mock<IKeyExchange>(MockBehavior.Strict);
-            _clientAuthenticationMock = new Mock<IClientAuthentication>(MockBehavior.Strict);
-
             Session = new Session(ConnectionInfo, _serviceFactoryMock.Object);
             Session.Disconnected += (sender, args) => DisconnectedRegister.Add(args);
             Session.DisconnectReceived += (sender, args) => DisconnectReceivedRegister.Add(args);
@@ -92,22 +96,6 @@ namespace Renci.SshNet.Tests.Classes
                     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<KeyExchangeInitMessage>()));
-            _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 =>
                 {
@@ -128,18 +116,18 @@ namespace Renci.SshNet.Tests.Classes
                     {
                         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]
-                                };
+                            {
+                                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;
@@ -151,8 +139,43 @@ namespace Renci.SshNet.Tests.Classes
                             break;
                     }
                 };
-            ServerListener.Start();
+        }
+
+        private void CreateMocks()
+        {
+            _serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
+            _keyExchangeMock = new Mock<IKeyExchange>(MockBehavior.Strict);
+            _clientAuthenticationMock = new Mock<IClientAuthentication>(MockBehavior.Strict);
+        }
 
+        private void SetupMocks()
+        {
+            _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<KeyExchangeInitMessage>()));
+            _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));
+        }
+
+        protected virtual void Arrange()
+        {
+            CreateMocks();
+            SetupData();
+            SetupMocks();
+
+            ServerListener.Start();
             Session.Connect();
         }
 

+ 2 - 1
src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs

@@ -4,6 +4,7 @@ using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Transport;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes
 {
@@ -51,7 +52,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void ErrorOccurredIsRaisedOnce()
         {
-            Assert.AreEqual(1, ErrorOccurredRegister.Count);
+            Assert.AreEqual(1, ErrorOccurredRegister.Count, ErrorOccurredRegister.AsString());
 
             var errorOccurred = ErrorOccurredRegister[0];
             Assert.IsNotNull(errorOccurred);

+ 11 - 2
src/Renci.SshNet.Tests/Classes/SessionTest_Connected_GlobalRequestMessageAfterAuthenticationRace.cs

@@ -1,4 +1,5 @@
 using System.Net.Sockets;
+using System.Text;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Messages.Connection;
 
@@ -10,14 +11,22 @@ namespace Renci.SshNet.Tests.Classes
     [TestClass]
     public class SessionTest_Connected_GlobalRequestMessageAfterAuthenticationRace : SessionTest_ConnectedBase
     {
+        private GlobalRequestMessage _globalRequestMessage;
+
+        protected override void SetupData()
+        {
+            base.SetupData();
+
+            _globalRequestMessage = new GlobalRequestMessage(Encoding.ASCII.GetBytes("ping-mocana-com"), false);
+        }
+
         protected override void Act()
         {
         }
 
         protected override void ClientAuthentication_Callback()
         {
-            var globalRequestMessage = new GlobalRequestMessage(GlobalRequestName.TcpIpForward, false, "address", 70);
-            var globalRequest = globalRequestMessage.GetPacket(8, null);
+            var globalRequest = _globalRequestMessage.GetPacket(8, null);
             ServerSocket.Send(globalRequest, 4, globalRequest.Length - 4, SocketFlags.None);
         }
 

+ 210 - 0
src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerAndClientDisconnectRace.cs

@@ -0,0 +1,210 @@
+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 class SessionTest_Connected_ServerAndClientDisconnectRace
+    {
+        private Mock<IServiceFactory> _serviceFactoryMock;
+        private Mock<IKeyExchange> _keyExchangeMock;
+        private Mock<IClientAuthentication> _clientAuthenticationMock;
+        private IPEndPoint _serverEndPoint;
+        private string _keyExchangeAlgorithm;
+        private DisconnectMessage _disconnectMessage;
+
+        protected Random Random { get; private set; }
+        protected byte[] SessionId { get; private set; }
+        protected ConnectionInfo ConnectionInfo { get; private set; }
+        protected IList<EventArgs> DisconnectedRegister { get; private set; }
+        protected IList<MessageEventArgs<DisconnectMessage>> DisconnectReceivedRegister { get; private set; }
+        protected IList<ExceptionEventArgs> ErrorOccurredRegister { get; private set; }
+        protected AsyncSocketListener ServerListener { get; private set; }
+        protected IList<byte[]> ServerBytesReceivedRegister { get; private set; }
+        protected Session Session { get; private set; }
+        protected Socket ServerSocket { get; private set; }
+
+        private void TearDown()
+        {
+            if (ServerListener != null)
+            {
+                ServerListener.Dispose();
+            }
+
+            if (Session != null)
+            {
+                Session.Dispose();
+            }
+        }
+
+        protected virtual void SetupData()
+        {
+            Random = new Random();
+
+            _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
+            ConnectionInfo = new ConnectionInfo(
+                _serverEndPoint.Address.ToString(),
+                _serverEndPoint.Port,
+                "user",
+                new PasswordAuthenticationMethod("user", "password"))
+            { Timeout = TimeSpan.FromSeconds(20) };
+            _keyExchangeAlgorithm = Random.Next().ToString(CultureInfo.InvariantCulture);
+            SessionId = new byte[10];
+            Random.NextBytes(SessionId);
+            DisconnectedRegister = new List<EventArgs>();
+            DisconnectReceivedRegister = new List<MessageEventArgs<DisconnectMessage>>();
+            ErrorOccurredRegister = new List<ExceptionEventArgs>();
+            ServerBytesReceivedRegister = new List<byte[]>();
+            _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!");
+
+            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);
+            };
+
+            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;
+                }
+            };
+        }
+
+        private void CreateMocks()
+        {
+            _serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
+            _keyExchangeMock = new Mock<IKeyExchange>(MockBehavior.Strict);
+            _clientAuthenticationMock = new Mock<IClientAuthentication>(MockBehavior.Strict);
+        }
+
+        private void SetupMocks()
+        {
+            _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<KeyExchangeInitMessage>()));
+            _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()).Returns(_clientAuthenticationMock.Object);
+            _clientAuthenticationMock.Setup(p => p.Authenticate(ConnectionInfo, Session));
+        }
+
+        protected virtual void Arrange()
+        {
+            CreateMocks();
+            SetupData();
+            SetupMocks();
+
+            ServerListener.Start();
+            Session.Connect();
+        }
+
+        [TestMethod]
+        public  void Act()
+        {
+            for (var i = 0; i < 50; i++)
+            {
+                Arrange();
+                try
+                {
+                    var disconnect = _disconnectMessage.GetPacket(8, null);
+                    ServerSocket.Send(disconnect, 4, disconnect.Length - 4, SocketFlags.None);
+                    Session.Disconnect();
+                }
+                finally
+                {
+                    TearDown();
+                }
+            }
+        }
+
+        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();
+            }
+        }
+    }
+}

+ 2 - 1
src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs

@@ -4,6 +4,7 @@ using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Transport;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes
 {
@@ -52,7 +53,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void ErrorOccurredIsRaisedOnce()
         {
-            Assert.AreEqual(1, ErrorOccurredRegister.Count);
+            Assert.AreEqual(1, ErrorOccurredRegister.Count, ErrorOccurredRegister.AsString());
 
             var errorOccurred = ErrorOccurredRegister[0];
             Assert.IsNotNull(errorOccurred);

+ 4 - 6
src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessage.cs

@@ -8,16 +8,15 @@ 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()
+        protected override void SetupData()
         {
-            _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!");
+            base.SetupData();
 
-            base.Arrange();
+            _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!");
         }
 
         protected override void Act()
@@ -25,8 +24,7 @@ namespace Renci.SshNet.Tests.Classes
             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);
+            Session.Disconnect();
         }
 
         [TestMethod]

+ 4 - 4
src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket.cs

@@ -13,11 +13,11 @@ namespace Renci.SshNet.Tests.Classes
     {
         private DisconnectMessage _disconnectMessage;
 
-        protected override void Arrange()
+        protected override void SetupData()
         {
-            _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!");
+            base.SetupData();
 
-            base.Arrange();
+            _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!");
         }
 
         protected override void Act()
@@ -116,7 +116,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void ISession_MessageListenerCompletedShouldBeSignaled()
         {
-            var session = (ISession)Session;
+            var session = (ISession) Session;
 
             Assert.IsNotNull(session.MessageListenerCompleted);
             Assert.IsTrue(session.MessageListenerCompleted.WaitOne());

+ 167 - 0
src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSendAfterSendingIncompletePacket.cs

@@ -0,0 +1,167 @@
+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;
+using Renci.SshNet.Tests.Common;
+
+namespace Renci.SshNet.Tests.Classes
+{
+    [TestClass]
+    public class SessionTest_Connected_ServerShutsDownSendAfterSendingIncompletePacket : SessionTest_ConnectedBase
+    {
+        protected override void Act()
+        {
+            var incompletePacket = new byte[] {0x0a, 0x05, 0x05};
+            ServerSocket.Send(incompletePacket, 0, incompletePacket.Length, SocketFlags.None);
+
+            // give session some time to start reading packet
+            Thread.Sleep(100);
+
+            ServerSocket.Shutdown(SocketShutdown.Send);
+
+            // give session some time to process shut down of server socket
+            Thread.Sleep(100);
+        }
+
+        [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, ErrorOccurredRegister.AsString());
+
+            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 SendMessageShouldSucceed()
+        {
+            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());
+        }
+
+        [TestMethod]
+        public void ISession_SendMessageShouldSucceed()
+        {
+            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_TrySendMessageShouldReturnTrue()
+        {
+            var session = (ISession) Session;
+
+            Assert.IsFalse(session.TrySendMessage(new IgnoreMessage()));
+        }
+
+        [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.ConnectionLost, ex.DisconnectReason);
+                Assert.IsNull(ex.InnerException);
+                Assert.AreEqual("An established connection was aborted by the server.", ex.Message);
+            }
+        }
+    }
+}

+ 3 - 3
src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs

@@ -1,10 +1,10 @@
-using System;
-using System.Diagnostics;
+using System.Diagnostics;
 using System.Net.Sockets;
 using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Transport;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes
 {
@@ -52,7 +52,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void ErrorOccurredIsRaisedOnce()
         {
-            Assert.AreEqual(1, ErrorOccurredRegister.Count);
+            Assert.AreEqual(1, ErrorOccurredRegister.Count, ErrorOccurredRegister.AsString());
 
             var errorOccurred = ErrorOccurredRegister[0];
             Assert.IsNotNull(errorOccurred);

+ 17 - 12
src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpWriteRequestTest.cs

@@ -15,8 +15,9 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Requests
         private uint _protocolVersion;
         private uint _requestId;
         private byte[] _handle;
-        private ulong _offset;
+        private ulong _serverFileOffset;
         private byte[] _data;
+        private int _offset;
         private int _length;
 
         [TestInitialize]
@@ -24,26 +25,29 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Requests
         {
             var random = new Random();
 
-            _protocolVersion = (uint)random.Next(0, int.MaxValue);
-            _requestId = (uint)random.Next(0, int.MaxValue);
+            _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)];
+            _serverFileOffset = (ulong) random.Next(0, int.MaxValue);
+            _data = new byte[random.Next(10, 15)];
             random.NextBytes(_data);
-            _length = random.Next(1, 4);
+            _offset = random.Next(0, _data.Length - 1);
+            _length = random.Next(0, _data.Length - _offset);
         }
 
         [TestMethod]
         public void Constructor()
         {
-            var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _offset, _data, _length, null);
+            var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _serverFileOffset, _data, _offset, _length, null);
 
             Assert.AreSame(_data, request.Data);
             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(_serverFileOffset, request.ServerFileOffset);
             Assert.AreEqual(SftpMessageTypes.Write, request.SftpMessageType);
         }
 
@@ -58,8 +62,9 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Requests
                 _protocolVersion,
                 _requestId,
                 _handle,
-                _offset,
+                _serverFileOffset,
                 _data,
+                _offset,
                 _length,
                 statusAction);
 
@@ -72,7 +77,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Requests
         [TestMethod]
         public void GetBytes()
         {
-            var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _offset, _data, _length, null);
+            var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _serverFileOffset, _data, _offset, _length, null);
 
             var bytes = request.GetBytes();
 
@@ -82,7 +87,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Requests
             expectedBytesLength += 4; // RequestId
             expectedBytesLength += 4; // Handle length
             expectedBytesLength += _handle.Length; // Handle
-            expectedBytesLength += 8; // Offset
+            expectedBytesLength += 8; // ServerFileOffset
             expectedBytesLength += 4; // Data length
             expectedBytesLength += _length; // Data
 
@@ -99,12 +104,12 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Requests
             sshDataStream.Read(actualHandle, 0, actualHandle.Length);
             Assert.IsTrue(_handle.SequenceEqual(actualHandle));
 
-            Assert.AreEqual(_offset, sshDataStream.ReadUInt64());
+            Assert.AreEqual(_serverFileOffset, 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(_data.Take(_offset, _length).SequenceEqual(actualData));
 
             Assert.IsTrue(sshDataStream.IsEndOfData);
         }

+ 0 - 2
src/Renci.SshNet.Tests/Classes/Sftp/Responses/ExtendedReplies/StatVfsReplyInfoTest.cs

@@ -53,8 +53,6 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Responses
             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);

+ 1 - 4
src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpAttrsResponseTest.cs

@@ -3,7 +3,6 @@ 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
 {
@@ -40,9 +39,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Responses
             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);
+            var sshDataStream = new SshDataStream(4 + attributesBytes.Length);
             sshDataStream.Write(_responseId);
             sshDataStream.Write(attributesBytes, 0, attributesBytes.Length);
 

+ 4 - 4
src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpDataResponseTest.cs

@@ -41,14 +41,14 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Responses
         {
             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);
+            var sshDataStream = new SshDataStream(4 + _data.Length);
             sshDataStream.Write(_responseId);
             sshDataStream.Write((uint) _data.Length);
             sshDataStream.Write(_data, 0, _data.Length);
 
-            target.Load(sshDataStream.ToArray());
+            var sshData = sshDataStream.ToArray();
+
+            target.Load(sshData);
 
             Assert.IsNotNull(target.Data);
             Assert.IsTrue(target.Data.SequenceEqual(_data));

+ 5 - 5
src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpExtendedReplyResponseTest.cs

@@ -36,9 +36,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Responses
         {
             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);
+            var sshDataStream = new SshDataStream(4);
             sshDataStream.Write(_responseId);
 
             target.Load(sshDataStream.ToArray());
@@ -64,7 +62,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Responses
 
             var sshDataStream = new SshDataStream(4 + 1 + 4 + 88);
             sshDataStream.Position = 4; // skip 4 bytes for SSH packet length
-            sshDataStream.WriteByte((byte) SftpMessageTypes.Attrs);
+            sshDataStream.WriteByte((byte)SftpMessageTypes.Attrs);
             sshDataStream.Write(_responseId);
             sshDataStream.Write(bsize);
             sshDataStream.Write(frsize);
@@ -78,8 +76,10 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Responses
             sshDataStream.Write((ulong) 0x2);
             sshDataStream.Write(namemax);
 
+            var sshData = sshDataStream.ToArray();
+
             var target = new SftpExtendedReplyResponse(_protocolVersion);
-            target.Load(sshDataStream.ToArray());
+            target.Load(sshData, 5, sshData.Length - 5);
 
             var reply = target.GetReply<StatVfsReplyInfo>();
             Assert.IsNotNull(reply);

+ 1 - 3
src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpHandleResponseTest.cs

@@ -41,9 +41,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp.Responses
         {
             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);
+            var sshDataStream = new SshDataStream(4 + _handle.Length);
             sshDataStream.Write(_responseId);
             sshDataStream.Write((uint) _handle.Length);
             sshDataStream.Write(_handle, 0, _handle.Length);

+ 187 - 0
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs

@@ -0,0 +1,187 @@
+using System;
+using System.Globalization;
+using System.IO;
+using System.Threading;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+using Renci.SshNet.Sftp;
+using Renci.SshNet.Sftp.Responses;
+
+namespace Renci.SshNet.Tests.Classes.Sftp
+{
+    [TestClass]
+    public class SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize
+    {
+        private Mock<ISftpSession> _sftpSessionMock;
+        private string _path;
+        private SftpFileStream _sftpFileStream;
+        private byte[] _handle;
+        private SftpFileAttributes _fileAttributes;
+        private uint _bufferSize;
+        private uint _readBufferSize;
+        private uint _writeBufferSize;
+        private byte[] _data;
+        private int _count;
+        private int _offset;
+        private MockSequence _sequence;
+        private Random _random;
+        private uint _expectedWrittenByteCount;
+        private int _expectedBufferedByteCount;
+        private byte[] _expectedBufferedBytes;
+
+        [TestInitialize]
+        public void Setup()
+        {
+            Arrange();
+            Act();
+        }
+
+        [TestCleanup]
+        public void TearDown()
+        {
+            if (_sftpSessionMock != null)
+            {
+                // allow Dispose to complete successfully
+                _sftpSessionMock.InSequence(_sequence)
+                    .Setup(p => p.IsOpen)
+                    .Returns(true);
+                _sftpSessionMock.InSequence(_sequence)
+                    .Setup(p => p.RequestWrite(_handle, _expectedWrittenByteCount, It.IsAny<byte[]>(), 0, _expectedBufferedByteCount, It.IsAny<AutoResetEvent>(), null));
+                _sftpSessionMock.InSequence(_sequence)
+                    .Setup(p => p.RequestClose(_handle));
+            }
+        }
+
+        protected void Arrange()
+        {
+            _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(500, 1000);
+            _data = new byte[(_writeBufferSize  * 2) + 15];
+            _random.NextBytes(_data);
+            _offset = _random.Next(1, 5);
+            // to get multiple SSH_FXP_WRITE messages (and verify the offset is updated correctly), we make sure
+            // the number of bytes to write is at least two times the write buffer size; we write a few extra bytes to
+            // ensure the buffer is not empty after the writes so we can verify whether Length, Dispose and Flush
+            // flush the buffer
+            _count = ((int) _writeBufferSize*2) + _random.Next(1, 5);
+
+            _expectedWrittenByteCount = (2 * _writeBufferSize);
+            _expectedBufferedByteCount = (int)(_count - _expectedWrittenByteCount);
+            _expectedBufferedBytes = _data.Take(_offset + (int)_expectedWrittenByteCount, _expectedBufferedByteCount);
+
+            _sftpSessionMock = new Mock<ISftpSession>(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.RequestWrite(_handle, 0, _data, _offset, (int) _writeBufferSize, It.IsAny<AutoResetEvent>(), null));
+            _sftpSessionMock.InSequence(_sequence)
+                .Setup(p => p.RequestWrite(_handle, _writeBufferSize, _data, _offset + (int) _writeBufferSize, (int)_writeBufferSize, It.IsAny<AutoResetEvent>(), null));
+
+            _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int) _bufferSize);
+        }
+
+        protected void Act()
+        {
+            _sftpFileStream.Write(_data, _offset, _count);
+        }
+
+        [TestMethod]
+        public void RequestWriteOnSftpSessionShouldBeInvokedTwice()
+        {
+            _sftpSessionMock.Verify(p => p.RequestWrite(_handle, 0, _data, _offset, (int)_writeBufferSize, It.IsAny<AutoResetEvent>(), null), Times.Once);
+            _sftpSessionMock.Verify(p => p.RequestWrite(_handle, _writeBufferSize, _data, _offset + (int)_writeBufferSize, (int)_writeBufferSize, It.IsAny<AutoResetEvent>(), null), Times.Once);
+        }
+
+        [TestMethod]
+        public void PositionShouldBeNumberOfBytesWrittenToFileAndNUmberOfBytesInBuffer()
+        {
+            _sftpSessionMock.InSequence(_sequence)
+                            .Setup(p => p.IsOpen)
+                            .Returns(true);
+
+            Assert.AreEqual(_count, _sftpFileStream.Position);
+        }
+
+        [TestMethod]
+        public void LengthShouldFlushBufferAndReturnSizeOfFile()
+        {
+            var lengthFileAttributes = new SftpFileAttributes(DateTime.Now, DateTime.Now, _random.Next(), _random.Next(),
+                                                        _random.Next(), (uint) _random.Next(0, int.MaxValue), null);
+            byte[] actualFlushedData = null;
+
+            _sftpSessionMock.InSequence(_sequence)
+                            .Setup(p => p.IsOpen)
+                            .Returns(true);
+            _sftpSessionMock.InSequence(_sequence)
+                            .Setup(p => p.RequestWrite(_handle, _expectedWrittenByteCount, It.IsAny<byte[]>(), 0, _expectedBufferedByteCount, It.IsAny<AutoResetEvent>(), null))
+                            .Callback<byte[], ulong, byte[], int, int, AutoResetEvent, Action<SftpStatusResponse>>((handle, serverFileOffset, data, offset, length, wait, writeCompleted) => actualFlushedData = data.Take(offset, length));
+            _sftpSessionMock.InSequence(_sequence)
+                            .Setup(p => p.RequestFStat(_handle))
+                            .Returns(lengthFileAttributes);
+
+            Assert.AreEqual(lengthFileAttributes.Size, _sftpFileStream.Length);
+            Assert.IsTrue(actualFlushedData.IsEqualTo(_expectedBufferedBytes));
+
+            _sftpSessionMock.Verify(p => p.RequestWrite(_handle, _expectedWrittenByteCount, It.IsAny<byte[]>(), 0, _expectedBufferedByteCount, It.IsAny<AutoResetEvent>(), null), Times.Once);
+        }
+
+        [TestMethod]
+        public void DisposeShouldFlushBufferAndCloseRequest()
+        {
+            byte[] actualFlushedData = null;
+
+            _sftpSessionMock.InSequence(_sequence)
+                            .Setup(p => p.IsOpen)
+                            .Returns(true);
+            _sftpSessionMock.InSequence(_sequence)
+                            .Setup(p => p.RequestWrite(_handle, _expectedWrittenByteCount, It.IsAny<byte[]>(), 0, _expectedBufferedByteCount, It.IsAny<AutoResetEvent>(), null))
+                            .Callback<byte[], ulong, byte[], int, int, AutoResetEvent, Action<SftpStatusResponse>>((handle, serverFileOffset, data, offset, length, wait, writeCompleted) => actualFlushedData = data.Take(offset, length));
+            _sftpSessionMock.InSequence(_sequence)
+                            .Setup(p => p.RequestClose(_handle));
+
+            _sftpFileStream.Dispose();
+
+            Assert.IsTrue(actualFlushedData.IsEqualTo(_expectedBufferedBytes));
+
+            _sftpSessionMock.Verify(p => p.RequestWrite(_handle, _expectedWrittenByteCount, It.IsAny<byte[]>(), 0, _expectedBufferedByteCount, It.IsAny<AutoResetEvent>(), null), Times.Once);
+            _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once);
+        }
+
+        [TestMethod]
+        public void FlushShouldFlushBuffer()
+        {
+            byte[] actualFlushedData = null;
+
+            _sftpSessionMock.InSequence(_sequence)
+                            .Setup(p => p.IsOpen)
+                            .Returns(true);
+            _sftpSessionMock.InSequence(_sequence)
+                            .Setup(p => p.RequestWrite(_handle, _expectedWrittenByteCount, It.IsAny<byte[]>(), 0, _expectedBufferedByteCount, It.IsAny<AutoResetEvent>(), null))
+                            .Callback<byte[], ulong, byte[], int, int, AutoResetEvent, Action<SftpStatusResponse>>((handle, serverFileOffset, data, offset, length, wait, writeCompleted) => actualFlushedData = data.Take(offset, length));
+
+            _sftpFileStream.Flush();
+
+            Assert.IsTrue(actualFlushedData.IsEqualTo(_expectedBufferedBytes));
+
+            _sftpSessionMock.Verify(p => p.RequestWrite(_handle, _expectedWrittenByteCount, It.IsAny<byte[]>(), 0, _expectedBufferedByteCount, It.IsAny<AutoResetEvent>(), null), Times.Once);
+        }
+    }
+}

+ 4 - 6
src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Connected.cs

@@ -48,9 +48,7 @@ namespace Renci.SshNet.Tests.Classes
                 .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();
@@ -76,15 +74,15 @@ namespace Renci.SshNet.Tests.Classes
         }
 
         [TestMethod]
-        public void DisconnectOnNetConfSessionShouldBeInvokedOnce()
+        public void DisconnectOnNetConfSessionShouldNeverBeInvoked()
         {
-            _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sftpSessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]
-        public void DisconnectOnSessionShouldBeInvokedOnce()
+        public void DisconnectOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]

+ 4 - 6
src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disconnected.cs

@@ -48,9 +48,7 @@ namespace Renci.SshNet.Tests.Classes
                 .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();
@@ -77,15 +75,15 @@ namespace Renci.SshNet.Tests.Classes
         }
 
         [TestMethod]
-        public void DisconnectOnNetConfSessionShouldBeInvokedOnce()
+        public void DisconnectOnNetConfSessionShouldNeverBeInvoked()
         {
-            _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sftpSessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]
-        public void DisconnectOnSessionShouldBeInvokedOnce()
+        public void DisconnectOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]

+ 4 - 6
src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disposed.cs

@@ -48,9 +48,7 @@ namespace Renci.SshNet.Tests.Classes
                 .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();
@@ -77,15 +75,15 @@ namespace Renci.SshNet.Tests.Classes
         }
 
         [TestMethod]
-        public void DisconnectOnNetConfSessionShouldBeInvokedOnce()
+        public void DisconnectOnNetConfSessionShouldNeverBeInvoked()
         {
-            _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sftpSessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]
-        public void DisconnectOnSessionShouldBeInvokedOnce()
+        public void DisconnectOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]

+ 1 - 1
src/Renci.SshNet.Tests/Classes/SshClientTest.cs

@@ -109,7 +109,7 @@ namespace Renci.SshNet.Tests.Classes
             {
                 client.ErrorOccurred += delegate(object sender, ExceptionEventArgs e)
                 {
-                    Console.WriteLine("Error occured: " + e.Exception.ToString());
+                    Console.WriteLine("Error occured: " + e.Exception);
                     exceptionOccured = true;
                 };
 

+ 2 - 3
src/Renci.SshNet.Tests/Classes/SshClientTest_Disconnect_ForwardedPortStarted.cs

@@ -40,7 +40,6 @@ namespace Renci.SshNet.Tests.Classes
             _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);
@@ -68,9 +67,9 @@ namespace Renci.SshNet.Tests.Classes
         }
 
         [TestMethod]
-        public void DisconnectOnSessionShouldBeInvokedOnce()
+        public void DisconnectOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]

+ 2 - 3
src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Connected.cs

@@ -34,7 +34,6 @@ namespace Renci.SshNet.Tests.Classes
             _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);
@@ -53,9 +52,9 @@ namespace Renci.SshNet.Tests.Classes
         }
 
         [TestMethod]
-        public void DisconnectOnSessionShouldBeInvokedOnce()
+        public void DisconnectOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]

+ 2 - 3
src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disconnected.cs

@@ -34,7 +34,6 @@ namespace Renci.SshNet.Tests.Classes
             _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);
@@ -54,9 +53,9 @@ namespace Renci.SshNet.Tests.Classes
         }
 
         [TestMethod]
-        public void DisconnectOnSessionShouldBeInvokedOnce()
+        public void DisconnectOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]

+ 2 - 3
src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disposed.cs

@@ -34,7 +34,6 @@ namespace Renci.SshNet.Tests.Classes
             _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);
@@ -54,9 +53,9 @@ namespace Renci.SshNet.Tests.Classes
         }
 
         [TestMethod]
-        public void DisconnectOnSessionShouldBeInvokedOnce()
+        public void DisconnectOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]

+ 3 - 4
src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_ForwardedPortStarted.cs

@@ -41,7 +41,6 @@ namespace Renci.SshNet.Tests.Classes
             _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);
@@ -83,15 +82,15 @@ namespace Renci.SshNet.Tests.Classes
         }
 
         [TestMethod]
-        public void DisconnectOnSessionShouldBeInvokedOnce()
+        public void DisconnectOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Disconnect(), Times.Never);
         }
 
         [TestMethod]
         public void DisposeOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.Disconnect(), Times.Once);
+            _sessionMock.Verify(p => p.Dispose(), Times.Once);
         }
     }
 }

+ 0 - 2
src/Renci.SshNet.Tests/Classes/SshCommandTest_BeginExecute_EndExecuteInvokedOnAsyncResultFromPreviousInvocation.cs

@@ -47,8 +47,6 @@ namespace Renci.SshNet.Tests.Classes
             _channelSessionAMock.InSequence(seq).Setup(p => p.SendExecRequest(_commandText))
                 .Returns(true)
                 .Raises(c => c.Closed += null, new ChannelEventArgs(5));
-            _channelSessionAMock.InSequence(seq).Setup(p => p.IsOpen).Returns(true);
-            _channelSessionAMock.InSequence(seq).Setup(p => p.Close());
             _channelSessionAMock.InSequence(seq).Setup(p => p.Dispose());
 
             _sshCommand = new SshCommand(_sessionMock.Object, _commandText, _encoding);

+ 1 - 4
src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs

@@ -40,7 +40,6 @@ namespace Renci.SshNet.Tests.Classes
             _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();
@@ -59,14 +58,12 @@ namespace Renci.SshNet.Tests.Classes
             _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);
+            _channelSessionMock.Verify(p => p.Dispose(), Times.Once);
         }
     }
 }

+ 0 - 8
src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute_ChannelOpen.cs

@@ -55,8 +55,6 @@ namespace Renci.SshNet.Tests.Classes
             _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());
 
             _sshCommand = new SshCommand(_sessionMock.Object, _commandText, _encoding);
@@ -79,12 +77,6 @@ namespace Renci.SshNet.Tests.Classes
             _actual = _sshCommand.EndExecute(_asyncResult);
         }
 
-        [TestMethod]
-        public void ChannelSessionShouldBeClosedOnce()
-        {
-            _channelSessionMock.Verify(p => p.Close(), Times.Once);
-        }
-
         [TestMethod]
         public void ChannelSessionShouldBeDisposedOnce()
         {

部分文件因为文件数量过多而无法显示