Skip to content

Commit

Permalink
Run test against different Delete APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
tmds committed Nov 22, 2021
1 parent 599514a commit 63953d7
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/libraries/System.IO.FileSystem/tests/Directory/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,6 @@ public void DeletingSymLinkDoesntDeleteTarget()
Assert.False(Directory.Exists(linkPath), "linkPath should no longer exist");
}

[ConditionalFact(nameof(CanCreateSymbolicLinks))]
public void RecursiveDeletingDoesntFollowLinks()
{
var target = GetTestFilePath();
Directory.CreateDirectory(target);

var fileInTarget = Path.Combine(target, GetTestFileName());
File.WriteAllText(fileInTarget, "");

var linkParent = GetTestFilePath();
Directory.CreateDirectory(linkParent);

var linkPath = Path.Combine(linkParent, GetTestFileName());
Assert.True(MountHelper.CreateSymbolicLink(linkPath, target, isDirectory: true));

// Both the symlink and the target exist
Assert.True(Directory.Exists(target), "target should exist");
Assert.True(Directory.Exists(linkPath), "linkPath should exist");
Assert.True(File.Exists(fileInTarget), "fileInTarget should exist");

// Delete the parent folder of the symlink.
Directory.Delete(linkParent, true);

// Target should still exist
Assert.True(Directory.Exists(target), "target should still exist");
Assert.False(Directory.Exists(linkPath), "linkPath should no longer exist");
Assert.True(File.Exists(fileInTarget), "fileInTarget should exist");
}

[ConditionalFact(nameof(UsingNewNormalization))]
public void ExtendedDirectoryWithSubdirectories()
{
Expand Down Expand Up @@ -319,5 +290,34 @@ public void RecursiveDelete_ShouldThrowIOExceptionIfContainedFileInUse()
}
Assert.True(testDir.Exists);
}

[ConditionalFact(nameof(CanCreateSymbolicLinks))]
public void RecursiveDeletingDoesntFollowLinks()
{
var target = GetTestFilePath();
Directory.CreateDirectory(target);

var fileInTarget = Path.Combine(target, GetTestFileName());
File.WriteAllText(fileInTarget, "");

var linkParent = GetTestFilePath();
Directory.CreateDirectory(linkParent);

var linkPath = Path.Combine(linkParent, GetTestFileName());
Assert.NotNull(Directory.CreateSymbolicLink(linkPath, target));

// Both the symlink and the target exist
Assert.True(Directory.Exists(target), "target should exist");
Assert.True(Directory.Exists(linkPath), "linkPath should exist");
Assert.True(File.Exists(fileInTarget), "fileInTarget should exist");

// Delete the parent folder of the symlink.
Delete(linkParent, true);

// Target should still exist
Assert.True(Directory.Exists(target), "target should still exist");
Assert.False(Directory.Exists(linkPath), "linkPath should no longer exist");
Assert.True(File.Exists(fileInTarget), "fileInTarget should exist");
}
}
}

0 comments on commit 63953d7

Please sign in to comment.