From c5b487c057af82f6a84e0df736f76aea116bb2f6 Mon Sep 17 00:00:00 2001 From: drieseng Date: Sun, 3 May 2020 17:37:48 +0200 Subject: [PATCH] Fix tests. --- .../SessionTest_Connected_ConnectionReset.cs | 38 ++++--------------- src/Renci.SshNet/Session.cs | 8 +++- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs index c10e2799..a177317f 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs @@ -64,14 +64,8 @@ namespace Renci.SshNet.Tests.Classes var connectionException = (SshConnectionException) exception; Assert.AreEqual(DisconnectReason.ConnectionLost, connectionException.DisconnectReason); - - var innerException = exception.InnerException; - Assert.IsNotNull(innerException); - Assert.AreEqual(typeof(SocketException), innerException.GetType()); - - var socketException = (SocketException) innerException; - Assert.AreSame(connectionException.Message, socketException.Message); - Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode); + Assert.IsNull(connectionException.InnerException); + Assert.AreEqual("An established connection was aborted by the server.", connectionException.Message); } [TestMethod] @@ -140,7 +134,7 @@ namespace Renci.SshNet.Tests.Classes } [TestMethod] - public void ISession_WaitOnHandle_WaitHandle_ShouldThrowSshConnectionExceptionDetailingConnectionReset() + public void ISession_WaitOnHandle_WaitHandle_ShouldThrowSshConnectionException() { var session = (ISession) Session; var waitHandle = new ManualResetEvent(false); @@ -152,22 +146,14 @@ namespace Renci.SshNet.Tests.Classes } catch (SshConnectionException ex) { + Assert.AreEqual("An established connection was aborted by the server.", ex.Message); + Assert.IsNull(ex.InnerException); Assert.AreEqual(DisconnectReason.ConnectionLost, ex.DisconnectReason); - - var innerException = ex.InnerException; - Assert.IsNotNull(innerException); - Assert.AreEqual(typeof(SocketException), innerException.GetType()); - - var socketException = (SocketException) ex.InnerException; - Assert.IsNotNull(socketException); - Assert.IsNull(socketException.InnerException); - Assert.AreSame(innerException.Message, ex.Message); - Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode); } } [TestMethod] - public void ISession_WaitOnHandle_WaitHandleAndTimeout_ShouldThrowSshConnectionExceptionDetailingConnectionReset() + public void ISession_WaitOnHandle_WaitHandleAndTimeout_ShouldThrowSshConnectionException() { var session = (ISession) Session; var waitHandle = new ManualResetEvent(false); @@ -180,16 +166,8 @@ namespace Renci.SshNet.Tests.Classes catch (SshConnectionException ex) { Assert.AreEqual(DisconnectReason.ConnectionLost, ex.DisconnectReason); - - var innerException = ex.InnerException; - Assert.IsNotNull(innerException); - Assert.AreEqual(typeof(SocketException), innerException.GetType()); - - var socketException = (SocketException) ex.InnerException; - Assert.IsNotNull(socketException); - Assert.IsNull(socketException.InnerException); - Assert.AreSame(innerException.Message, socketException.Message); - Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("An established connection was aborted by the server.", ex.Message); } } diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 5685653b..058e589a 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -1942,8 +1942,7 @@ namespace Renci.SshNet var connectionClosedOrDataAvailable = socket.Poll(-1, SelectMode.SelectRead); if (connectionClosedOrDataAvailable && socket.Available == 0) { - // connection with SSH server was closed or socket was disposed; - // break out of the message loop + // connection with SSH server was closed or connection was reset break; } #elif FEATURE_SOCKET_SELECT @@ -1993,6 +1992,8 @@ namespace Renci.SshNet // * a call to Disconnect() // * a call to Dispose() // * a SSH_MSG_DISCONNECT received from server + + Console.WriteLine("B"); break; } @@ -2001,6 +2002,7 @@ namespace Renci.SshNet { // connection with SSH server was closed; // break out of the message loop + Console.WriteLine("C"); break; } @@ -2008,6 +2010,8 @@ namespace Renci.SshNet message.Process(this); } + Console.WriteLine("D"); + // connection with SSH server was closed or socket was disposed RaiseError(CreateConnectionAbortedByServerException()); }