SftpClientTest.GetAttributesAsync.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Renci.SshNet.Common;
  2. namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
  3. {
  4. /// <summary>
  5. /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
  6. /// </summary>
  7. public partial class SftpClientTest
  8. {
  9. [TestMethod]
  10. [TestCategory("Sftp")]
  11. public async Task Test_Sftp_GetAttributesAsync_Not_Exists()
  12. {
  13. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  14. {
  15. var cts = new CancellationTokenSource();
  16. cts.CancelAfter(TimeSpan.FromMinutes(1));
  17. await sftp.ConnectAsync(cts.Token);
  18. await Assert.ThrowsExceptionAsync<SftpPathNotFoundException>(async () => await sftp.GetAttributesAsync("/asdfgh", cts.Token));
  19. }
  20. }
  21. [TestMethod]
  22. [TestCategory("Sftp")]
  23. public async Task Test_Sftp_GetAttributesAsync_Null()
  24. {
  25. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  26. {
  27. var cts = new CancellationTokenSource();
  28. cts.CancelAfter(TimeSpan.FromMinutes(1));
  29. await sftp.ConnectAsync(cts.Token);
  30. await Assert.ThrowsExceptionAsync<ArgumentNullException>(async () => await sftp.GetAttributesAsync(null, cts.Token));
  31. }
  32. }
  33. [TestMethod]
  34. [TestCategory("Sftp")]
  35. public async Task Test_Sftp_GetAttributesAsync_Current()
  36. {
  37. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  38. {
  39. var cts = new CancellationTokenSource();
  40. cts.CancelAfter(TimeSpan.FromMinutes(1));
  41. await sftp.ConnectAsync(cts.Token);
  42. var fileAttributes = await sftp.GetAttributesAsync(".", cts.Token);
  43. Assert.IsNotNull(fileAttributes);
  44. sftp.Disconnect();
  45. }
  46. }
  47. }
  48. }