Skip to content

Commit

Permalink
Use OS-agnostic socket error codes to allow tests run on different OS…
Browse files Browse the repository at this point in the history
…es (#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>
  • Loading branch information
dimhotepus and WojciechNagorski authored Sep 26, 2023
1 parent 4ba591e commit dd2e552
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit dd2e552

Please sign in to comment.