SftpClientTest.CreateDirectory.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Common;
  3. using Renci.SshNet.Tests.Common;
  4. using Renci.SshNet.Tests.Properties;
  5. using System;
  6. namespace Renci.SshNet.Tests.Classes
  7. {
  8. /// <summary>
  9. /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
  10. /// </summary>
  11. public partial class SftpClientTest : TestBase
  12. {
  13. [TestMethod]
  14. [TestCategory("Sftp")]
  15. [ExpectedException(typeof(SshConnectionException))]
  16. public void Test_Sftp_CreateDirectory_Without_Connecting()
  17. {
  18. using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  19. {
  20. sftp.CreateDirectory("test");
  21. }
  22. }
  23. [TestMethod]
  24. [TestCategory("Sftp")]
  25. [TestCategory("integration")]
  26. public void Test_Sftp_CreateDirectory_In_Current_Location()
  27. {
  28. using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  29. {
  30. sftp.Connect();
  31. sftp.CreateDirectory("test");
  32. sftp.Disconnect();
  33. }
  34. }
  35. [TestMethod]
  36. [TestCategory("Sftp")]
  37. [TestCategory("integration")]
  38. [ExpectedException(typeof(SftpPermissionDeniedException))]
  39. public void Test_Sftp_CreateDirectory_In_Forbidden_Directory()
  40. {
  41. if (Resources.USERNAME == "root")
  42. Assert.Fail("Must not run this test as root!");
  43. using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  44. {
  45. sftp.Connect();
  46. sftp.CreateDirectory("/sbin/test");
  47. sftp.Disconnect();
  48. }
  49. }
  50. [TestMethod]
  51. [TestCategory("Sftp")]
  52. [TestCategory("integration")]
  53. [ExpectedException(typeof(SftpPathNotFoundException))]
  54. public void Test_Sftp_CreateDirectory_Invalid_Path()
  55. {
  56. using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  57. {
  58. sftp.Connect();
  59. sftp.CreateDirectory("/abcdefg/abcefg");
  60. sftp.Disconnect();
  61. }
  62. }
  63. [TestMethod]
  64. [TestCategory("Sftp")]
  65. [TestCategory("integration")]
  66. [ExpectedException(typeof(SshException))]
  67. public void Test_Sftp_CreateDirectory_Already_Exists()
  68. {
  69. using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  70. {
  71. sftp.Connect();
  72. sftp.CreateDirectory("test");
  73. sftp.CreateDirectory("test");
  74. sftp.Disconnect();
  75. }
  76. }
  77. [TestMethod]
  78. [TestCategory("Sftp")]
  79. [Description("Test passing null to CreateDirectory.")]
  80. [ExpectedException(typeof(ArgumentException))]
  81. public void Test_Sftp_CreateDirectory_Null()
  82. {
  83. using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  84. {
  85. sftp.CreateDirectory(null);
  86. }
  87. }
  88. }
  89. }