-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: deleting a file with open file handles behaves consistently to t…
…he real file system (#179) This takes into account the following issues on [System.IO.Abstractions](https://github.com/TestableIO/System.IO.Abstractions): - TestableIO/System.IO.Abstractions#894 - TestableIO/System.IO.Abstractions#756
- Loading branch information
Showing
10 changed files
with
205 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
Tests/Testably.Abstractions.Tests/FileSystem/File/DeleteTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.IO; | ||
using Testably.Abstractions.FileSystem; | ||
|
||
namespace Testably.Abstractions.Tests.FileSystem.File; | ||
|
||
// ReSharper disable once PartialTypeWithSinglePart | ||
public abstract partial class DeleteTests<TFileSystem> | ||
: FileSystemTestBase<TFileSystem> | ||
where TFileSystem : IFileSystem | ||
{ | ||
[SkippableTheory] | ||
[AutoData] | ||
public void Delete_WithOpenFile_ShouldThrowIOException(string filename) | ||
{ | ||
FileSystem.Initialize(); | ||
FileSystemStream openFile = FileSystem.File.OpenWrite(filename); | ||
openFile.Write(new byte[] { 0 }, 0, 1); | ||
openFile.Flush(); | ||
Exception? exception = Record.Exception(() => | ||
{ | ||
FileSystem.File.Delete(filename); | ||
openFile.Write(new byte[] { 0 }, 0, 1); | ||
openFile.Flush(); | ||
}); | ||
|
||
if (Test.RunsOnWindows) | ||
{ | ||
exception.Should().BeOfType<IOException>() | ||
.Which.Message.Should() | ||
.Contain($"{filename}'"); | ||
FileSystem.File.Exists(filename).Should().BeTrue(); | ||
} | ||
else | ||
{ | ||
exception.Should().BeNull(); | ||
FileSystem.File.Exists(filename).Should().BeFalse(); | ||
} | ||
} | ||
} |
Oops, something went wrong.