2
0

PosixPathTest_GetDirectoryName.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Renci.SshNet.Common;
  4. namespace Renci.SshNet.Tests.Classes.Common
  5. {
  6. [TestClass]
  7. public class PosixPathTest_GetDirectoryName
  8. {
  9. [TestMethod]
  10. public void Path_Null()
  11. {
  12. const string path = null;
  13. try
  14. {
  15. _ = PosixPath.GetDirectoryName(path);
  16. Assert.Fail();
  17. }
  18. catch (ArgumentNullException ex)
  19. {
  20. Assert.IsNull(ex.InnerException);
  21. Assert.AreEqual("path", ex.ParamName);
  22. }
  23. }
  24. [TestMethod]
  25. public void Path_Empty()
  26. {
  27. var path = string.Empty;
  28. var actual = PosixPath.GetDirectoryName(path);
  29. Assert.IsNotNull(actual);
  30. Assert.AreEqual(".", actual);
  31. }
  32. [TestMethod]
  33. public void Path_TrailingForwardSlash()
  34. {
  35. var path = "/abc/";
  36. var actual = PosixPath.GetDirectoryName(path);
  37. Assert.IsNotNull(actual);
  38. Assert.AreEqual("/abc", actual);
  39. }
  40. [TestMethod]
  41. public void Path_FileWithoutNoDirectory()
  42. {
  43. var path = "abc.log";
  44. var actual = PosixPath.GetDirectoryName(path);
  45. Assert.IsNotNull(actual);
  46. Assert.AreEqual(".", actual);
  47. }
  48. [TestMethod]
  49. public void Path_FileInRootDirectory()
  50. {
  51. var path = "/abc.log";
  52. var actual = PosixPath.GetDirectoryName(path);
  53. Assert.IsNotNull(actual);
  54. Assert.AreEqual("/", actual);
  55. }
  56. [TestMethod]
  57. public void Path_RootDirectoryOnly()
  58. {
  59. var path = "/";
  60. var actual = PosixPath.GetDirectoryName(path);
  61. Assert.IsNotNull(actual);
  62. Assert.AreEqual("/", actual);
  63. }
  64. [TestMethod]
  65. public void Path_FileInNonRootDirectory()
  66. {
  67. var path = "/home/sshnet/xyz";
  68. var actual = PosixPath.GetDirectoryName(path);
  69. Assert.IsNotNull(actual);
  70. Assert.AreEqual("/home/sshnet", actual);
  71. }
  72. [TestMethod]
  73. public void Path_BackslashIsNotConsideredDirectorySeparator()
  74. {
  75. var path = "/home\\abc.log";
  76. var actual = PosixPath.GetDirectoryName(path);
  77. Assert.IsNotNull(actual);
  78. Assert.AreEqual("/", actual);
  79. }
  80. [TestMethod]
  81. public void Path_ColonIsNotConsideredPathSeparator()
  82. {
  83. var path = "/home:abc.log";
  84. var actual = PosixPath.GetDirectoryName(path);
  85. Assert.IsNotNull(actual);
  86. Assert.AreEqual("/", actual);
  87. }
  88. [TestMethod]
  89. public void Path_LeadingWhitespace()
  90. {
  91. var path = " / \tabc";
  92. var actual = PosixPath.GetDirectoryName(path);
  93. Assert.IsNotNull(actual);
  94. Assert.AreEqual(" ", actual);
  95. }
  96. [TestMethod]
  97. public void Path_TrailingWhitespace()
  98. {
  99. var path = "/abc \t ";
  100. var actual = PosixPath.GetDirectoryName(path);
  101. Assert.IsNotNull(actual);
  102. Assert.AreEqual("/", actual);
  103. }
  104. [TestMethod]
  105. public void Path_OnlyWhitespace()
  106. {
  107. var path = " ";
  108. var actual = PosixPath.GetDirectoryName(path);
  109. Assert.IsNotNull(actual);
  110. Assert.AreEqual(".", actual);
  111. }
  112. [TestMethod]
  113. public void Path_FileNameOnlyWhitespace()
  114. {
  115. var path = "/home/\t ";
  116. var actual = PosixPath.GetDirectoryName(path);
  117. Assert.IsNotNull(actual);
  118. Assert.AreEqual("/home", actual);
  119. }
  120. }
  121. }