Skip to content

Commit c61a14f

Browse files
authored
Merge pull request #505 from vigneshmoha/relativepathbug_475
Fix for #475: Made changes to MockDirectory class to resolve the bug
2 parents bfa61db + 5402836 commit c61a14f

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,20 @@ public void MockDirectory_GetFiles_Returns_Files()
788788
Assert.AreEqual(testPath, entries.First());
789789
}
790790

791+
[Test]
792+
public void MockDirectory_GetFiles_Returns_Files_WithRelativePath()
793+
{
794+
// arrange
795+
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
796+
797+
string directory = XFS.Path(@"C:\foo");
798+
799+
fileSystem.Directory.SetCurrentDirectory(directory);
800+
fileSystem.AddFile(XFS.Path(@"C:\test.txt"), new MockFileData("Some ASCII text."));
801+
802+
Assert.AreEqual(fileSystem.Directory.GetFiles(XFS.Path(@"..\")).Length, 1); // Assert with relative path
803+
}
804+
791805
[Test]
792806
public void MockDirectory_GetFiles_ShouldThrowAnArgumentNullException_IfSearchPatternIsNull()
793807
{

System.IO.Abstractions.TestingHelpers/MockDirectory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,13 @@ private string[] GetFilesInternal(
212212
CheckSearchPattern(searchPattern);
213213
path = path.TrimSlashes();
214214
path = path.NormalizeSlashes();
215+
path = mockFileDataAccessor.Path.GetFullPath(path);
215216

216217
if (!Exists(path))
217218
{
218219
throw CommonExceptions.CouldNotFindPartOfPath(path);
219220
}
220221

221-
path = EnsureAbsolutePath(path);
222-
223222
if (!path.EndsWith(Path.DirectorySeparatorChar.ToString()))
224223
{
225224
path += Path.DirectorySeparatorChar;

0 commit comments

Comments
 (0)