Skip to content

Commit

Permalink
fix: use correct path for wrapped FileInfo and DirectoryInfo (#1079)
Browse files Browse the repository at this point in the history
Use the full path when wrapping a `FileInfo` or `DirectoryInfo` to preserve the relevant information.

*Fixes #1049*
  • Loading branch information
vbreuss authored Jan 22, 2024
1 parent d32fedd commit 3d517f4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public IDirectoryInfo Wrap(DirectoryInfo directoryInfo)
return null;
}

return new MockDirectoryInfo(mockFileSystem, directoryInfo.Name);
return new MockDirectoryInfo(mockFileSystem, directoryInfo.FullName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public IFileInfo Wrap(FileInfo fileInfo)
return null;
}

return new MockFileInfo(mockFileSystem, fileInfo.Name);
return new MockFileInfo(mockFileSystem, fileInfo.FullName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,16 @@ public void MockDirectoryInfoFactory_Wrap_WithNull_ShouldReturnNull()

Assert.That(result, Is.Null);
}

[Test]
public void MockDirectoryInfoFactory_Wrap_ShouldKeepNameAndFullName()
{
var fs = new MockFileSystem();
var directoryInfo = new DirectoryInfo(@"C:\subfolder\file");
var wrappedDirectoryInfo = fs.DirectoryInfo.Wrap(directoryInfo);

Assert.That(wrappedDirectoryInfo.FullName, Is.EqualTo(directoryInfo.FullName));
Assert.That(wrappedDirectoryInfo.Name, Is.EqualTo(directoryInfo.Name));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,16 @@ public void MockFileInfoFactory_Wrap_WithNull_ShouldReturnNull()

Assert.That(result, Is.Null);
}

[Test]
public void MockFileInfoFactory_Wrap_ShouldKeepNameAndFullName()
{
var fs = new MockFileSystem();
var fileInfo = new FileInfo(@"C:\subfolder\file");
var wrappedFileInfo = fs.FileInfo.Wrap(fileInfo);

Assert.That(wrappedFileInfo.FullName, Is.EqualTo(fileInfo.FullName));
Assert.That(wrappedFileInfo.Name, Is.EqualTo(fileInfo.Name));
}
}
}

0 comments on commit 3d517f4

Please sign in to comment.