Fix tests.

This commit is contained in:
drieseng
2020-05-03 17:37:48 +02:00
parent 8094c0917a
commit c5b487c057
2 changed files with 14 additions and 32 deletions
@@ -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);
}
}
+6 -2
View File
@@ -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());
}