diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs
index 127bca599..243c00629 100644
--- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs
+++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectoryInfo.cs
@@ -33,7 +33,7 @@ public MockDirectoryInfo(IMockFileDataAccessor mockFileDataAccessor, string dire
{
throw new ArgumentNullException("path", StringResources.Manager.GetString("VALUE_CANNOT_BE_NULL"));
}
- if (directoryPath.Trim() == string.Empty)
+ if (PathVerifier.IsEffectivelyEmpty(directoryPath))
{
throw CommonExceptions.PathIsNotOfALegalForm("path");
}
diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs
index 0b99f6e0c..ecded9cc8 100644
--- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs
+++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFile.cs
@@ -309,7 +309,7 @@ public override bool Exists(string path)
return false;
}
- if (path.Trim() == string.Empty)
+ if (PathVerifier.IsEffectivelyEmpty(path))
{
return false;
}
diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs
index c1852f9e1..d3ad7230e 100644
--- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs
+++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockPath.cs
@@ -41,7 +41,7 @@ public override string GetFullPath(string path)
throw new ArgumentNullException(nameof(path), StringResources.Manager.GetString("VALUE_CANNOT_BE_NULL"));
}
- if (string.IsNullOrWhiteSpace(path))
+ if (PathVerifier.IsEffectivelyEmpty(path))
{
throw CommonExceptions.PathIsNotOfALegalForm(nameof(path));
}
@@ -167,7 +167,7 @@ public override string GetRelativePath(string relativeTo, string path)
throw new ArgumentNullException(nameof(relativeTo), StringResources.Manager.GetString("VALUE_CANNOT_BE_NULL"));
}
- if (string.IsNullOrWhiteSpace(relativeTo))
+ if (PathVerifier.IsEffectivelyEmpty(relativeTo))
{
throw CommonExceptions.PathIsNotOfALegalForm(nameof(relativeTo));
}
diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs
index 8034b1bc1..d464947c8 100644
--- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs
+++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs
@@ -43,7 +43,7 @@ public void IsLegalAbsoluteOrRelative(string path, string paramName)
throw new ArgumentException("Empty file name is not legal.", paramName);
}
- if (path.Trim() == string.Empty)
+ if (IsEffectivelyEmpty(path))
{
throw CommonExceptions.PathIsNotOfALegalForm(paramName);
}
@@ -67,6 +67,15 @@ public void IsLegalAbsoluteOrRelative(string path, string paramName)
}
}
+ ///
+ /// Determines whether the given path is effectively empty: empty on every platform,
+ /// and also whitespace-only on Windows. Other platforms accept whitespace-only names.
+ ///
+ internal static bool IsEffectivelyEmpty(string path)
+ {
+ return string.IsNullOrEmpty(path) || (XFS.IsWindowsPlatform() && string.IsNullOrWhiteSpace(path));
+ }
+
private static bool IsValidUseOfVolumeSeparatorChar(string path)
{
if (XFS.IsWindowsPlatform() && path.StartsWith(WINDOWS_EXTENDED_LENGTH_PATH_PREFIX))
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs
index a3f5f8f88..f3cf76d51 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs
@@ -451,6 +451,22 @@ public async Task MockDirectoryInfo_Constructor_ShouldThrowArgumentException_IfA
await That(exception.Message).StartsWith("The path is not of a legal form.");
}
+ [Test]
+ [UnixOnly(UnixSpecifics.WhitespaceOnlyNames)]
+ public async Task MockDirectoryInfo_Constructor_ShouldAcceptWhitespaceOnlyNameOnUnix()
+ {
+ // Arrange
+ var fileSystem = new MockFileSystem();
+ var directoryInfo = fileSystem.DirectoryInfo.New(" ");
+
+ // Act
+ directoryInfo.Create();
+
+ // Assert
+ await That(directoryInfo.FullName).IsEqualTo(fileSystem.Path.Combine(fileSystem.Directory.GetCurrentDirectory(), " "));
+ await That(fileSystem.Directory.Exists(" ")).IsTrue();
+ }
+
[TestCase(@"c:\temp\folder\folder")]
[TestCase(@"..\..\..\Desktop")]
public async Task MockDirectoryInfo_ToString_ShouldReturnDirectoryName(string directoryName)
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs
index e0e617b7a..2e654ccb4 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectorySymlinkTests.cs
@@ -106,6 +106,7 @@ public async Task MockDirectory_CreateSymbolicLink_ShouldFailWithEmptyTarget()
}
[Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockDirectory_CreateSymbolicLink_ShouldFailWithIllegalPath()
{
// Arrange
@@ -121,6 +122,7 @@ public async Task MockDirectory_CreateSymbolicLink_ShouldFailWithIllegalPath()
}
[Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockDirectory_CreateSymbolicLink_ShouldFailWithIllegalTarget()
{
// Arrange
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllLinesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllLinesTests.cs
index f67ed4c76..dae05c4ab 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllLinesTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileAppendAllLinesTests.cs
@@ -62,6 +62,7 @@ public async Task MockFile_AppendAllLines_ShouldThrowArgumentExceptionIfPathIsZe
[TestCase(" ")]
[TestCase(" ")]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_AppendAllLines_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
// Arrange
@@ -196,6 +197,7 @@ public async Task MockFile_AppendAllLinesAsync_ShouldThrowArgumentExceptionIfPat
[TestCase(" ")]
[TestCase(" ")]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_AppendAllLinesAsync_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
// Arrange
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs
index 7e81754a3..5ca4a8d6a 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCopyTests.cs
@@ -324,6 +324,7 @@ public async Task MockFile_Copy_ShouldThrowArgumentExceptionWhenSourceIsEmpty_Pa
}
[Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_Copy_ShouldThrowArgumentExceptionWhenSourceIsStringOfBlanks()
{
string sourceFilePath = " ";
@@ -358,6 +359,7 @@ public async Task MockFile_Copy_ShouldThrowArgumentNullExceptionWhenTargetIsNull
}
[Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_Copy_ShouldThrowArgumentExceptionWhenTargetIsStringOfBlanks()
{
string sourceFilePath = XFS.Path(@"c:\something\demo.txt");
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs
index e63005dde..e1264a229 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileCreateTests.cs
@@ -124,6 +124,7 @@ public async Task MockFile_Create_ShouldThrowArgumentNullExceptionIfPathIsNull1(
[TestCase(" ")]
[TestCase(" ")]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_Create_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
// Arrange
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileDeleteTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileDeleteTests.cs
index 9012b04e3..0f474bfcf 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileDeleteTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileDeleteTests.cs
@@ -25,6 +25,7 @@ public async Task MockFile_Delete_ShouldDeleteFile()
[TestCase(" ")]
[TestCase(" ")]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_Delete_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
// Arrange
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeTests.cs
index 0e4429a14..8a6a4cec6 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeTests.cs
@@ -7,6 +7,7 @@ public class MockFileGetCreationTimeTests
{
[TestCase(" ")]
[TestCase(" ")]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_GetCreationTime_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
// Arrange
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeUtcTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeUtcTests.cs
index db39b178c..f5f826852 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeUtcTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetCreationTimeUtcTests.cs
@@ -7,6 +7,7 @@ public class MockFileGetCreationTimeUtcTests
{
[TestCase(" ")]
[TestCase(" ")]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_GetCreationTimeUtc_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
// Arrange
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeTests.cs
index 0f18507a7..0c3a1fbb7 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeTests.cs
@@ -7,6 +7,7 @@ public class MockFileGetLastAccessTimeTests
{
[TestCase(" ")]
[TestCase(" ")]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_GetLastAccessTime_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
// Arrange
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeUtcTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeUtcTests.cs
index 0495110a4..16a7fcc69 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeUtcTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastAccessTimeUtcTests.cs
@@ -7,6 +7,7 @@ public class MockFileGetLastAccessTimeUtcTests
{
[TestCase(" ")]
[TestCase(" ")]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_GetLastAccessTimeUtc_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
// Arrange
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeTests.cs
index 218868919..dbf07fe6f 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeTests.cs
@@ -7,6 +7,7 @@ public class MockFileGetLastWriteTimeTests
{
[TestCase(" ")]
[TestCase(" ")]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_GetLastWriteTime_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
// Arrange
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeUtcTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeUtcTests.cs
index b607d73e4..12b936690 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeUtcTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileGetLastWriteTimeUtcTests.cs
@@ -6,6 +6,7 @@ public class MockFileGetLastWriteTimeUtcTests
{
[TestCase(" ")]
[TestCase(" ")]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_GetLastWriteTimeUtc_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
// Arrange
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
index 7afb8347e..c8829f823 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
@@ -20,6 +20,35 @@ public async Task MockFileInfo_NullPath_ThrowArgumentNullException()
}
+ [Test]
+ [UnixOnly(UnixSpecifics.WhitespaceOnlyNames)]
+ public async Task MockFileInfo_WhitespaceOnlyName_ShouldBeLegalOnUnix()
+ {
+ var fileSystem = new MockFileSystem();
+ var currentDirectory = fileSystem.Directory.GetCurrentDirectory();
+ var fileInfo = fileSystem.FileInfo.New(" ");
+
+ fileSystem.File.WriteAllText(" ", "Demo text content");
+
+ await That(fileInfo.FullName).IsEqualTo(fileSystem.Path.Combine(currentDirectory, " "));
+ await That(fileInfo.Exists).IsTrue();
+ await That(fileSystem.File.Exists(" ")).IsTrue();
+ await That(fileSystem.File.ReadAllText(" ")).IsEqualTo("Demo text content");
+ await That(fileSystem.Directory.GetFiles(currentDirectory)).Contains(fileInfo.FullName);
+ }
+
+ [Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
+ public async Task MockFileInfo_WhitespaceOnlyName_ShouldThrowArgumentExceptionOnWindows()
+ {
+ var fileSystem = new MockFileSystem();
+
+ Action action = () => fileSystem.FileInfo.New(" ");
+
+ var exception = await That(action).Throws();
+ await That(exception.Message).StartsWith("The path is not of a legal form.");
+ }
+
[Test]
public async Task MockFileInfo_Exists_ShouldReturnTrueIfFileExistsInMemoryFileSystem()
{
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileMoveTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileMoveTests.cs
index 8032d3ad0..d42f85f4a 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileMoveTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileMoveTests.cs
@@ -288,6 +288,7 @@ public async Task MockFile_Move_ShouldThrowArgumentExceptionWhenSourceIsEmpty_Pa
}
[Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_Move_ShouldThrowArgumentExceptionWhenSourceIsStringOfBlanks()
{
string sourceFilePath = " ";
@@ -322,6 +323,7 @@ public async Task MockFile_Move_ShouldThrowArgumentNullExceptionWhenTargetIsNull
}
[Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_Move_ShouldThrowArgumentExceptionWhenTargetIsStringOfBlanks()
{
string sourceFilePath = XFS.Path(@"c:\something\demo.txt");
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSetAttributesTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSetAttributesTests.cs
index ef597c6d5..64d901c94 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSetAttributesTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSetAttributesTests.cs
@@ -39,8 +39,18 @@ public async Task MockFile_SetAttributes_ShouldSetAttributesOnDirectory()
}
[Test]
- [TestCase("", FileAttributes.Normal)]
+ public async Task MockFile_SetAttributes_ShouldThrowArgumentExceptionIfPathIsEmpty()
+ {
+ var fileSystem = new MockFileSystem();
+
+ Action action = () => fileSystem.File.SetAttributes("", FileAttributes.Normal);
+
+ await That(action).Throws();
+ }
+
+ [Test]
[TestCase(" ", FileAttributes.Normal)]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_SetAttributes_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path, FileAttributes attributes)
{
var fileSystem = new MockFileSystem();
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs
index 0b92c94b0..deed17548 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSymlinkTests.cs
@@ -112,6 +112,7 @@ public async Task MockFile_CreateSymbolicLink_ShouldFailWithEmptyTarget()
}
[Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_CreateSymbolicLink_ShouldFailWithIllegalPath()
{
// Arrange
@@ -128,6 +129,7 @@ public async Task MockFile_CreateSymbolicLink_ShouldFailWithIllegalPath()
}
[Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task MockFile_CreateSymbolicLink_ShouldFailWithIllegalTarget()
{
// Arrange
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs
index e614de495..60c750757 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs
@@ -267,6 +267,7 @@ public async Task GetFullPath_EmptyValue_ShouldThrowArgumentException()
}
[Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task GetFullPath_WithWhiteSpace_ShouldThrowArgumentException()
{
var mockFileSystem = new MockFileSystem();
@@ -535,6 +536,7 @@ public async Task GetRelativePath_WhenPathIsNull_ShouldThrowArgumentNullExceptio
}
[Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task GetRelativePath_WhenPathIsWhitespace_ShouldThrowArgumentException()
{
var mockPath = new MockFileSystem().Path;
@@ -561,6 +563,7 @@ public async Task GetRelativePath_WhenRelativeToNull_ShouldThrowArgumentNullExce
}
[Test]
+ [WindowsOnly(WindowsSpecifics.StrictPathRules)]
public async Task GetRelativePath_WhenRelativeToIsWhitespace_ShouldThrowArgumentException()
{
var mockPath = new MockFileSystem().Path;
@@ -572,6 +575,18 @@ public async Task GetRelativePath_WhenRelativeToIsWhitespace_ShouldThrowArgument
await That(exception.ParamName).IsEqualTo("relativeTo");
}
+
+ [TestCase(" ", "foo", "../foo")]
+ [TestCase("foo", " ", "../ ")]
+ [UnixOnly(UnixSpecifics.WhitespaceOnlyNames)]
+ public async Task GetRelativePath_WithWhitespaceOnlyName_ShouldWorkOnUnix(string relativeTo, string path, string expected)
+ {
+ var mockPath = new MockFileSystem().Path;
+
+ var result = mockPath.GetRelativePath(relativeTo, path);
+
+ await That(result).IsEqualTo(expected);
+ }
#endif
#if FEATURE_PATH_EXISTS
diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/UnixSpecifics.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/UnixSpecifics.cs
index 24dcf0f59..cd421f1c2 100644
--- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/UnixSpecifics.cs
+++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/UnixSpecifics.cs
@@ -5,4 +5,6 @@ internal static class UnixSpecifics
public const string SlashRoot = "Filesystem root is just '/' on Unix";
public const string CaseSensitivity = "Paths are case-sensitive on Unix";
+
+ public const string WhitespaceOnlyNames = "Whitespace-only names are legal on Unix";
}
\ No newline at end of file