Skip to content

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

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]publicvoidMockFileInfo_Delete_ShouldThrowIfFileAccessShareHasNoWriteOrDeleteAccess(){// ArrangevarfileSystem=newMockFileSystem(newDictionary<string,MockFileData>(StringComparer.OrdinalIgnoreCase){{@"c:\bar\foo.txt",newMockFileData("some demo content"){AllowedFileShare=System.IO.FileShare.None}},{@"c:\bar\baz.txt",newMockFileData("some demo content"){AllowedFileShare=System.IO.FileShare.None}},});// Throws exception, as expectedAssert.Throws(typeof(System.IO.IOException),()=>fileSystem.File.Delete(@"c:\bar\baz.txt"));varfi=fileSystem.FileInfo.FromFileName(@"c:\bar\foo.txt");// Does not throw exception, but shouldAssert.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!

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