Skip to content

Commit c5b487c

Browse files
committed
Fix tests.
1 parent 8094c09 commit c5b487c

File tree

2 files changed

+14
-32
lines changed

2 files changed

+14
-32
lines changed

src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,8 @@ public void ErrorOccurredIsRaisedOnce()
6464

6565
var connectionException = (SshConnectionException) exception;
6666
Assert.AreEqual(DisconnectReason.ConnectionLost, connectionException.DisconnectReason);
67-
68-
var innerException = exception.InnerException;
69-
Assert.IsNotNull(innerException);
70-
Assert.AreEqual(typeof(SocketException), innerException.GetType());
71-
72-
var socketException = (SocketException) innerException;
73-
Assert.AreSame(connectionException.Message, socketException.Message);
74-
Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode);
67+
Assert.IsNull(connectionException.InnerException);
68+
Assert.AreEqual("An established connection was aborted by the server.", connectionException.Message);
7569
}
7670

7771
[TestMethod]
@@ -140,7 +134,7 @@ public void ISession_TrySendMessageShouldReturnFalse()
140134
}
141135

142136
[TestMethod]
143-
public void ISession_WaitOnHandle_WaitHandle_ShouldThrowSshConnectionExceptionDetailingConnectionReset()
137+
public void ISession_WaitOnHandle_WaitHandle_ShouldThrowSshConnectionException()
144138
{
145139
var session = (ISession) Session;
146140
var waitHandle = new ManualResetEvent(false);
@@ -152,22 +146,14 @@ public void ISession_WaitOnHandle_WaitHandle_ShouldThrowSshConnectionExceptionDe
152146
}
153147
catch (SshConnectionException ex)
154148
{
149+
Assert.AreEqual("An established connection was aborted by the server.", ex.Message);
150+
Assert.IsNull(ex.InnerException);
155151
Assert.AreEqual(DisconnectReason.ConnectionLost, ex.DisconnectReason);
156-
157-
var innerException = ex.InnerException;
158-
Assert.IsNotNull(innerException);
159-
Assert.AreEqual(typeof(SocketException), innerException.GetType());
160-
161-
var socketException = (SocketException) ex.InnerException;
162-
Assert.IsNotNull(socketException);
163-
Assert.IsNull(socketException.InnerException);
164-
Assert.AreSame(innerException.Message, ex.Message);
165-
Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode);
166152
}
167153
}
168154

169155
[TestMethod]
170-
public void ISession_WaitOnHandle_WaitHandleAndTimeout_ShouldThrowSshConnectionExceptionDetailingConnectionReset()
156+
public void ISession_WaitOnHandle_WaitHandleAndTimeout_ShouldThrowSshConnectionException()
171157
{
172158
var session = (ISession) Session;
173159
var waitHandle = new ManualResetEvent(false);
@@ -180,16 +166,8 @@ public void ISession_WaitOnHandle_WaitHandleAndTimeout_ShouldThrowSshConnectionE
180166
catch (SshConnectionException ex)
181167
{
182168
Assert.AreEqual(DisconnectReason.ConnectionLost, ex.DisconnectReason);
183-
184-
var innerException = ex.InnerException;
185-
Assert.IsNotNull(innerException);
186-
Assert.AreEqual(typeof(SocketException), innerException.GetType());
187-
188-
var socketException = (SocketException) ex.InnerException;
189-
Assert.IsNotNull(socketException);
190-
Assert.IsNull(socketException.InnerException);
191-
Assert.AreSame(innerException.Message, socketException.Message);
192-
Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode);
169+
Assert.IsNull(ex.InnerException);
170+
Assert.AreEqual("An established connection was aborted by the server.", ex.Message);
193171
}
194172
}
195173

src/Renci.SshNet/Session.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,8 +1942,7 @@ private void MessageListener()
19421942
var connectionClosedOrDataAvailable = socket.Poll(-1, SelectMode.SelectRead);
19431943
if (connectionClosedOrDataAvailable && socket.Available == 0)
19441944
{
1945-
// connection with SSH server was closed or socket was disposed;
1946-
// break out of the message loop
1945+
// connection with SSH server was closed or connection was reset
19471946
break;
19481947
}
19491948
#elif FEATURE_SOCKET_SELECT
@@ -1993,6 +1992,8 @@ private void MessageListener()
19931992
// * a call to Disconnect()
19941993
// * a call to Dispose()
19951994
// * a SSH_MSG_DISCONNECT received from server
1995+
1996+
Console.WriteLine("B");
19961997
break;
19971998
}
19981999

@@ -2001,13 +2002,16 @@ private void MessageListener()
20012002
{
20022003
// connection with SSH server was closed;
20032004
// break out of the message loop
2005+
Console.WriteLine("C");
20042006
break;
20052007
}
20062008

20072009
// process message
20082010
message.Process(this);
20092011
}
20102012

2013+
Console.WriteLine("D");
2014+
20112015
// connection with SSH server was closed or socket was disposed
20122016
RaiseError(CreateConnectionAbortedByServerException());
20132017
}

0 commit comments

Comments
 (0)