Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage: Add tests for correct update of the exists cache for IFileInfo and IDirectoryInfo #313

Merged
merged 3 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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