Skip to content

Commit 2e36643

Browse files
jfleppFlepp Jannfgreinacher
authored
fixed unix file move (#701)
Co-authored-by: Flepp Jann <JFlepp@Hamilton.ch> Co-authored-by: Florian Greinacher <florian@greinacher.de>
1 parent 4f0b75c commit 2e36643

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/System.IO.Abstractions.TestingHelpers/MockFileSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void MoveDirectory(string sourcePath, string destPath)
248248

249249
foreach (var path in affectedPaths)
250250
{
251-
var newPath = StringOperations.Replace(path, sourcePath, destPath);
251+
var newPath = Path.Combine(destPath, path.Substring(sourcePath.Length).TrimStart(Path.DirectorySeparatorChar));
252252
var entry = files[path];
253253
entry.Path = newPath;
254254
files[newPath] = entry;

tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ public void MockFileSystem_AddFilesFromEmbeddedResource_ShouldAddAllTheFiles()
252252
Assert.Contains(XFS.Path(@"C:\SecondTestFile.txt"), fileSystem.AllFiles.ToList());
253253
}
254254

255+
[Test]
256+
public void MockFileSystem_MoveDirectory_MovesDirectoryWithoutRenamingFiles()
257+
{
258+
var fileSystem = new MockFileSystem();
259+
fileSystem.AddFile(XFS.Path(@"C:\dir1\dir1\dir1.txt"), string.Empty);
260+
261+
fileSystem.MoveDirectory(XFS.Path(@"C:\dir1"), XFS.Path(@"C:\dir2"));
262+
263+
var expected = new[] { XFS.Path(@"C:\dir2\dir1\dir1.txt") };
264+
CollectionAssert.AreEquivalent(expected, fileSystem.AllFiles);
265+
}
266+
255267
[Test]
256268
public void MockFileSystem_MoveDirectoryAndFile_ShouldMoveCorrectly()
257269
{

0 commit comments

Comments
 (0)