Skip to content

MockDirectory.Delete recursive does not consider nested files MockFileData.AllowedFileShare property #747

Open

Description

@cedsan

Describe the bug
MockDirectory.Delete recursive does not consider nested files which MockFileData.AllowedFileShare property does not allow delete operation.

To Reproduce
The following test reproduces the error:

    [Test]
    public void MockDirectory_Delete_ShouldThrowIfFileAccessShareHasNoWriteOrDeleteAccess()
    {
        // Arrange
        var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
        {
            { @"c:\bar\foo.txt", new MockFileData("some demo content") },
            { @"c:\bar\baz.txt", new MockFileData("some demo content"){ AllowedFileShare = FileShare.None } }
        });
  
        // Throws exception
        Assert.Throws(typeof(IOException), () => fileSystem.File.Delete(@"c:\bar\baz.txt"));
  
        // Does not throw exception
        Assert.Throws(typeof(IOException), () => fileSystem.Directory.Delete(@"c:\bar", true));
    }

Expected behavior
I'm not sure if this is indeed a bug or I didn't understand the semantics of the AllowedFileShare property, but the behaviour seems inconsistent. In case it's a bug, I'd be happy to open a PR for it.

Thanks!

Activity

  1. added
    type: bugIssues that describe misbehaving functionality
    on Aug 1, 2021
  2. fgreinacher commented on Aug 9, 2021

    @fgreinacher
    Contributor

    Thanks for reporting. You got the idea totally right and I agree it's a gap in our implementation.

  3. added
    state: ready to pickIssues that are ready for being worked on
    and removed on Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked ontype: bugIssues that describe misbehaving functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions