Skip to content

Commit

Permalink
Re-initialize DirectoryInfo.Name after a MoveTo() operation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexischr committed Nov 14, 2018
1 parent e30b792 commit b9974f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/System.IO.FileSystem/src/System/IO/DirectoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void MoveTo(string destDirName)

Init(originalPath: destDirName,
fullPath: destinationWithSeparator,
fileName: _name,
fileName: null,
isNormalized: true);

// Flush any cached information about the directory.
Expand Down
8 changes: 6 additions & 2 deletions src/System.IO.FileSystem/tests/DirectoryInfo/MoveTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ public virtual void Move(DirectoryInfo sourceDir, string destDir)
public void DirectoryPathUpdatesOnMove()
{
//NOTE: MoveTo adds a trailing separator character to the FullName of a DirectoryInfo
string DestName1 = GetTestFileName();
string DestName2 = GetTestFileName();
string testDirSource = Path.Combine(TestDirectory, GetTestFileName());
string testDirDest1 = Path.Combine(TestDirectory, GetTestFileName());
string testDirDest2 = Path.Combine(TestDirectory, GetTestFileName());
string testDirDest1 = Path.Combine(TestDirectory, DestName1);
string testDirDest2 = Path.Combine(TestDirectory, DestName2);

DirectoryInfo sourceDir = Directory.CreateDirectory(testDirSource);
Move(sourceDir, testDirDest1);
Assert.True(Directory.Exists(testDirDest1));
Assert.False(Directory.Exists(testDirSource));
Assert.Equal(testDirDest1 + Path.DirectorySeparatorChar, sourceDir.FullName);
Assert.Equal(DestName1, sourceDir.Name);

Move(sourceDir, testDirDest2);
Assert.True(Directory.Exists(testDirDest2));
Assert.Equal(testDirDest2 + Path.DirectorySeparatorChar, sourceDir.FullName);
Assert.Equal(DestName2, sourceDir.Name);
}

#endregion
Expand Down

0 comments on commit b9974f9

Please sign in to comment.