Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cedsan opened this issue Aug 1, 2021 · 1 comment
Labels
area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on type: bug Issues that describe misbehaving functionality

Comments

@cedsan
Copy link

cedsan commented Aug 1, 2021

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!

@cedsan cedsan added state: needs discussion Issues that need further discussion type: bug Issues that describe misbehaving functionality labels Aug 1, 2021
@fgreinacher
Copy link
Contributor

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

@fgreinacher fgreinacher added area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on and removed state: needs discussion Issues that need further discussion labels Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on type: bug Issues that describe misbehaving functionality
Projects
None yet
Development

No branches or pull requests

2 participants