2
0

SftpClientTest.ConnectAsync.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Net.Sockets;
  3. using System.Threading.Tasks;
  4. using Microsoft.VisualStudio.TestTools.UnitTesting;
  5. namespace Renci.SshNet.Tests.Classes
  6. {
  7. public partial class SftpClientTest
  8. {
  9. [TestMethod]
  10. public async Task ConnectAsync_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound()
  11. {
  12. var connectionInfo = new ConnectionInfo(Guid.NewGuid().ToString("N"), 40, "user",
  13. new KeyboardInteractiveAuthenticationMethod("user"));
  14. var sftpClient = new SftpClient(connectionInfo);
  15. try
  16. {
  17. await sftpClient.ConnectAsync(default);
  18. Assert.Fail();
  19. }
  20. catch (SocketException ex)
  21. {
  22. Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain, $"Socket error is {ex.SocketErrorCode}");
  23. }
  24. }
  25. [TestMethod]
  26. public async Task ConnectAsync_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound()
  27. {
  28. var connectionInfo = new ConnectionInfo("localhost", 40, "user", ProxyTypes.Http, Guid.NewGuid().ToString("N"), 80,
  29. "proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user"));
  30. var sftpClient = new SftpClient(connectionInfo);
  31. try
  32. {
  33. await sftpClient.ConnectAsync(default);
  34. Assert.Fail();
  35. }
  36. catch (SocketException ex)
  37. {
  38. Assert.IsTrue(ex.SocketErrorCode is SocketError.HostNotFound or SocketError.TryAgain, $"Socket error is {ex.SocketErrorCode}");
  39. }
  40. }
  41. }
  42. }