You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mock FileInfo.Delete does not consider MockFileData.AllowedFileShare property #794
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.
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
Activity
[-]Mock FileInfo.Delete recursive does not consider nested files MockFileData.AllowedFileShare property[/-][+]Mock FileInfo.Delete does not consider MockFileData.AllowedFileShare property[/+]fgreinacher commentedon Jan 9, 2022
Thanks for reporting!
pianomanjh commentedon Feb 3, 2022
It should be mentioned that Linux filesystems do not honor the FileShare flag at all.
dotnet/runtime#24432
fix for TestableIO#794. use the same Delete path that MockFile does, …
fix: make MockFileInfo.Delete honor FileAccess (#807)
github-actions commentedon Feb 4, 2022
This is addressed in release v16.1.10.