SftpClientTest.Connect.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Net.Sockets;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Renci.SshNet.Tests.Common;
  4. namespace Renci.SshNet.Tests.Classes
  5. {
  6. public partial class SftpClientTest : TestBase
  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.AreEqual(ex.ErrorCode, (int) SocketError.HostNotFound);
  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.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound);
  38. }
  39. }
  40. }
  41. }