diff --git a/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs b/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs index a850a157d..0fcb8bfb1 100644 --- a/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs +++ b/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs @@ -55,6 +55,29 @@ public void MockDirectoryInfo_Exists(string path, bool expected) Assert.That(result, Is.EqualTo(expected)); } + [Test] + [WindowsOnly(WindowsSpecifics.UNCPaths)] + public void MockDirectoryInfo_GetFiles_ShouldWorkWithUNCPath() + { + var fileName = XFS.Path(@"\\unc\folder\file.txt"); + var directoryName = XFS.Path(@"\\unc\folder"); + // Arrange + var fileSystem = new MockFileSystem(new Dictionary + { + {fileName, ""} + }); + + var directoryInfo = new MockDirectoryInfo(fileSystem, directoryName); + + // Act + var files = directoryInfo.GetFiles(); + + // Assert + Assert.AreEqual(fileName, files[0].FullName); + } + + + [Test] public void MockDirectoryInfo_FullName_ShouldReturnFullNameWithoutIncludingTrailingPathDelimiter() { diff --git a/System.IO.Abstractions.TestingHelpers.Tests/StringExtensionsTests.cs b/System.IO.Abstractions.TestingHelpers.Tests/StringExtensionsTests.cs index 41f2ab2ce..e9a750040 100644 --- a/System.IO.Abstractions.TestingHelpers.Tests/StringExtensionsTests.cs +++ b/System.IO.Abstractions.TestingHelpers.Tests/StringExtensionsTests.cs @@ -112,5 +112,13 @@ public void TrimSlashes_SlashRoot_PreserveSlashRoot() { Assert.AreEqual("/", "/".TrimSlashes()); } + + [TestCase(@"\\unc\folder\file.txt", @"\\unc\folder\file.txt")] + [TestCase(@"//unc/folder/file.txt", @"\\unc\folder\file.txt")] + [WindowsOnly(WindowsSpecifics.UNCPaths)] + public void NormalizeSlashes_KeepsUNCPathPrefix(string path, string expectedValue) + { + Assert.AreEqual(expectedValue, path.NormalizeSlashes()); + } } } diff --git a/System.IO.Abstractions.TestingHelpers/StringExtensions.cs b/System.IO.Abstractions.TestingHelpers/StringExtensions.cs index f8640c861..2d32641bc 100644 --- a/System.IO.Abstractions.TestingHelpers/StringExtensions.cs +++ b/System.IO.Abstractions.TestingHelpers/StringExtensions.cs @@ -99,7 +99,7 @@ public static string NormalizeSlashes(this string path) // UNC Paths start with double slash but no reason // to have more than 2 slashes at the start of a path - if (XFS.IsWindowsPlatform() && prefixSeps.Length > 2) + if (XFS.IsWindowsPlatform() && prefixSeps.Length >= 2) { prefixSeps = prefixSeps.Substring(0, 2); }