-
Notifications
You must be signed in to change notification settings - Fork 266
Closed
Labels
area: testinghelpersIssues that address the testing helpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked onIssues that are ready for being worked onstate: releasedIssues that are releasedIssues that are releasedtype: bugIssues that describe misbehaving functionalityIssues that describe misbehaving functionality
Description
Describe the bug
Recursively deleting a directory with read only file results in an inconsistent state of the MockFileSystem:
- The deletion results (as expected) in an
UnauthorizedAccessException - The file is still present (
File.Existsreturnstrue) - The directory however is removed (
Directory.Existsreturnsfalse)
To Reproduce
Consider the following unit test (using Xunit and FluentAssertions):
[Fact]
public void DeleteDirectoryRecursive_WithReadOnlyFile_ShouldThrowExceptionAndNotDeleteDirectory()
{
var sut = new MockFileSystem();
sut.Directory.CreateDirectory("foo");
sut.File.WriteAllText("foo/bar.txt", "xyz");
sut.File.SetAttributes("foo/bar.txt", FileAttributes.ReadOnly);
var exception = Record.Exception(() =>
{
sut.Directory.Delete("foo", true);
});
exception.Should().BeAssignableTo<UnauthorizedAccessException>();
sut.File.Exists("foo/bar.txt").Should().BeTrue();
sut.Directory.Exists("foo").Should().BeTrue();
}This test fails at the last line, as the directory is deleted, although the file still exists, resulting in an inconsistent state of the MockFileSystem
Expected behavior
The unit test should be successful.
Metadata
Metadata
Assignees
Labels
area: testinghelpersIssues that address the testing helpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked onIssues that are ready for being worked onstate: releasedIssues that are releasedIssues that are releasedtype: bugIssues that describe misbehaving functionalityIssues that describe misbehaving functionality