SftpClientTest.ChangeDirectory.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 : IntegrationTestBase
  8. {
  9. [TestMethod]
  10. [TestCategory("Sftp")]
  11. [ExpectedException(typeof(SftpPathNotFoundException))]
  12. public void Test_Sftp_ChangeDirectory_Root_Dont_Exists()
  13. {
  14. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  15. {
  16. sftp.Connect();
  17. sftp.ChangeDirectory("/asdasd");
  18. }
  19. }
  20. [TestMethod]
  21. [TestCategory("Sftp")]
  22. [ExpectedException(typeof(SftpPathNotFoundException))]
  23. public async Task Test_Sftp_ChangeDirectory_Root_Dont_ExistsAsync()
  24. {
  25. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  26. {
  27. await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
  28. await sftp.ChangeDirectoryAsync("/asdasd", CancellationToken.None).ConfigureAwait(false);
  29. }
  30. }
  31. [TestMethod]
  32. [TestCategory("Sftp")]
  33. [ExpectedException(typeof(SftpPathNotFoundException))]
  34. public void Test_Sftp_ChangeDirectory_Root_With_Slash_Dont_Exists()
  35. {
  36. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  37. {
  38. sftp.Connect();
  39. sftp.ChangeDirectory("/asdasd/");
  40. }
  41. }
  42. [TestMethod]
  43. [TestCategory("Sftp")]
  44. [ExpectedException(typeof(SftpPathNotFoundException))]
  45. public async Task Test_Sftp_ChangeDirectory_Root_With_Slash_Dont_ExistsAsync()
  46. {
  47. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  48. {
  49. await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
  50. await sftp.ChangeDirectoryAsync("/asdasd/", CancellationToken.None).ConfigureAwait(false);
  51. }
  52. }
  53. [TestMethod]
  54. [TestCategory("Sftp")]
  55. [ExpectedException(typeof(SftpPathNotFoundException))]
  56. public void Test_Sftp_ChangeDirectory_Subfolder_Dont_Exists()
  57. {
  58. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  59. {
  60. sftp.Connect();
  61. sftp.ChangeDirectory("/asdasd/sssddds");
  62. }
  63. }
  64. [TestMethod]
  65. [TestCategory("Sftp")]
  66. [ExpectedException(typeof(SftpPathNotFoundException))]
  67. public async Task Test_Sftp_ChangeDirectory_Subfolder_Dont_ExistsAsync()
  68. {
  69. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  70. {
  71. await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
  72. await sftp.ChangeDirectoryAsync("/asdasd/sssddds", CancellationToken.None).ConfigureAwait(false);
  73. }
  74. }
  75. [TestMethod]
  76. [TestCategory("Sftp")]
  77. [ExpectedException(typeof(SftpPathNotFoundException))]
  78. public void Test_Sftp_ChangeDirectory_Subfolder_With_Slash_Dont_Exists()
  79. {
  80. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  81. {
  82. sftp.Connect();
  83. sftp.ChangeDirectory("/asdasd/sssddds/");
  84. }
  85. }
  86. [TestMethod]
  87. [TestCategory("Sftp")]
  88. [ExpectedException(typeof(SftpPathNotFoundException))]
  89. public async Task Test_Sftp_ChangeDirectory_Subfolder_With_Slash_Dont_ExistsAsync()
  90. {
  91. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  92. {
  93. await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
  94. await sftp.ChangeDirectoryAsync("/asdasd/sssddds/", CancellationToken.None).ConfigureAwait(false);
  95. }
  96. }
  97. [TestMethod]
  98. [TestCategory("Sftp")]
  99. public void Test_Sftp_ChangeDirectory_Which_Exists()
  100. {
  101. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  102. {
  103. sftp.Connect();
  104. sftp.ChangeDirectory("/usr");
  105. Assert.AreEqual("/usr", sftp.WorkingDirectory);
  106. }
  107. }
  108. [TestMethod]
  109. [TestCategory("Sftp")]
  110. public async Task Test_Sftp_ChangeDirectory_Which_ExistsAsync()
  111. {
  112. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  113. {
  114. await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
  115. await sftp.ChangeDirectoryAsync("/usr", CancellationToken.None).ConfigureAwait(false);
  116. Assert.AreEqual("/usr", sftp.WorkingDirectory);
  117. }
  118. }
  119. [TestMethod]
  120. [TestCategory("Sftp")]
  121. public void Test_Sftp_ChangeDirectory_Which_Exists_With_Slash()
  122. {
  123. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  124. {
  125. sftp.Connect();
  126. sftp.ChangeDirectory("/usr/");
  127. Assert.AreEqual("/usr", sftp.WorkingDirectory);
  128. }
  129. }
  130. [TestMethod]
  131. [TestCategory("Sftp")]
  132. public async Task Test_Sftp_ChangeDirectory_Which_Exists_With_SlashAsync()
  133. {
  134. using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
  135. {
  136. await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
  137. await sftp.ChangeDirectoryAsync("/usr/", CancellationToken.None).ConfigureAwait(false);
  138. Assert.AreEqual("/usr", sftp.WorkingDirectory);
  139. }
  140. }
  141. }
  142. }