Files
Rob Hague c7a0ca93de Add another allowed SocketError value in tests (#1457)
These have started failing for me locally (Win11). SocketError.NoData means
"The requested name or IP address was not found on the name server." which
lines up with what we are testing here.
2024-08-11 07:47:42 +02:00

47 lines
1.5 KiB
C#

using System.Net.Sockets;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Renci.SshNet.Tests.Classes
{
[TestClass]
public class SftpClientTest_Connect
{
[TestMethod]
public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound()
{
var connectionInfo = new ConnectionInfo("invalid.", 40, "user",
new KeyboardInteractiveAuthenticationMethod("user"));
var sftpClient = new SftpClient(connectionInfo);
try
{
sftpClient.Connect();
Assert.Fail();
}
catch (SocketException ex)
{
Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain or SocketError.NoData);
}
}
[TestMethod]
public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound()
{
var connectionInfo = new ConnectionInfo("localhost", 40, "user", ProxyTypes.Http, "invalid.", 80,
"proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user"));
var sftpClient = new SftpClient(connectionInfo);
try
{
sftpClient.Connect();
Assert.Fail();
}
catch (SocketException ex)
{
Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain or SocketError.NoData);
}
}
}
}