Description
Describe the bug
When performing a File.OpenWrite()
, followed by File.Delete()
the current implementation executes this without giving any indication anything is wrong.
even if attampting to perform a filestream.Flush()
operation on the file that is deleted.
To Reproduce
Steps to reproduce the behavior:
fileSystem = new MockFileSystem();
var openfile = fileSystem.File.OpenWrite("somefile.txt");
openfile.Write(new byte[] { 0 }, 0, 1);
openfile.Flush();
fileSystem.File.Delete("somefile.txt");
openfile.Write(new byte[] { 0 }, 0, 1);
openfile.Flush();
Expected behavior
From quick investigation, using the normal filesystem the results of the above would be different between windows and linux, but in any case will not match with the result that occurs here, which is that it all executes with no issue.
In windows the fileSystem.File.Delete("somefile.txt");
call would fail with an exception noting that the file cannot be deleted as it is open.
meanwhile on Linux it would appear to fail on the final openfile.Flush();
call, noting that there is no longer any stream.
The outcome of the operation should match one of these, but ideally should support both.