Skip to content

Commit

Permalink
coverage: Add tests for correct update of the exists cache for IFileI…
Browse files Browse the repository at this point in the history
…nfo and IDirectoryInfo (#313)

When creating a File or Directory the "Exists" property should only
update for the item where `Create()` was called.

---------

Co-authored-by: Valentin Breuß <[email protected]>
  • Loading branch information
vbreuss and vbtig authored May 21, 2023
1 parent f209d46 commit 14d980a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,35 @@ public void Create_ShouldCreateParentDirectories()
result.ToString().Should().Be(path);
}

[SkippableTheory]
[AutoData]
public void Create_ShouldRefreshExistsCacheForCurrentItem_ExceptOnNetFramework(string path)
{
IDirectoryInfo sut1 = FileSystem.DirectoryInfo.New(path);
IDirectoryInfo sut2 = FileSystem.DirectoryInfo.New(path);
IDirectoryInfo sut3 = FileSystem.DirectoryInfo.New(path);
sut1.Exists.Should().BeFalse();
sut2.Exists.Should().BeFalse();
// Do not call Exists for `sut3`

sut1.Create();

if (Test.IsNetFramework)
{
sut1.Exists.Should().BeFalse();
sut2.Exists.Should().BeFalse();
sut3.Exists.Should().BeFalse();
}
else
{
sut1.Exists.Should().BeTrue();
sut2.Exists.Should().BeFalse();
sut3.Exists.Should().BeTrue();
}

FileSystem.Directory.Exists(path).Should().BeTrue();
}

[SkippableTheory]
[InlineData("")]
[InlineData("/")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@ public void Create_MissingFile_ShouldCreateFile(string path)

[SkippableTheory]
[AutoData]
public void Create_ShouldRefreshExistsCache_ExceptOnNetFramework(string path)
public void Create_ShouldRefreshExistsCacheForCurrentItem_ExceptOnNetFramework(string path)
{
IFileInfo sut = FileSystem.FileInfo.New(path);
sut.Exists.Should().BeFalse();
IFileInfo sut1 = FileSystem.FileInfo.New(path);
IFileInfo sut2 = FileSystem.FileInfo.New(path);
IFileInfo sut3 = FileSystem.FileInfo.New(path);
sut1.Exists.Should().BeFalse();
sut2.Exists.Should().BeFalse();
// Do not call Exists for `sut3`

using FileSystemStream stream = sut.Create();
using FileSystemStream stream = sut1.Create();

if (Test.IsNetFramework)
{
sut.Exists.Should().BeFalse();
sut1.Exists.Should().BeFalse();
sut2.Exists.Should().BeFalse();
sut3.Exists.Should().BeFalse();
}
else
{
sut.Exists.Should().BeTrue();
sut1.Exists.Should().BeTrue();
sut2.Exists.Should().BeFalse();
sut3.Exists.Should().BeTrue();
}

FileSystem.File.Exists(path).Should().BeTrue();
Expand Down

0 comments on commit 14d980a

Please sign in to comment.