Skip to content

Commit dd2e552

Browse files
Use OS-agnostic socket error codes to allow tests run on different OSes (#1179)
SocketErrorCode is OS agnostic, ErrorCode is OS specific. On Windows ErrorCode = (int) SocketErrorCode, but on Mac and Unix it is not. For example ExitCode for HostNotFound (11001) on Windows is 11001, on Mac & Unix is -131073. So testing for ExitCode == 11001 fails on Mac & Unix. Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
1 parent 4ba591e commit dd2e552

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostN
2020
}
2121
catch (SocketException ex)
2222
{
23-
Assert.IsTrue(ex.ErrorCode is (int) SocketError.HostNotFound or (int) SocketError.TryAgain);
23+
Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain);
2424
}
2525
}
2626

@@ -38,7 +38,7 @@ public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCode
3838
}
3939
catch (SocketException ex)
4040
{
41-
Assert.IsTrue(ex.ErrorCode is (int) SocketError.HostNotFound or (int) SocketError.TryAgain);
41+
Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain);
4242
}
4343
}
4444
}

0 commit comments

Comments
 (0)