Skip to content

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

Closed

Description

@eobeda

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!

Activity

  1. added
    type: bugIssues that describe misbehaving functionality
    on Jan 8, 2022
  2. changed the title [-]Mock FileInfo.Delete recursive does not consider nested files MockFileData.AllowedFileShare property[/-] [+]Mock FileInfo.Delete does not consider MockFileData.AllowedFileShare property[/+] on Jan 8, 2022
  3. fgreinacher commented on Jan 9, 2022

    @fgreinacher
    Contributor

    Thanks for reporting!

  4. added
    state: ready to pickIssues that are ready for being worked on
    and removed on Jan 9, 2022
  5. pianomanjh commented on Feb 3, 2022

    @pianomanjh
    Contributor

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

  6. added a commit that references this issue on Feb 3, 2022
  7. added a commit that references this issue on Feb 4, 2022
    c2acd1a
  8. github-actions commented on Feb 4, 2022

    @github-actions

    This is addressed in release v16.1.10.

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 onstate: releasedIssues that are releasedtype: 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