From 1d6177fcebf36064c4212187d8245631088f2e7e Mon Sep 17 00:00:00 2001 From: drieseng Date: Sat, 10 Sep 2016 18:55:03 +0200 Subject: [PATCH] Send SSH_MSG_CHANNEL_EOF and SSH_MSG_CHANNEL_CLOSE in synchronized block. Fixes issue #84. Eliminate public Close() method and its use within SSH.NET. Remove wait bool from protected Close(bool) method. The protected Close() method will now always wait for a SSH_MSG_CHANNEL_CLOSE if the client initiated closing the channel. --- .../Channels/ChannelDirectTcpipTest.cs | 4 +- ...ose_SessionIsConnectedAndChannelIsOpen.cs} | 4 +- ...ose_SessionIsConnectedAndChannelIsOpen.cs} | 4 +- ...=> ChannelSessionTest_Dispose_Disposed.cs} | 6 +- ...eceived_SendChannelCloseMessageFailure.cs} | 4 +- ...eceived_SendChannelCloseMessageSuccess.cs} | 12 +- ...eceived_SendChannelCloseMessageFailure.cs} | 4 +- ...eceived_SendChannelCloseMessageSuccess.cs} | 12 +- ...eceived_SendChannelCloseMessageFailure.cs} | 4 +- ...eceived_SendChannelCloseMessageSuccess.cs} | 4 +- ...pen_NoChannelCloseOrChannelEofReceived.cs} | 4 +- ...fReceived_SendChannelEofMessageFailure.cs} | 4 +- ...Open_ChannelCloseAndChannelEofReceived.cs} | 4 +- ...dAndChannelIsOpen_ChannelCloseReceived.cs} | 4 +- ...pen_NoChannelCloseOrChannelEofReceived.cs} | 4 +- .../ChannelSessionTest_Disposed_Closed.cs | 2 +- ...ived_SessionIsConnectedAndChannelIsOpen.cs | 8 +- ..._SessionIsConnectedAndChannelIsNotOpen.cs} | 4 +- ...nnectedAndChannelIsOpen_EofNotReceived.cs} | 4 +- ...elIsOpen_EofNotReceived_SendEofInvoked.cs} | 4 +- ...sConnectedAndChannelIsOpen_EofReceived.cs} | 4 +- ...ssionIsNotConnectedAndChannelIsNotOpen.cs} | 4 +- ..._SessionIsNotConnectedAndChannelIsOpen.cs} | 4 +- ...nChannelCloseReceived_OnClose_Exception.cs | 4 +- ...onnectedAndChannelIsOpen_EofNotReceived.cs | 16 +- ...IsConnectedAndChannelIsOpen_EofReceived.cs | 16 +- ...icTest_Dispose_PortStarted_ChannelBound.cs | 22 +-- ...est_Dispose_PortStarted_ChannelNotBound.cs | 7 - ...cTest_SessionErrorOccurred_ChannelBound.cs | 14 +- ...t_Started_SocketSendShutdownImmediately.cs | 24 +-- ...cTest_Started_SocketVersionNotSupported.cs | 24 +-- ...namicTest_Stop_PortStarted_ChannelBound.cs | 7 - ...icTest_Stop_PortStarted_ChannelNotBound.cs | 7 - ...alTest_Dispose_PortStarted_ChannelBound.cs | 7 - ...dedPortLocalTest_Start_PortNeverStarted.cs | 1 - ...orwardedPortLocalTest_Start_PortStarted.cs | 9 +- ...orwardedPortLocalTest_Start_PortStopped.cs | 1 - ...LocalTest_Stop_PortStarted_ChannelBound.cs | 7 - ...teTest_Dispose_PortStarted_ChannelBound.cs | 7 - ...edPortRemoteTest_Start_PortNeverStarted.cs | 2 - ...rwardedPortRemoteTest_Start_PortStarted.cs | 2 - ...rwardedPortRemoteTest_Start_PortStopped.cs | 8 +- .../ForwardedPortRemoteTest_Started.cs | 2 - ...InfoAndPath_SendExecRequestReturnsFalse.cs | 6 - ...ientTest_Upload_FileInfoAndPath_Success.cs | 7 - .../SessionTest_Connected_ConnectionReset.cs | 3 +- ...sionTest_Connected_ServerSendsBadPacket.cs | 3 +- ...utsDownSendAfterSendingIncompletePacket.cs | 3 +- ...ionTest_Connected_ServerShutsDownSocket.cs | 3 +- .../Classes/SshClientTest.cs | 2 +- ...okedOnAsyncResultFromPreviousInvocation.cs | 2 - .../Classes/SshCommandTest_EndExecute.cs | 5 +- .../SshCommandTest_EndExecute_ChannelOpen.cs | 8 - .../SubsystemSession_Connect_Connected.cs | 6 - .../SubsystemSession_Connect_Disconnected.cs | 15 +- .../SubsystemSession_Disconnect_Connected.cs | 7 - .../SubsystemSession_Disconnect_Disposed.cs | 7 - .../SubsystemSession_Dispose_Connected.cs | 7 - .../SubsystemSession_Dispose_Disconnected.cs | 7 - .../SubsystemSession_Dispose_Disposed.cs | 7 - ...Session_OnChannelDataReceived_Connected.cs | 6 - ...mSession_OnChannelDataReceived_Disposed.cs | 1 - ...elDataReceived_OnDataReceived_Exception.cs | 5 +- ...temSession_OnChannelException_Connected.cs | 11 +- ...stemSession_OnChannelException_Disposed.cs | 1 - ...Session_OnSessionDisconnected_Connected.cs | 6 - ...mSession_OnSessionDisconnected_Disposed.cs | 1 - ...ession_OnSessionErrorOccurred_Connected.cs | 11 +- ...Session_OnSessionErrorOccurred_Disposed.cs | 1 - .../SubsystemSession_SendData_Disposed.cs | 1 - src/Renci.SshNet.Tests/Common/Extensions.cs | 20 +++ .../Renci.SshNet.Tests.csproj | 41 ++--- src/Renci.SshNet/Channels/Channel.cs | 151 ++++++++---------- .../Channels/ChannelDirectTcpip.cs | 10 +- .../Channels/ChannelForwardedTcpip.cs | 8 +- src/Renci.SshNet/Channels/ChannelSession.cs | 17 +- src/Renci.SshNet/Channels/IChannel.cs | 5 - .../Channels/IChannelDirectTcpip.cs | 5 - .../Channels/IChannelForwardedTcpip.cs | 5 - src/Renci.SshNet/ForwardedPortDynamic.NET.cs | 19 +-- src/Renci.SshNet/ForwardedPortLocal.NET.cs | 1 - src/Renci.SshNet/ForwardedPortRemote.cs | 1 - src/Renci.SshNet/ISession.cs | 15 ++ src/Renci.SshNet/ScpClient.NET.cs | 8 - src/Renci.SshNet/ScpClient.cs | 4 - src/Renci.SshNet/Session.cs | 22 ++- src/Renci.SshNet/Shell.cs | 8 +- src/Renci.SshNet/ShellStream.cs | 2 +- src/Renci.SshNet/SshCommand.cs | 7 +- src/Renci.SshNet/SubsystemSession.cs | 1 - 90 files changed, 283 insertions(+), 508 deletions(-) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelDirectTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs => ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs} (98%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs => ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs} (98%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_Closed.cs => ChannelSessionTest_Dispose_Disposed.cs} (98%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs => ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs} (96%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs => ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs} (90%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs => ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs} (96%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs => ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs} (90%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs => ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs} (96%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs => ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs} (97%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs => ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs} (97%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs => ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs} (97%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs => ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs} (97%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs => ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs} (97%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs => ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs} (96%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs => ChannelTest_Dispose_SessionIsConnectedAndChannelIsNotOpen.cs} (95%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs => ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs} (97%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs => ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs} (97%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs => ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs} (98%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs => ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsNotOpen.cs} (95%) rename src/Renci.SshNet.Tests/Classes/Channels/{ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs => ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsOpen.cs} (95%) create mode 100644 src/Renci.SshNet.Tests/Common/Extensions.cs diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs index 2de7725da..804e477a5 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs @@ -195,7 +195,7 @@ public void SocketShouldBeClosedAndEofShouldBeSentToServerWhenClientShutsDownSoc _localPacketSize); channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket); channel.Bind(); - channel.Close(); + channel.Dispose(); handler = socket; @@ -215,7 +215,7 @@ public void SocketShouldBeClosedAndEofShouldBeSentToServerWhenClientShutsDownSoc _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); - channel.Close(); + channel.Dispose(); _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs similarity index 98% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs index 499ba6de0..de5922ff9 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs @@ -12,7 +12,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelDirectTcpipTest_Close_SessionIsConnectedAndChannelIsOpen + public class ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen { private Mock _sessionMock; private Mock _forwardedPortMock; @@ -165,7 +165,7 @@ private void Act() { if (_channel != null) { - _channel.Close(); + _channel.Dispose(); } } diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs similarity index 98% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs index de0984fc2..3dddb2065 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs @@ -13,7 +13,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen + public class ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen { private Mock _sessionMock; private Mock _forwardedPortMock; @@ -157,7 +157,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_Closed.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_Disposed.cs similarity index 98% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_Closed.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_Disposed.cs index d115681ad..75461290b 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_Closed.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_Disposed.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelSessionTest_Close_Closed + public class ChannelSessionTest_Dispose_Disposed { private Mock _sessionMock; private Mock _connectionInfoMock; @@ -97,12 +97,12 @@ private void Arrange() _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 diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs similarity index 96% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs index e99818dcc..4f5590f45 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure + public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure { private Mock _sessionMock; private uint _localChannelNumber; @@ -100,7 +100,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs similarity index 90% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs index 5b05fbf03..8f007fb3f 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs @@ -6,11 +6,12 @@ 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 _sessionMock; private uint _localChannelNumber; @@ -79,11 +80,14 @@ private void Arrange() _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(c => c.LocalChannelNumber == _remoteChannelNumber))) .Returns(true); + _sessionMock.InSequence(_sequence) + .Setup(s => s.WaitOnHandle(It.IsNotNull())) + .Callback(w => w.WaitOne()); _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); @@ -100,7 +104,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] @@ -112,7 +116,7 @@ public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() [TestMethod] public void ExceptionShouldNeverHaveFired() { - Assert.AreEqual(0, _channelExceptionRegister.Count); + Assert.AreEqual(0, _channelExceptionRegister.Count, _channelExceptionRegister.AsString()); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs similarity index 96% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs index 31c133389..049d90f14 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure + public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure { private Mock _sessionMock; private uint _localChannelNumber; @@ -97,7 +97,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs similarity index 90% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs index 5c950564a..dcb0a8fbc 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs @@ -6,11 +6,12 @@ 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 _sessionMock; private uint _localChannelNumber; @@ -79,11 +80,14 @@ private void Arrange() _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(c => c.LocalChannelNumber == _remoteChannelNumber))) .Returns(true); + _sessionMock.InSequence(_sequence) + .Setup(s => s.WaitOnHandle(It.IsNotNull())) + .Callback(w => w.WaitOne()); _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); @@ -97,7 +101,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] @@ -109,7 +113,7 @@ public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() [TestMethod] public void ExceptionShouldNeverHaveFired() { - Assert.AreEqual(0, _channelExceptionRegister.Count); + Assert.AreEqual(0, _channelExceptionRegister.Count, _channelExceptionRegister.AsString()); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs similarity index 96% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs index 2aa4f8326..3173232f5 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure + public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure { private Mock _sessionMock; private uint _localChannelNumber; @@ -97,7 +97,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs similarity index 97% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs index 383a4ff5a..f0b7bd01b 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess + public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess { private Mock _sessionMock; private uint _localChannelNumber; @@ -107,7 +107,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs similarity index 97% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs index bc294c291..fdd0e4694 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived + public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived { private Mock _sessionMock; private Mock _connectionInfoMock; @@ -105,7 +105,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs similarity index 97% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs index 8f53f68bd..084d5b1db 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure + public class ChannelSessionTest_Dispose_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure { private Mock _sessionMock; private Mock _connectionInfoMock; @@ -105,7 +105,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs similarity index 97% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs index 16e215085..b0407c3f9 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived + public class ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived { private Mock _sessionMock; private uint _localChannelNumber; @@ -96,7 +96,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs similarity index 97% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs index 3a1a94afd..7a16c21d6 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived + public class ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived { private Mock _sessionMock; private uint _localChannelNumber; @@ -93,7 +93,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs similarity index 96% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs index 050a6ec6f..ad14e13a0 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived + public class ChannelSessionTest_Dispose_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived { private Mock _sessionMock; private uint _localChannelNumber; @@ -89,7 +89,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Disposed_Closed.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Disposed_Closed.cs index af9361f32..0d461ecba 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Disposed_Closed.cs +++ b/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() { diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs index 9e0df191f..130797cde 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs @@ -6,6 +6,7 @@ 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 @@ private void Arrange() _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(c => c.LocalChannelNumber == _remoteChannelNumber))) .Returns(true); + _sessionMock.InSequence(_sequence) + .Setup(s => s.WaitOnHandle(It.IsNotNull())) + .Callback(w => w.WaitOne()); _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); @@ -107,7 +111,7 @@ public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() [TestMethod] public void ExceptionShouldNeverHaveFired() { - Assert.AreEqual(0, _channelExceptionRegister.Count); + Assert.AreEqual(0, _channelExceptionRegister.Count, _channelExceptionRegister.AsString()); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsNotOpen.cs similarity index 95% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsNotOpen.cs index 0dcaa1772..67903d6ed 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsNotOpen.cs @@ -9,7 +9,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen + public class ChannelTest_Dispose_SessionIsConnectedAndChannelIsNotOpen { private Mock _sessionMock; private uint _localWindowSize; @@ -46,7 +46,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs similarity index 97% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs index 29ae3ed2e..e671e780b 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived + public class ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived { private Mock _sessionMock; private uint _localChannelNumber; @@ -84,7 +84,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs similarity index 97% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs index 9b9b2a94c..9cb4d9d85 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked + public class ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked { private Mock _sessionMock; private uint _localChannelNumber; @@ -84,7 +84,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs similarity index 98% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs index d7b9528d9..214123fd0 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs @@ -10,7 +10,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived + public class ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived { private Mock _sessionMock; private uint _localChannelNumber; @@ -93,7 +93,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsNotOpen.cs similarity index 95% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsNotOpen.cs index 880ce65fe..3ef388d9e 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsNotOpen.cs @@ -9,7 +9,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen + public class ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsNotOpen { private Mock _sessionMock; private uint _localWindowSize; @@ -46,7 +46,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsOpen.cs similarity index 95% rename from src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs rename to src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsOpen.cs index 159ebdc98..76fbaa659 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsOpen.cs @@ -8,7 +8,7 @@ namespace Renci.SshNet.Tests.Classes.Channels { [TestClass] - public class ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen + public class ChannelTest_Dispose_SessionIsNotConnectedAndChannelIsOpen { private Mock _sessionMock; private uint _localWindowSize; @@ -46,7 +46,7 @@ private void Arrange() private void Act() { - _channel.Close(); + _channel.Dispose(); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs index 9830be3ac..1933afb7f 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs @@ -28,9 +28,9 @@ public void Initialize() 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(); diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs index ab3c73d70..6d6bbd6a1 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs @@ -5,6 +5,7 @@ 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 @@ private void Arrange() _sessionMock = new Mock(MockBehavior.Strict); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.TrySendMessage(It.Is(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(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true); + _sessionMock.InSequence(sequence) + .Setup(s => s.WaitOnHandle(It.IsNotNull())) + .Callback(w => w.WaitOne()); _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); @@ -82,9 +88,9 @@ public void TrySendMessageOnSessionShouldNeverBeInvokedForChannelEofMessage() } [TestMethod] - public void WaitOnHandleOnSessionShouldNeverBeInvoked() + public void WaitOnHandleOnSessionShouldBeInvokedOnce() { - _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Never); + _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Once); } [TestMethod] @@ -97,7 +103,7 @@ public void ClosedEventShouldHaveFiredOnce() [TestMethod] public void ExceptionShouldNeverHaveFired() { - Assert.AreEqual(0, _channelExceptionRegister.Count); + Assert.AreEqual(0, _channelExceptionRegister.Count, _channelExceptionRegister.AsString()); } } } diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs index be1dfe28c..589b5665c 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs @@ -5,6 +5,7 @@ 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 @@ private void Arrange() _sessionMock = new Mock(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(c => c.LocalChannelNumber == _remoteChannelNumber))) .Returns(true); + _sessionMock.InSequence(sequence) + .Setup(s => s.WaitOnHandle(It.IsNotNull())) + .Callback(w => w.WaitOne()); _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); @@ -87,9 +93,9 @@ public void SendMessageOnSessionShouldNeverBeInvokedForChannelEofMessage() } [TestMethod] - public void WaitOnHandleOnSessionShouldNeverBeInvoked() + public void WaitOnHandleOnSessionShouldBeInvokedOnce() { - _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Never); + _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Once); } [TestMethod] @@ -102,7 +108,7 @@ public void ClosedEventShouldHaveFiredOnce() [TestMethod] public void ExceptionShouldNeverHaveFired() { - Assert.AreEqual(0, _channelExceptionRegister.Count); + Assert.AreEqual(0, _channelExceptionRegister.Count, _channelExceptionRegister.AsString()); } } } diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs index 69577a2f2..441250a0a 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs @@ -11,6 +11,7 @@ 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 @@ private void SetupMocks() Thread.Sleep(_bindSleepTime); _channelBindCompleted.Set(); }); - _channelMock.Setup(p => p.Close()); _channelMock.Setup(p => p.Dispose()); } @@ -190,7 +190,7 @@ public void ClosingShouldHaveFiredOnce() [TestMethod] public void ExceptionShouldNotHaveFired() { - Assert.AreEqual(0, _exceptionRegister.Count, GetReportedExceptions()); + Assert.AreEqual(0, _exceptionRegister.Count, _exceptionRegister.AsString()); } [TestMethod] @@ -208,12 +208,6 @@ public void BindOnChannelShouldBeInvokedOnce() _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 @@ private void EstablishSocks4Connection(Socket client) // 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; - } } } diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs index 137ad5aae..6c4439440 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs @@ -59,7 +59,6 @@ protected void Arrange() _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 @@ public void ExceptionShouldNotHaveFired() Assert.AreEqual(0, _exceptionRegister.Count); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs index bb5774a74..db778a089 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs @@ -11,6 +11,7 @@ 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 @@ private void SetupMocks() Thread.Sleep(_bindSleepTime); _channelBindCompleted.Set(); }); - _channelMock.Setup(p => p.Close()); _channelMock.Setup(p => p.Dispose()); } @@ -195,9 +195,9 @@ public void ClosingShouldHaveFiredOnce() [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 @@ public void BindOnChannelShouldBeInvokedOnce() _channelMock.Verify(p => p.Bind(), Times.Once); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs index 090931b5f..ffc104f17 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs @@ -8,6 +8,7 @@ using Moq; using Renci.SshNet.Channels; using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; namespace Renci.SshNet.Tests.Classes { @@ -90,7 +91,6 @@ private void SetupMocks() _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 @@ public void ClosingShouldNotHaveFired() [TestMethod] public void ExceptionShouldNeverBeFired() { - Assert.AreEqual(0, _exceptionRegister.Count, GetExceptions()); + Assert.AreEqual(0, _exceptionRegister.Count, _exceptionRegister.AsString()); } [TestMethod] @@ -147,30 +147,10 @@ public void CreateChannelDirectTcpipOnSessionShouldBeInvokedOnce() _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(); - } } } diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs index 16c5d877e..8eef3061f 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs @@ -8,6 +8,7 @@ using Moq; using Renci.SshNet.Channels; using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; namespace Renci.SshNet.Tests.Classes { @@ -77,7 +78,6 @@ private void SetupMocks() _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 @@ public void ClosingShouldNotHaveFired() [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 @@ public void CreateChannelDirectTcpipOnSessionShouldBeInvokedOnce() _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(); - } } } diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs index ddfe321bc..80f7877e3 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs @@ -110,7 +110,6 @@ private void SetupMocks() Thread.Sleep(_bindSleepTime); _channelBindCompleted.Set(); }); - _channelMock.Setup(p => p.Close()); _channelMock.Setup(p => p.Dispose()); } @@ -196,12 +195,6 @@ public void ExceptionShouldNotHaveFired() Assert.AreEqual(0, _exceptionRegister.Count); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs index d27c0751c..b84d947d5 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs @@ -59,7 +59,6 @@ protected void Arrange() _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 @@ public void ExceptionShouldNotHaveFired() Assert.AreEqual(0, _exceptionRegister.Count); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs index 51b4b0859..9677734a2 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs @@ -85,7 +85,6 @@ protected void Arrange() 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 @@ public void BindOnChannelShouldBeInvokedOnce() _channelMock.Verify(p => p.Bind(), Times.Once); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs index 416fb3315..6bb32b280 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs @@ -85,7 +85,6 @@ public void ForwardedPortShouldAcceptNewConnections() 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)) diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs index 4db07a97c..5980aad96 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs @@ -98,11 +98,10 @@ public void ForwardedPortShouldAcceptNewConnections() _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny())).Callback((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)) diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs index 79b5ae619..9889af6aa 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs @@ -89,7 +89,6 @@ public void ForwardedPortShouldAcceptNewConnections() 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)) diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs index a4e614544..b07bb9331 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs @@ -103,7 +103,6 @@ private void SetupMocks() Thread.Sleep(_bindSleepTime); _channelBindCompleted.Set(); }); - _channelMock.Setup(p => p.Close()); _channelMock.Setup(p => p.Dispose()); } @@ -201,12 +200,6 @@ public void BindOnChannelShouldBeInvokedOnce() _channelMock.Verify(p => p.Bind(), Times.Once); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs index 8a6be6577..69787c826 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs @@ -134,7 +134,6 @@ private void SetupMocks() Thread.Sleep(_bindSleepTime); _channelBindCompleted.Set(); }); - _channelMock.Setup(p => p.Close()); _channelMock.Setup(p => p.Dispose()); _sessionMock.Setup( p => @@ -239,12 +238,6 @@ public void BindOnChannelShouldBeInvokedOnceForChannelOpenedWhileStarted() ForwardedPort), Times.Once); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortNeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortNeverStarted.cs index 420a23f24..4b6a420d4 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortNeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortNeverStarted.cs @@ -114,7 +114,6 @@ public void ForwardedPortShouldAcceptNewConnections() It.Is( 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, @@ -125,7 +124,6 @@ public void ForwardedPortShouldAcceptNewConnections() _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once); channelMock.Verify(p => p.Bind(It.Is(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); } diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStarted.cs index eefe34f8f..a75026806 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStarted.cs @@ -131,7 +131,6 @@ public void ForwardedPortShouldAcceptNewConnections() It.Is( 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, @@ -142,7 +141,6 @@ public void ForwardedPortShouldAcceptNewConnections() _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once); channelMock.Verify(p => p.Bind(It.Is(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); } diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStopped.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStopped.cs index c1f417744..92caa7ac8 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStopped.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStopped.cs @@ -120,7 +120,7 @@ public void ForwardedPortShouldAcceptNewConnections() var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); var originatorPort = (uint)new Random().Next(0, int.MaxValue); var channelMock = new Mock(MockBehavior.Strict); - var channelDiposed = new ManualResetEvent(false); + var channelDisposed = new ManualResetEvent(false); _sessionMock.Setup( p => @@ -131,8 +131,7 @@ public void ForwardedPortShouldAcceptNewConnections() It.Is( 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(new ChannelOpenMessage(channelNumber, initialWindowSize, @@ -141,11 +140,10 @@ public void ForwardedPortShouldAcceptNewConnections() 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(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); } diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Started.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Started.cs index 7c122bb7c..dd7537a3b 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Started.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Started.cs @@ -107,7 +107,6 @@ public void ForwardedPortShouldAcceptChannelOpenMessageForBoundAddressAndBoundPo It.Is( 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, @@ -121,7 +120,6 @@ public void ForwardedPortShouldAcceptChannelOpenMessageForBoundAddressAndBoundPo _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once); channelMock.Verify(p => p.Bind(It.Is(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); diff --git a/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs b/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs index 7a6b2890b..8bb173c8d 100644 --- a/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs +++ b/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs @@ -101,12 +101,6 @@ public void SendExecREquestOnChannelSessionShouldBeInvokedOnce() _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() { diff --git a/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs b/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs index fbfdd8464..e71aea03b 100644 --- a/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs +++ b/src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs @@ -101,7 +101,6 @@ private void SetupMocks() .Setup( p => p.SendData(It.Is(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().InSequence(sequence).Setup(p => p.Dispose()); } @@ -131,12 +130,6 @@ public void SendExecRequestOnChannelSessionShouldBeInvokedOnce() _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() { diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs index bf1da4a75..464cf05b9 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs @@ -4,6 +4,7 @@ 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 @@ public void DisconnectReceivedIsNeverRaised() [TestMethod] public void ErrorOccurredIsRaisedOnce() { - Assert.AreEqual(1, ErrorOccurredRegister.Count); + Assert.AreEqual(1, ErrorOccurredRegister.Count, ErrorOccurredRegister.AsString()); var errorOccurred = ErrorOccurredRegister[0]; Assert.IsNotNull(errorOccurred); diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs index b55f87c40..4eaed4a38 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs @@ -4,6 +4,7 @@ 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 @@ public void DisconnectReceivedIsNeverRaised() [TestMethod] public void ErrorOccurredIsRaisedOnce() { - Assert.AreEqual(1, ErrorOccurredRegister.Count); + Assert.AreEqual(1, ErrorOccurredRegister.Count, ErrorOccurredRegister.AsString()); var errorOccurred = ErrorOccurredRegister[0]; Assert.IsNotNull(errorOccurred); diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSendAfterSendingIncompletePacket.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSendAfterSendingIncompletePacket.cs index a2a74e458..5aa487627 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSendAfterSendingIncompletePacket.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSendAfterSendingIncompletePacket.cs @@ -5,6 +5,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshNet.Common; using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Tests.Common; namespace Renci.SshNet.Tests.Classes { @@ -58,7 +59,7 @@ public void DisconnectReceivedIsNeverRaised() [TestMethod] public void ErrorOccurredIsRaisedOnce() { - Assert.AreEqual(1, ErrorOccurredRegister.Count); + Assert.AreEqual(1, ErrorOccurredRegister.Count, ErrorOccurredRegister.AsString()); var errorOccurred = ErrorOccurredRegister[0]; Assert.IsNotNull(errorOccurred); diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs index ace0953a2..72e27cd17 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs @@ -4,6 +4,7 @@ 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 @@ public void DisconnectReceivedIsNeverRaised() [TestMethod] public void ErrorOccurredIsRaisedOnce() { - Assert.AreEqual(1, ErrorOccurredRegister.Count); + Assert.AreEqual(1, ErrorOccurredRegister.Count, ErrorOccurredRegister.AsString()); var errorOccurred = ErrorOccurredRegister[0]; Assert.IsNotNull(errorOccurred); diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest.cs index d7e295f8e..78f1db6c4 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest.cs @@ -109,7 +109,7 @@ public void Test_Connect_Handle_ErrorOccurred() { client.ErrorOccurred += delegate(object sender, ExceptionEventArgs e) { - Console.WriteLine("Error occured: " + e.Exception.ToString()); + Console.WriteLine("Error occured: " + e.Exception); exceptionOccured = true; }; diff --git a/src/Renci.SshNet.Tests/Classes/SshCommandTest_BeginExecute_EndExecuteInvokedOnAsyncResultFromPreviousInvocation.cs b/src/Renci.SshNet.Tests/Classes/SshCommandTest_BeginExecute_EndExecuteInvokedOnAsyncResultFromPreviousInvocation.cs index a8bddb3e4..7f6be4a29 100644 --- a/src/Renci.SshNet.Tests/Classes/SshCommandTest_BeginExecute_EndExecuteInvokedOnAsyncResultFromPreviousInvocation.cs +++ b/src/Renci.SshNet.Tests/Classes/SshCommandTest_BeginExecute_EndExecuteInvokedOnAsyncResultFromPreviousInvocation.cs @@ -47,8 +47,6 @@ private void Arrange() _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); diff --git a/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs b/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs index 8fbbeac71..ac7d0f6f8 100644 --- a/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs +++ b/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs @@ -40,7 +40,6 @@ public void EndExecute_ChannelClosed_ShouldDisposeChannelSession() _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 @@ public void EndExecute_ChannelOpen_ShouldSendEofAndCloseAndDisposeChannelSession _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); } } } diff --git a/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute_ChannelOpen.cs b/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute_ChannelOpen.cs index 44212cbf5..0001a9184 100644 --- a/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute_ChannelOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute_ChannelOpen.cs @@ -55,8 +55,6 @@ private void Arrange() _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 @@ private void Act() _actual = _sshCommand.EndExecute(_asyncResult); } - [TestMethod] - public void ChannelSessionShouldBeClosedOnce() - { - _channelSessionMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void ChannelSessionShouldBeDisposedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs index 422b70d99..1b53351e6 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs @@ -112,12 +112,6 @@ public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); } - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - [TestMethod] public void DisposeOnChannelShouldNeverBeInvoked() { diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs index f5e9a5a1b..bfe60e301 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs @@ -47,7 +47,6 @@ protected void Arrange() _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelBeforeDisconnectMock.Object); _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Open()); _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Close()); _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Dispose()); _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelAfterDisconnectMock.Object); _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.Open()); @@ -101,18 +100,6 @@ public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() _channelAfterDisconnectMock.Verify(p => p.IsOpen, Times.Once); } - [TestMethod] - public void CloseOnChannelBeforeDisconnectShouldBeInvokedOnce() - { - _channelBeforeDisconnectMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void CloseOnChannelAfterDisconnectShouldNeverBeInvoked() - { - _channelAfterDisconnectMock.Verify(p => p.Close(), Times.Never); - } - [TestMethod] public void DisposeOnChannelBeforeDisconnectShouldBeInvokedOnce() { @@ -120,7 +107,7 @@ public void DisposeOnChannelBeforeDisconnectShouldBeInvokedOnce() } [TestMethod] - public void DisposeOnChannelAfterDisconnectShouldBeInvokedOnce() + public void DisposeOnChannelAfterDisconnectShouldNeverBeInvoked() { _channelAfterDisconnectMock.Verify(p => p.Dispose(), Times.Never); } diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs index 9a545f95b..117a6b3d6 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs @@ -45,7 +45,6 @@ protected void Arrange() _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); _channelMock.InSequence(_sequence).Setup(p => p.Open()); _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(_sequence).Setup(p => p.Close()); _channelMock.InSequence(_sequence).Setup(p => p.Dispose()); _subsystemSession = new SubsystemSessionStub( @@ -81,12 +80,6 @@ public void IsOpenShouldReturnFalse() Assert.IsFalse(_subsystemSession.IsOpen); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs index 734d8c5db..6dff14ca5 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs @@ -44,7 +44,6 @@ protected void Arrange() _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); _channelMock.InSequence(sequence).Setup(p => p.Open()); _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); _channelMock.InSequence(sequence).Setup(p => p.Dispose()); _subsystemSession = new SubsystemSessionStub( @@ -81,12 +80,6 @@ public void IsOpenShouldReturnFalse() Assert.IsFalse(_subsystemSession.IsOpen); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs index 3f03e5d4e..60325ad56 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs @@ -44,7 +44,6 @@ protected void Arrange() _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); _channelMock.InSequence(sequence).Setup(p => p.Open()); _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); _channelMock.InSequence(sequence).Setup(p => p.Dispose()); _subsystemSession = new SubsystemSessionStub( @@ -80,12 +79,6 @@ public void IsOpenShouldReturnFalse() Assert.IsFalse(_subsystemSession.IsOpen); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs index 6fc758e54..f1047192c 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs @@ -44,7 +44,6 @@ protected void Arrange() _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); _channelMock.InSequence(sequence).Setup(p => p.Open()); _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); _channelMock.InSequence(sequence).Setup(p => p.Dispose()); _subsystemSession = new SubsystemSessionStub( @@ -81,12 +80,6 @@ public void IsOpenShouldReturnFalse() Assert.IsFalse(_subsystemSession.IsOpen); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs index 1edec5bb5..25e0ff65a 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs @@ -44,7 +44,6 @@ protected void Arrange() _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); _channelMock.InSequence(sequence).Setup(p => p.Open()); _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); _channelMock.InSequence(sequence).Setup(p => p.Dispose()); _subsystemSession = new SubsystemSessionStub( @@ -81,12 +80,6 @@ public void IsOpenShouldReturnFalse() Assert.IsFalse(_subsystemSession.IsOpen); } - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - [TestMethod] public void DisposeOnChannelShouldBeInvokedOnce() { diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs index 5878f1a9d..a03d4be80 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs @@ -106,12 +106,6 @@ public void IsOpenShouldReturnFalseWhenSessionIsNotConnected() _channelMock.Verify(p => p.IsOpen, Times.Once); } - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - [TestMethod] public void DisposeOnChannelShouldNeverBeInvoked() { diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs index 661783264..41d879f78 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs @@ -48,7 +48,6 @@ protected void Arrange() _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); _channelMock.InSequence(sequence).Setup(p => p.Open()); _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); _channelMock.InSequence(sequence).Setup(p => p.Dispose()); _subsystemSession = new SubsystemSessionStub( diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs index b724e14d5..e52e3e1b6 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs @@ -6,6 +6,7 @@ using Moq; using Renci.SshNet.Channels; using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; namespace Renci.SshNet.Tests.Classes { @@ -76,8 +77,8 @@ public void DisconnectHasNeverFired() [TestMethod] public void ErrorOccurredHaveFiredOnce() { - Assert.AreEqual(1, _errorOccurredRegister.Count); - Assert.AreSame(_onDataReceivedException, _errorOccurredRegister[0].Exception); + Assert.AreEqual(1, _errorOccurredRegister.Count, _errorOccurredRegister.AsString()); + Assert.AreSame(_onDataReceivedException, _errorOccurredRegister[0].Exception, _errorOccurredRegister.AsString()); } [TestMethod] diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs index 887330e53..3853b7ccb 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs @@ -6,6 +6,7 @@ using Moq; using Renci.SshNet.Channels; using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; namespace Renci.SshNet.Tests.Classes { @@ -72,8 +73,8 @@ public void DisconnectHasNeverFired() [TestMethod] public void ErrorOccurredHasFiredOnce() { - Assert.AreEqual(1, _errorOccurredRegister.Count); - Assert.AreSame(_channelExceptionEventArgs.Exception, _errorOccurredRegister[0].Exception); + Assert.AreEqual(1, _errorOccurredRegister.Count, _errorOccurredRegister.AsString()); + Assert.AreSame(_channelExceptionEventArgs.Exception, _errorOccurredRegister[0].Exception, _errorOccurredRegister.AsString()); } [TestMethod] @@ -96,12 +97,6 @@ public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); } - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - [TestMethod] public void DisposeOnChannelShouldNeverBeInvoked() { diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs index 6cb47486a..d434802eb 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs @@ -46,7 +46,6 @@ protected void Arrange() _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); _channelMock.InSequence(sequence).Setup(p => p.Open()); _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); _channelMock.InSequence(sequence).Setup(p => p.Dispose()); _subsystemSession = new SubsystemSessionStub( diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs index 318c64ae9..fd49ea738 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs @@ -93,12 +93,6 @@ public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); } - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - [TestMethod] public void DisposeOnChannelShouldNeverBeInvoked() { diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs index df4f0f599..7bcefa3c0 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs @@ -44,7 +44,6 @@ protected void Arrange() _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); _channelMock.InSequence(sequence).Setup(p => p.Open()); _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); _channelMock.InSequence(sequence).Setup(p => p.Dispose()); _subsystemSession = new SubsystemSessionStub( diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs index aa2a135d0..c2d93cf43 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs @@ -6,6 +6,7 @@ using Moq; using Renci.SshNet.Channels; using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; namespace Renci.SshNet.Tests.Classes { @@ -72,8 +73,8 @@ public void DisconnectHasNeverFired() [TestMethod] public void ErrorOccurredHasFiredOnce() { - Assert.AreEqual(1, _errorOccurredRegister.Count); - Assert.AreSame(_errorOccurredEventArgs.Exception, _errorOccurredRegister[0].Exception); + Assert.AreEqual(1, _errorOccurredRegister.Count, _errorOccurredRegister.AsString()); + Assert.AreSame(_errorOccurredEventArgs.Exception, _errorOccurredRegister[0].Exception, _errorOccurredRegister.AsString()); } [TestMethod] @@ -96,12 +97,6 @@ public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); } - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - [TestMethod] public void DisposeOnChannelShouldNeverBeInvoked() { diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs index f59b0fcf9..728857e55 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs @@ -46,7 +46,6 @@ protected void Arrange() _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); _channelMock.InSequence(sequence).Setup(p => p.Open()); _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); _channelMock.InSequence(sequence).Setup(p => p.Dispose()); _subsystemSession = new SubsystemSessionStub( diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs index f8e5ef0cd..70b53f58f 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs @@ -45,7 +45,6 @@ protected void Arrange() _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); _channelMock.InSequence(sequence).Setup(p => p.Open()); _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); _channelMock.InSequence(sequence).Setup(p => p.Dispose()); _subsystemSession = new SubsystemSessionStub( diff --git a/src/Renci.SshNet.Tests/Common/Extensions.cs b/src/Renci.SshNet.Tests/Common/Extensions.cs new file mode 100644 index 000000000..68a2923ff --- /dev/null +++ b/src/Renci.SshNet.Tests/Common/Extensions.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Common +{ + internal static class Extensions + { + public static string AsString(this IList exceptionEvents) + { + if (exceptionEvents.Count == 0) + return string.Empty; + + string reportedExceptions = string.Empty; + foreach (var exceptionEvent in exceptionEvents) + reportedExceptions += exceptionEvent.Exception.ToString(); + + return reportedExceptions; + } + } +} diff --git a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj index 41cf3e958..a2f78e61a 100644 --- a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj +++ b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj @@ -90,33 +90,33 @@ - - - - - - - - - - - - + + + + + + + + + + + + - + - - - + + + - - - + + + @@ -238,7 +238,7 @@ - + @@ -458,6 +458,7 @@ + diff --git a/src/Renci.SshNet/Channels/Channel.cs b/src/Renci.SshNet/Channels/Channel.cs index dc2c6efd5..21fb4b1fc 100644 --- a/src/Renci.SshNet/Channels/Channel.cs +++ b/src/Renci.SshNet/Channels/Channel.cs @@ -13,10 +13,6 @@ namespace Renci.SshNet.Channels /// internal abstract class Channel : IChannel { - private const int Initial = 0; - private const int Considered = 1; - private const int Sent = 2; - private EventWaitHandle _channelClosedWaitHandle = new ManualResetEvent(false); private EventWaitHandle _channelServerWindowAdjustWaitHandle = new ManualResetEvent(false); private EventWaitHandle _errorOccuredWaitHandle = new ManualResetEvent(false); @@ -31,11 +27,10 @@ internal abstract class Channel : IChannel /// Holds a value indicating whether the SSH_MSG_CHANNEL_CLOSE has been sent to the remote party. /// /// - /// 0 when the SSH_MSG_CHANNEL_CLOSE message has not been sent or considered - /// 1 when sending a SSH_MSG_CHANNEL_CLOSE message to the remote party is under consideration - /// 2 when this message has been sent to the remote party + /// true when a SSH_MSG_CHANNEL_CLOSE message has been sent to the other party; + /// otherwise, false. /// - private int _closeMessageSent; + private bool _closeMessageSent; /// /// Holds a value indicating whether a SSH_MSG_CHANNEL_CLOSE has been received from the other @@ -60,11 +55,10 @@ internal abstract class Channel : IChannel /// Holds a value indicating whether the SSH_MSG_CHANNEL_EOF has been sent to the remote party. /// /// - /// 0 when the SSH_MSG_CHANNEL_EOF message has not been sent or considered - /// 1 when sending a SSH_MSG_CHANNEL_EOF message to the remote party is under consideration - /// 2 when this message has been sent to the remote party + /// true when a SSH_MSG_CHANNEL_EOF message has been sent to the remote party; + /// otherwise, false. /// - private int _eofMessageSent; + private bool _eofMessageSent; /// /// Occurs when an exception is thrown when processing channel messages. @@ -86,16 +80,16 @@ protected Channel(ISession session, uint localChannelNumber, uint localWindowSiz LocalPacketSize = localPacketSize; LocalWindowSize = localWindowSize; - _session.ChannelWindowAdjustReceived += OnChannelWindowAdjust; - _session.ChannelDataReceived += OnChannelData; - _session.ChannelExtendedDataReceived += OnChannelExtendedData; - _session.ChannelEofReceived += OnChannelEof; - _session.ChannelCloseReceived += OnChannelClose; - _session.ChannelRequestReceived += OnChannelRequest; - _session.ChannelSuccessReceived += OnChannelSuccess; - _session.ChannelFailureReceived += OnChannelFailure; - _session.ErrorOccured += Session_ErrorOccured; - _session.Disconnected += Session_Disconnected; + session.ChannelWindowAdjustReceived += OnChannelWindowAdjust; + session.ChannelDataReceived += OnChannelData; + session.ChannelExtendedDataReceived += OnChannelExtendedData; + session.ChannelEofReceived += OnChannelEof; + session.ChannelCloseReceived += OnChannelClose; + session.ChannelRequestReceived += OnChannelRequest; + session.ChannelSuccessReceived += OnChannelSuccess; + session.ChannelFailureReceived += OnChannelFailure; + session.ErrorOccured += Session_ErrorOccured; + session.Disconnected += Session_Disconnected; } /// @@ -336,14 +330,6 @@ public void SendData(byte[] data, int offset, int size) } } - /// - /// Closes the channel. - /// - public void Close() - { - Close(true); - } - #region Channel virtual methods /// @@ -405,9 +391,15 @@ protected virtual void OnClose() { _closeMessageReceived = true; + // signal that SSH_MSG_CHANNEL_CLOSE message was received from server + var channelClosedWaitHandle = _channelClosedWaitHandle; + if (channelClosedWaitHandle != null) + channelClosedWaitHandle.Set(); + // close the channel - Close(false); + Close(); + // raise event signaling that the server has closed the channel var closed = Closed; if (closed != null) closed(this, new ChannelEventArgs(LocalChannelNumber)); @@ -498,8 +490,11 @@ public void SendEof() if (!IsOpen) throw CreateChannelClosedException(); - _session.SendMessage(new ChannelEofMessage(RemoteChannelNumber)); - _eofMessageSent = Sent; + lock (this) + { + _session.SendMessage(new ChannelEofMessage(RemoteChannelNumber)); + _eofMessageSent = true; + } } /// @@ -512,66 +507,54 @@ protected void WaitOnHandle(WaitHandle waitHandle) } /// - /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to - /// be received from the server. + /// Closes the channel, waiting for the SSH_MSG_CHANNEL_CLOSE message to be received from the server. /// - /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. - protected virtual void Close(bool wait) + protected virtual void Close() { - // send EOF message first when channel need to be closed, and the remote party has not already sent - // a SSH_MSG_CHANNEL_EOF or SSH_MSG_CHANNEL_CLOSE message - // - // note that we might have had a race condition here when the remote party sends a SSH_MSG_CHANNEL_CLOSE - // immediately after it has sent a SSH_MSG_CHANNEL_EOF message - // - // in that case, we would risk sending a SSH_MSG_CHANNEL_EOF message after the remote party has - // closed its end of the channel - // - // as a solution for this issue we only send a SSH_MSG_CHANNEL_EOF message if we haven't received a - // SSH_MSG_CHANNEL_EOF or SSH_MSG_CHANNEL_CLOSE message from the remote party - if (Interlocked.CompareExchange(ref _eofMessageSent, Considered, Initial) == Initial) + // synchronize sending SSH_MSG_CHANNEL_EOF and SSH_MSG_CHANNEL_CLOSE to ensure that these messages + // are sent in that other; when both the client and the server attempt to close the channel at the + // same time we would otherwise risk sending the SSH_MSG_CHANNEL_EOF after the SSH_MSG_CHANNEL_CLOSE + // message causing the server to disconnect the session. + + lock (this) { - if (!_closeMessageReceived && !_eofMessageReceived && IsOpen && IsConnected) + // send EOF message first the following conditions are met: + // * we have not sent a SSH_MSG_CHANNEL_EOF message + // * remote party has not already sent a SSH_MSG_CHANNEL_EOF message + // * remote party has not already sent a SSH_MSG_CHANNEL_CLOSE message + // * the channel is open + // * the session is connected + if (!_eofMessageSent && !_closeMessageReceived && !_eofMessageReceived && IsOpen && IsConnected) { if (TrySendMessage(new ChannelEofMessage(RemoteChannelNumber))) - _eofMessageSent = Sent; + { + _eofMessageSent = true; + } } - } - // send message to close the channel on the server - if (Interlocked.CompareExchange(ref _closeMessageSent, Considered, Initial) == Initial) - { - // ignore sending close message when client is not connected or the channel is closed - if (IsOpen && IsConnected) + // send message to close the channel on the server when it has not already been sent + // and the channel is open and the session is connected + if (!_closeMessageSent && IsOpen && IsConnected) { if (TrySendMessage(new ChannelCloseMessage(RemoteChannelNumber))) - _closeMessageSent = Sent; + { + _closeMessageSent = true; + + // wait for channel to be closed if we actually sent a close message (either to initiate closing + // the channel, or as response to a SSH_MSG_CHANNEL_CLOSE message sent by the server + try + { + WaitOnHandle(_channelClosedWaitHandle); + } + catch (SshConnectionException) + { + // ignore connection failures as we're closing the channel anyway + } + } } - } - - // mark the channel closed - IsOpen = false; - // wait for channel to be closed if we actually sent a close message (either to initiate closing - // the channel, or as response to a SSH_MSG_CHANNEL_CLOSE message sent by the server - if (wait && _closeMessageSent == Sent) - { - try - { - WaitOnHandle(_channelClosedWaitHandle); - } - catch (SshConnectionException) - { - // ignore connection failures as we're closing the channel anyway - } + IsOpen = false; } - - // reset indicators in case we want to reopen the channel; these are safe to reset - // since the channel is marked closed by now - _eofMessageSent = Initial; - _eofMessageReceived = false; - _closeMessageReceived = false; - _closeMessageSent = Initial; } protected virtual void OnDisconnected() @@ -700,10 +683,6 @@ private void OnChannelClose(object sender, MessageEventArgs { OnChannelException(ex); } - - var channelClosedWaitHandle = _channelClosedWaitHandle; - if (channelClosedWaitHandle != null) - channelClosedWaitHandle.Set(); } } @@ -846,7 +825,7 @@ protected virtual void Dispose(bool disposing) if (disposing) { - Close(false); + Close(); var session = _session; if (session != null) diff --git a/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs b/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs index 9ae5d6766..60ff3b283 100644 --- a/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs +++ b/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs @@ -137,11 +137,9 @@ private void ShutdownSocket(SocketShutdown how) } /// - /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to - /// be received from the server. + /// Closes the channel, waiting for the SSH_MSG_CHANNEL_CLOSE message to be received from the server. /// - /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. - protected override void Close(bool wait) + protected override void Close() { var forwardedPort = _forwardedPort; if (forwardedPort != null) @@ -156,8 +154,8 @@ protected override void Close(bool wait) // if the FIN/ACK is not sent in time, the socket will be closed after the channel is closed ShutdownSocket(SocketShutdown.Send); - // close the SSH channel, and mark the channel closed - base.Close(wait); + // close the SSH channel + base.Close(); // close the socket CloseSocket(); diff --git a/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs b/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs index 9ebc369eb..4cd3e9f5c 100644 --- a/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs +++ b/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs @@ -142,11 +142,9 @@ private void CloseSocket() } /// - /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to - /// be received from the server. + /// Closes the channel waiting for the SSH_MSG_CHANNEL_CLOSE message to be received from the server. /// - /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. - protected override void Close(bool wait) + protected override void Close() { var forwardedPort = _forwardedPort; if (forwardedPort != null) @@ -162,7 +160,7 @@ protected override void Close(bool wait) ShutdownSocket(SocketShutdown.Send); // close the SSH channel, and mark the channel closed - base.Close(wait); + base.Close(); // close the socket CloseSocket(); diff --git a/src/Renci.SshNet/Channels/ChannelSession.cs b/src/Renci.SshNet/Channels/ChannelSession.cs index 580cbb4da..72edcc251 100644 --- a/src/Renci.SshNet/Channels/ChannelSession.cs +++ b/src/Renci.SshNet/Channels/ChannelSession.cs @@ -113,22 +113,9 @@ protected override void OnOpenFailure(uint reasonCode, string description, strin _channelOpenResponseWaitHandle.Set(); } - /// - /// Called when channel is closed by the server. - /// - protected override void OnClose() + protected override void Close() { - base.OnClose(); - - // This timeout needed since when channel is closed it does not immediately becomes available - // but it takes time for the server to clean up resource and allow new channels to be created. - ThreadAbstraction.Sleep(100); - } - - protected override void Close(bool wait) - { - base.Close(wait); - + base.Close(); ReleaseSemaphore(); } diff --git a/src/Renci.SshNet/Channels/IChannel.cs b/src/Renci.SshNet/Channels/IChannel.cs index cfa5dcd25..c3fb67d81 100644 --- a/src/Renci.SshNet/Channels/IChannel.cs +++ b/src/Renci.SshNet/Channels/IChannel.cs @@ -60,11 +60,6 @@ internal interface IChannel : IDisposable /// The channel has not been opened, or the open has not yet been confirmed. uint RemotePacketSize { get; } - /// - /// Closes the channel. - /// - void Close(); - /// /// Gets a value indicating whether this channel is open. /// diff --git a/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs b/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs index 051fc77c2..6f50e778a 100644 --- a/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs +++ b/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs @@ -43,10 +43,5 @@ internal interface IChannelDirectTcpip : IDisposable /// Binds the channel to the remote host. /// void Bind(); - - /// - /// Closes the channel. - /// - void Close(); } } diff --git a/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs b/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs index f97fd1a46..7bc165a8d 100644 --- a/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs +++ b/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs @@ -20,10 +20,5 @@ internal interface IChannelForwardedTcpip : IDisposable /// The endpoint to connect to. /// The forwarded port for which the channel is opened. void Bind(IPEndPoint remoteEndpoint, IForwardedPort forwardedPort); - - /// - /// Closes the channel. - /// - void Close(); } } diff --git a/src/Renci.SshNet/ForwardedPortDynamic.NET.cs b/src/Renci.SshNet/ForwardedPortDynamic.NET.cs index 018ec6ef1..1fe24040a 100644 --- a/src/Renci.SshNet/ForwardedPortDynamic.NET.cs +++ b/src/Renci.SshNet/ForwardedPortDynamic.NET.cs @@ -124,21 +124,14 @@ private void ProcessAccept(Socket clientSocket) { channel.Exception += Channel_Exception; - try + if (!HandleSocks(channel, clientSocket, Session.ConnectionInfo.Timeout)) { - if (!HandleSocks(channel, clientSocket, Session.ConnectionInfo.Timeout)) - { - CloseClientSocket(clientSocket); - return; - } - - // start receiving from client socket (and sending to server) - channel.Bind(); - } - finally - { - channel.Close(); + CloseClientSocket(clientSocket); + return; } + + // start receiving from client socket (and sending to server) + channel.Bind(); } } catch (Exception exp) diff --git a/src/Renci.SshNet/ForwardedPortLocal.NET.cs b/src/Renci.SshNet/ForwardedPortLocal.NET.cs index a4b3095fb..ed8f89c08 100644 --- a/src/Renci.SshNet/ForwardedPortLocal.NET.cs +++ b/src/Renci.SshNet/ForwardedPortLocal.NET.cs @@ -125,7 +125,6 @@ private void ProcessAccept(Socket clientSocket) channel.Exception += Channel_Exception; channel.Open(Host, Port, this, clientSocket); channel.Bind(); - channel.Close(); } } catch (Exception exp) diff --git a/src/Renci.SshNet/ForwardedPortRemote.cs b/src/Renci.SshNet/ForwardedPortRemote.cs index 835201190..4b5915de3 100644 --- a/src/Renci.SshNet/ForwardedPortRemote.cs +++ b/src/Renci.SshNet/ForwardedPortRemote.cs @@ -251,7 +251,6 @@ private void Session_ChannelOpening(object sender, MessageEventArgs void WaitOnHandle(WaitHandle waitHandle); + /// + /// Waits for the specified handle or the exception handle for the receive thread + /// to signal within the specified timeout. + /// + /// The wait handle. + /// The time to wait for any of the handles to become signaled. + /// A received package was invalid or failed the message integrity check. + /// None of the handles are signaled in time and the session is not disconnecting. + /// A socket error was signaled while receiving messages from the server. + /// + /// When neither handles are signaled in time and the session is not closing, then the + /// session is disconnected. + /// + void WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout); + /// /// Occurs when message received /// diff --git a/src/Renci.SshNet/ScpClient.NET.cs b/src/Renci.SshNet/ScpClient.NET.cs index 52dd51b56..4814ecc0c 100644 --- a/src/Renci.SshNet/ScpClient.NET.cs +++ b/src/Renci.SshNet/ScpClient.NET.cs @@ -40,8 +40,6 @@ public void Upload(FileInfo fileInfo, string path) CheckReturnCode(input); InternalUpload(channel, input, fileInfo, fileInfo.Name); - - channel.Close(); } } @@ -77,8 +75,6 @@ public void Upload(DirectoryInfo directoryInfo, string path) SendData(channel, "E\n"); CheckReturnCode(input); - - channel.Close(); } } @@ -107,8 +103,6 @@ public void Download(string filename, FileInfo fileInfo) SendConfirmation(channel); // Send reply InternalDownload(channel, input, fileInfo); - - channel.Close(); } } @@ -137,8 +131,6 @@ public void Download(string directoryName, DirectoryInfo directoryInfo) SendConfirmation(channel); // Send reply InternalDownload(channel, input, directoryInfo); - - channel.Close(); } } diff --git a/src/Renci.SshNet/ScpClient.cs b/src/Renci.SshNet/ScpClient.cs index 3b16dca30..c10233c5f 100644 --- a/src/Renci.SshNet/ScpClient.cs +++ b/src/Renci.SshNet/ScpClient.cs @@ -187,8 +187,6 @@ public void Upload(Stream source, string path) } InternalUpload(channel, input, source, path); - - channel.Close(); } } @@ -239,8 +237,6 @@ public void Download(string filename, Stream destination) { SendConfirmation(channel, 1, string.Format("\"{0}\" is not valid protocol message.", message)); } - - channel.Close(); } } diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 6f91f1998..d60562bf0 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -722,7 +722,25 @@ private void Disconnect(DisconnectReason reason, string message) /// void ISession.WaitOnHandle(WaitHandle waitHandle) { - WaitOnHandle(waitHandle); + WaitOnHandle(waitHandle, ConnectionInfo.Timeout); + } + + /// + /// Waits for the specified handle or the exception handle for the receive thread + /// to signal within the specified timeout. + /// + /// The wait handle. + /// The time to wait for any of the handles to become signaled. + /// A received package was invalid or failed the message integrity check. + /// None of the handles are signaled in time and the session is not disconnecting. + /// A socket error was signaled while receiving messages from the server. + /// + /// When neither handles are signaled in time and the session is not closing, then the + /// session is disconnected. + /// + void ISession.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout) + { + WaitOnHandle(waitHandle, timeout); } /// @@ -1929,7 +1947,7 @@ private void MessageListener() var readSockets = new List {_socket}; // remain in message loop until socket is shut down or until we're disconnecting - while (!_isDisconnecting) + while (true) { #if FEATURE_SOCKET_POLL Socket.Select(readSockets, null, null, -1); diff --git a/src/Renci.SshNet/Shell.cs b/src/Renci.SshNet/Shell.cs index 0674882e9..e2e2b5587 100644 --- a/src/Renci.SshNet/Shell.cs +++ b/src/Renci.SshNet/Shell.cs @@ -191,7 +191,7 @@ public void Stop() if (_channel != null) { - _channel.Close(); + _channel.Dispose(); } } @@ -238,11 +238,7 @@ private void Channel_Closed(object sender, ChannelEventArgs e) ThreadAbstraction.ExecuteThread(() => Stopping(this, new EventArgs())); } - if (_channel.IsOpen) - { - _channel.Close(); - } - + _channel.Dispose(); _channelClosedWaitHandle.Set(); _input.Dispose(); diff --git a/src/Renci.SshNet/ShellStream.cs b/src/Renci.SshNet/ShellStream.cs index e57c8d58d..91df9fb02 100644 --- a/src/Renci.SshNet/ShellStream.cs +++ b/src/Renci.SshNet/ShellStream.cs @@ -723,7 +723,7 @@ private void Session_ErrorOccured(object sender, ExceptionEventArgs e) private void Session_Disconnected(object sender, EventArgs e) { if (_channel != null) - _channel.Close(); + _channel.Dispose(); } private void Channel_Closed(object sender, ChannelEventArgs e) diff --git a/src/Renci.SshNet/SshCommand.cs b/src/Renci.SshNet/SshCommand.cs index 292f67c82..37e91da08 100644 --- a/src/Renci.SshNet/SshCommand.cs +++ b/src/Renci.SshNet/SshCommand.cs @@ -310,11 +310,6 @@ public string EndExecute(IAsyncResult asyncResult) // wait for operation to complete (or time out) WaitOnHandle(_asyncResult.AsyncWaitHandle); - if (_channel.IsOpen) - { - _channel.Close(); - } - UnsubscribeFromEventsAndDisposeChannel(_channel); _channel = null; @@ -348,7 +343,7 @@ public void CancelAsync() if (_channel != null && _channel.IsOpen && _asyncResult != null) { // TODO: check with Oleg if we shouldn't dispose the channel and uninitialize it ? - _channel.Close(); + _channel.Dispose(); } } diff --git a/src/Renci.SshNet/SubsystemSession.cs b/src/Renci.SshNet/SubsystemSession.cs index 88a511a67..324e296b2 100644 --- a/src/Renci.SshNet/SubsystemSession.cs +++ b/src/Renci.SshNet/SubsystemSession.cs @@ -134,7 +134,6 @@ public void Disconnect() channel.DataReceived -= Channel_DataReceived; channel.Exception -= Channel_Exception; channel.Closed -= Channel_Closed; - channel.Close(); channel.Dispose(); _channel = null; }