|
@@ -2,12 +2,14 @@
|
|
|
using System.Diagnostics;
|
|
using System.Diagnostics;
|
|
|
using System.Globalization;
|
|
using System.Globalization;
|
|
|
using System.Net.Sockets;
|
|
using System.Net.Sockets;
|
|
|
|
|
+using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
|
|
using Moq;
|
|
using Moq;
|
|
|
|
|
|
|
|
using Renci.SshNet.Common;
|
|
using Renci.SshNet.Common;
|
|
|
|
|
+using Renci.SshNet.Tests.Common;
|
|
|
|
|
|
|
|
namespace Renci.SshNet.Tests.Classes.Connection
|
|
namespace Renci.SshNet.Tests.Classes.Connection
|
|
|
{
|
|
{
|
|
@@ -15,7 +17,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
|
|
|
public class Socks5ConnectorTest_Connect_TimeoutConnectingToProxy : Socks5ConnectorTestBase
|
|
public class Socks5ConnectorTest_Connect_TimeoutConnectingToProxy : Socks5ConnectorTestBase
|
|
|
{
|
|
{
|
|
|
private ConnectionInfo _connectionInfo;
|
|
private ConnectionInfo _connectionInfo;
|
|
|
- private SshOperationTimeoutException _actualException;
|
|
|
|
|
|
|
+ private Exception _actualException;
|
|
|
private Socket _clientSocket;
|
|
private Socket _clientSocket;
|
|
|
private Stopwatch _stopWatch;
|
|
private Stopwatch _stopWatch;
|
|
|
|
|
|
|
@@ -59,21 +61,34 @@ namespace Renci.SshNet.Tests.Classes.Connection
|
|
|
{
|
|
{
|
|
|
_actualException = ex;
|
|
_actualException = ex;
|
|
|
}
|
|
}
|
|
|
|
|
+ catch (SocketException ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ _actualException = ex;
|
|
|
|
|
+ }
|
|
|
finally
|
|
finally
|
|
|
{
|
|
{
|
|
|
_stopWatch.Stop();
|
|
_stopWatch.Stop();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [TestMethod]
|
|
|
|
|
- public void ConnectShouldHaveThrownSshOperationTimeoutException()
|
|
|
|
|
|
|
+ [TestMethodForPlatform(nameof(OSPlatform.Windows))]
|
|
|
|
|
+ public void ConnectShouldHaveThrownSshOperationTimeoutExceptionOnWindows()
|
|
|
{
|
|
{
|
|
|
Assert.IsNull(_actualException.InnerException);
|
|
Assert.IsNull(_actualException.InnerException);
|
|
|
|
|
+ Assert.IsInstanceOfType<SshOperationTimeoutException>(_actualException);
|
|
|
Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "Connection failed to establish within {0} milliseconds.", _connectionInfo.Timeout.TotalMilliseconds), _actualException.Message);
|
|
Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "Connection failed to establish within {0} milliseconds.", _connectionInfo.Timeout.TotalMilliseconds), _actualException.Message);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- [TestMethod]
|
|
|
|
|
- public void ConnectShouldHaveRespectedTimeout()
|
|
|
|
|
|
|
+ [TestMethodForPlatform(nameof(OSPlatform.Linux))]
|
|
|
|
|
+ public void ConnectShouldHaveThrownSshOperationTimeoutExceptionOnLinux()
|
|
|
|
|
+ {
|
|
|
|
|
+ Assert.IsNull(_actualException.InnerException);
|
|
|
|
|
+ Assert.IsInstanceOfType<SocketException>(_actualException);
|
|
|
|
|
+ Assert.AreEqual("Connection refused", _actualException.Message);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [TestMethodForPlatform(nameof(OSPlatform.Windows))]
|
|
|
|
|
+ public void ConnectShouldHaveRespectedTimeoutOnWindows()
|
|
|
{
|
|
{
|
|
|
var errorText = string.Format("Elapsed: {0}, Timeout: {1}",
|
|
var errorText = string.Format("Elapsed: {0}, Timeout: {1}",
|
|
|
_stopWatch.ElapsedMilliseconds,
|
|
_stopWatch.ElapsedMilliseconds,
|