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

Mock FileInfo.Delete does not consider MockFileData.AllowedFileShare property #794

Closed
eobeda opened this issue Jan 8, 2022 · 3 comments · Fixed by #807
Closed

Mock FileInfo.Delete does not consider MockFileData.AllowedFileShare property #794

eobeda opened this issue Jan 8, 2022 · 3 comments · Fixed by #807
Labels
area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on state: released Issues that are released type: bug Issues that describe misbehaving functionality

Comments

@eobeda
Copy link

eobeda commented Jan 8, 2022

Describe the bug
Mock FileInfo.Delete does not consider the MockFileData.AllowedFileShare property during the delete operation. Similar to #747, but on the FileInfo interface.

To Reproduce
The following test reproduces the error:

 [Test]
        public void MockFileInfo_Delete_ShouldThrowIfFileAccessShareHasNoWriteOrDeleteAccess()
        {
            // Arrange
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>(StringComparer.OrdinalIgnoreCase)
            {
                { @"c:\bar\foo.txt", new MockFileData("some demo content") { AllowedFileShare = System.IO.FileShare.None } },
                { @"c:\bar\baz.txt", new MockFileData("some demo content") { AllowedFileShare = System.IO.FileShare.None } },
            });

            // Throws exception, as expected
            Assert.Throws(typeof(System.IO.IOException), () => fileSystem.File.Delete(@"c:\bar\baz.txt"));

            var fi = fileSystem.FileInfo.FromFileName(@"c:\bar\foo.txt");

            // Does not throw exception, but should
            Assert.Throws(typeof(System.IO.IOException), () => fi.Delete());
        }

Expected behavior
As the AllowedFileShare is set to NONE, an exception should be throw when the delete is attempted.

Thanks!

@eobeda eobeda added state: needs discussion Issues that need further discussion type: bug Issues that describe misbehaving functionality labels Jan 8, 2022
@eobeda eobeda changed the title Mock FileInfo.Delete recursive does not consider nested files MockFileData.AllowedFileShare property Mock FileInfo.Delete does not consider MockFileData.AllowedFileShare property Jan 8, 2022
@fgreinacher
Copy link
Contributor

Thanks for reporting!

@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 Jan 9, 2022
@pianomanjh
Copy link
Contributor

It should be mentioned that Linux filesystems do not honor the FileShare flag at all.
dotnet/runtime#24432

pianomanjh added a commit to pianomanjh/System.IO.Abstractions that referenced this issue Feb 3, 2022
@github-actions
Copy link

github-actions bot commented Feb 4, 2022

This is addressed in release v16.1.10.

@github-actions github-actions bot added the state: released Issues that are released label Feb 4, 2022
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 state: released Issues that are released type: bug Issues that describe misbehaving functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants