Files
ssh.net/test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_HostNameInvalid.cs
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

51 lines
1.5 KiB
C#

using System.Net.Sockets;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Renci.SshNet.Tests.Classes.Connection
{
[TestClass]
public class DirectConnectorTest_Connect_HostNameInvalid : DirectConnectorTestBase
{
private ConnectionInfo _connectionInfo;
private Socket _clientSocket;
private SocketException _actualException;
protected override void SetupData()
{
base.SetupData();
_connectionInfo = CreateConnectionInfo("invalid.");
_actualException = null;
_clientSocket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
}
protected override void Act()
{
try
{
_ = Connector.Connect(_connectionInfo);
Assert.Fail();
}
catch (SocketException ex)
{
_actualException = ex;
}
}
protected override void SetupMocks()
{
_ = SocketFactoryMock.Setup(p => p.Create(SocketType.Stream, ProtocolType.Tcp))
.Returns(_clientSocket);
}
[TestMethod]
public void ConnectShouldHaveThrownSocketException()
{
Assert.IsNotNull(_actualException);
Assert.IsNull(_actualException.InnerException);
Assert.IsTrue(_actualException.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain or SocketError.NoData);
}
}
}