-
Notifications
You must be signed in to change notification settings - Fork 258
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
fix: Refresh FileInfo & DirectoryInfo after adding to MockFileSystem #984
Conversation
Modify the `IFileInfo` and `IDirectoryInfo` overloads of `AddFile()`, `AddEmptyFile()`, or `AddDirectory()` in `MockFileSystem`, to call `Refresh()` on those objects after the paths they refer to are created.
47cfa07
to
d3e823c
Compare
Latest push has no changes; just rebased to pull in latest on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, makes sense!
…19.2.26 (#306) [](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [TestableIO.System.IO.Abstractions](https://togithub.com/TestableIO/System.IO.Abstractions) | nuget | patch | `19.2.22` -> `19.2.26` | --- ### Release Notes <details> <summary>TestableIO/System.IO.Abstractions</summary> ### [`v19.2.26`](https://togithub.com/TestableIO/System.IO.Abstractions/releases/tag/v19.2.26) ##### What's Changed - fix: Refresh FileInfo & DirectoryInfo after adding to MockFileSystem by [@​rcdailey](https://togithub.com/rcdailey) in [https://github.com/TestableIO/System.IO.Abstractions/pull/984](https://togithub.com/TestableIO/System.IO.Abstractions/pull/984) **Full Changelog**: TestableIO/System.IO.Abstractions@v19.2.25...v19.2.26 ### [`v19.2.25`](https://togithub.com/TestableIO/System.IO.Abstractions/releases/tag/v19.2.25) #### What's Changed - chore(deps): update dependency githubactionstestlogger to v2.1.0 by [@​renovate](https://togithub.com/renovate) in [https://github.com/TestableIO/System.IO.Abstractions/pull/986](https://togithub.com/TestableIO/System.IO.Abstractions/pull/986) - chore(deps): update dependency nerdbank.gitversioning to v3.6.132 by [@​renovate](https://togithub.com/renovate) in [https://github.com/TestableIO/System.IO.Abstractions/pull/987](https://togithub.com/TestableIO/System.IO.Abstractions/pull/987) - feat: Add Flush(bool) to FileSystemStream. by [@​gregington](https://togithub.com/gregington) in [https://github.com/TestableIO/System.IO.Abstractions/pull/985](https://togithub.com/TestableIO/System.IO.Abstractions/pull/985) **Full Changelog**: TestableIO/System.IO.Abstractions@v19.2.22...v19.2.25 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/Testably/Testably.Abstractions). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS43OS4xIiwidXBkYXRlZEluVmVyIjoiMzUuNzkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…19.2.26 (#306) [](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [TestableIO.System.IO.Abstractions](https://togithub.com/TestableIO/System.IO.Abstractions) | nuget | patch | `19.2.22` -> `19.2.26` | --- ### Release Notes <details> <summary>TestableIO/System.IO.Abstractions</summary> ### [`v19.2.26`](https://togithub.com/TestableIO/System.IO.Abstractions/releases/tag/v19.2.26) ##### What's Changed - fix: Refresh FileInfo & DirectoryInfo after adding to MockFileSystem by [@​rcdailey](https://togithub.com/rcdailey) in [https://github.com/TestableIO/System.IO.Abstractions/pull/984](https://togithub.com/TestableIO/System.IO.Abstractions/pull/984) **Full Changelog**: TestableIO/System.IO.Abstractions@v19.2.25...v19.2.26 ### [`v19.2.25`](https://togithub.com/TestableIO/System.IO.Abstractions/releases/tag/v19.2.25) #### What's Changed - chore(deps): update dependency githubactionstestlogger to v2.1.0 by [@​renovate](https://togithub.com/renovate) in [https://github.com/TestableIO/System.IO.Abstractions/pull/986](https://togithub.com/TestableIO/System.IO.Abstractions/pull/986) - chore(deps): update dependency nerdbank.gitversioning to v3.6.132 by [@​renovate](https://togithub.com/renovate) in [https://github.com/TestableIO/System.IO.Abstractions/pull/987](https://togithub.com/TestableIO/System.IO.Abstractions/pull/987) - feat: Add Flush(bool) to FileSystemStream. by [@​gregington](https://togithub.com/gregington) in [https://github.com/TestableIO/System.IO.Abstractions/pull/985](https://togithub.com/TestableIO/System.IO.Abstractions/pull/985) **Full Changelog**: TestableIO/System.IO.Abstractions@v19.2.22...v19.2.25 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/Testably/Testably.Abstractions). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS43OS4xIiwidXBkYXRlZEluVmVyIjoiMzUuNzkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This is addressed in release v19.2.26. |
@fgreinacher Thanks for merging this, I really appreciate it! One thing I'm noticing, is that this doesn't cover all use cases. For example, if there are other Do you have any insight here you can share? This is somewhat a pain point I only experience in unit tests, having to manually refresh file info objects. Thanks for any feedback you can share. |
@rcdailey :
The following test is successful on the real file system on all platforms: [Fact]
public void Create_ShouldRefreshExistsCacheForCurrentItem_ExceptOnNetFramework()
{
string path = "file-path-to-check",
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 = 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.File.Exists(path).Should().BeTrue();
} For reference see Testably/Testably.Abstractions#313 |
Modify the
IFileInfo
andIDirectoryInfo
overloads ofAddFile()
,AddEmptyFile()
, orAddDirectory()
inMockFileSystem
, to callRefresh()
on those objects after the paths they refer to are created.