From 09626fb5b5935b38c1bfc0d260cd9777a92cc886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sun, 21 May 2023 09:24:06 +0200 Subject: [PATCH 1/3] Add tests for updating the cache for IFileInfo and IDirectoryInfo --- .../FileSystem/DirectoryInfo/CreateTests.cs | 25 +++++++++++++++++++ .../FileSystem/FileInfo/CreateTests.cs | 4 +++ 2 files changed, 29 insertions(+) diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs index eada3313f..2002d6a76 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs @@ -74,6 +74,31 @@ public void Create_ShouldCreateParentDirectories() result.ToString().Should().Be(path); } + [SkippableTheory] + [AutoData] + public void Create_ShouldRefreshExistsCache_ExceptOnNetFramework(string path) + { + IDirectoryInfo sut = FileSystem.DirectoryInfo.New(path); + IDirectoryInfo sut2 = FileSystem.DirectoryInfo.New(path); + sut.Exists.Should().BeFalse(); + sut2.Exists.Should().BeFalse(); + + sut.Create(); + + if (Test.IsNetFramework) + { + sut.Exists.Should().BeFalse(); + sut2.Exists.Should().BeFalse(); + } + else + { + sut.Exists.Should().BeTrue(); + sut2.Exists.Should().BeTrue(); + } + + FileSystem.Directory.Exists(path).Should().BeTrue(); + } + [SkippableTheory] [InlineData("")] [InlineData("/")] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs index 21b38fc3d..c5923f8fd 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs @@ -24,17 +24,21 @@ public void Create_MissingFile_ShouldCreateFile(string path) public void Create_ShouldRefreshExistsCache_ExceptOnNetFramework(string path) { IFileInfo sut = FileSystem.FileInfo.New(path); + IFileInfo sut2 = FileSystem.FileInfo.New(path); sut.Exists.Should().BeFalse(); + sut2.Exists.Should().BeFalse(); using FileSystemStream stream = sut.Create(); if (Test.IsNetFramework) { sut.Exists.Should().BeFalse(); + sut2.Exists.Should().BeFalse(); } else { sut.Exists.Should().BeTrue(); + sut2.Exists.Should().BeTrue(); } FileSystem.File.Exists(path).Should().BeTrue(); From 9f27bf7d7134a72334899e773b8d15dd5522733c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sun, 21 May 2023 09:32:52 +0200 Subject: [PATCH 2/3] Fix tests to be according to real file system --- .../FileSystem/DirectoryInfo/CreateTests.cs | 2 +- .../FileSystem/FileInfo/CreateTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs index 2002d6a76..7ec7c0782 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs @@ -93,7 +93,7 @@ public void Create_ShouldRefreshExistsCache_ExceptOnNetFramework(string path) else { sut.Exists.Should().BeTrue(); - sut2.Exists.Should().BeTrue(); + sut2.Exists.Should().BeFalse(); } FileSystem.Directory.Exists(path).Should().BeTrue(); diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs index c5923f8fd..559f2f410 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs @@ -38,7 +38,7 @@ public void Create_ShouldRefreshExistsCache_ExceptOnNetFramework(string path) else { sut.Exists.Should().BeTrue(); - sut2.Exists.Should().BeTrue(); + sut2.Exists.Should().BeFalse(); } FileSystem.File.Exists(path).Should().BeTrue(); From 6c4f33f0b926bbc844f935c66778852abc19e8d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sun, 21 May 2023 09:41:16 +0200 Subject: [PATCH 3/3] Check behaviour when "Exists" was not called previously --- .../FileSystem/DirectoryInfo/CreateTests.cs | 16 ++++++++++------ .../FileSystem/FileInfo/CreateTests.cs | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs index 7ec7c0782..cd9daa75b 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/CreateTests.cs @@ -76,24 +76,28 @@ public void Create_ShouldCreateParentDirectories() [SkippableTheory] [AutoData] - public void Create_ShouldRefreshExistsCache_ExceptOnNetFramework(string path) + public void Create_ShouldRefreshExistsCacheForCurrentItem_ExceptOnNetFramework(string path) { - IDirectoryInfo sut = FileSystem.DirectoryInfo.New(path); + IDirectoryInfo sut1 = FileSystem.DirectoryInfo.New(path); IDirectoryInfo sut2 = FileSystem.DirectoryInfo.New(path); - sut.Exists.Should().BeFalse(); + IDirectoryInfo sut3 = FileSystem.DirectoryInfo.New(path); + sut1.Exists.Should().BeFalse(); sut2.Exists.Should().BeFalse(); + // Do not call Exists for `sut3` - sut.Create(); + 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.Directory.Exists(path).Should().BeTrue(); diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs index 559f2f410..4567b9108 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/CreateTests.cs @@ -21,24 +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); + IFileInfo sut1 = FileSystem.FileInfo.New(path); IFileInfo sut2 = FileSystem.FileInfo.New(path); - sut.Exists.Should().BeFalse(); + 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();