SftpClientTest.Connect.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Net.Sockets;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. namespace Renci.SshNet.Tests.Classes
  4. {
  5. [TestClass]
  6. public class SftpClientTest_Connect
  7. {
  8. [TestMethod]
  9. public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound()
  10. {
  11. var connectionInfo = new ConnectionInfo("invalid.", 40, "user",
  12. new KeyboardInteractiveAuthenticationMethod("user"));
  13. var sftpClient = new SftpClient(connectionInfo);
  14. try
  15. {
  16. sftpClient.Connect();
  17. Assert.Fail();
  18. }
  19. catch (SocketException ex)
  20. {
  21. Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain or SocketError.NoData);
  22. }
  23. }
  24. [TestMethod]
  25. public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound()
  26. {
  27. var connectionInfo = new ConnectionInfo("localhost", 40, "user", ProxyTypes.Http, "invalid.", 80,
  28. "proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user"));
  29. var sftpClient = new SftpClient(connectionInfo);
  30. try
  31. {
  32. sftpClient.Connect();
  33. Assert.Fail();
  34. }
  35. catch (SocketException ex)
  36. {
  37. Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain or SocketError.NoData);
  38. }
  39. }
  40. }
  41. }