From e563ff0bfa54dec1a9640cb573117ee535579134 Mon Sep 17 00:00:00 2001 From: Dmitry Tsarevich Date: Fri, 22 Sep 2023 16:38:56 +0300 Subject: [PATCH] Use OS-agnostic socket error codes to allow tests run on different OSes 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. --- src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs index c2798104a..db03567b4 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs @@ -20,7 +20,7 @@ public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostN } catch (SocketException ex) { - Assert.IsTrue(ex.ErrorCode is (int) SocketError.HostNotFound or (int) SocketError.TryAgain); + Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain); } } @@ -38,7 +38,7 @@ public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCode } catch (SocketException ex) { - Assert.IsTrue(ex.ErrorCode is (int) SocketError.HostNotFound or (int) SocketError.TryAgain); + Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain); } } }