-
Notifications
You must be signed in to change notification settings - Fork 256
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: Make mocked data lazy-loaded #900
base: main
Are you sure you want to change the base?
Conversation
@fgreinacher this partly implicitly reverts a change that you made here. In #899, we noticed that the behaviour of |
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.
There are several aspects not checked or which needs to be changed, see the inline comments
tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
Outdated
Show resolved
Hide resolved
tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
Outdated
Show resolved
Hide resolved
tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs
Outdated
Show resolved
Hide resolved
Test is renamed from MockFileInfo_Exists_ShouldReturnCachedData to MockFileInfo_Exists_LazyLoadsData, and now checks that the lazy-loading in MockFileInfo works correctly. Co-authored-by: Peter Baumann <[email protected]>
`Refresh()` needs to be called in the Arrange phase, so that the data is not simply lazy-loaded in the assertion case. Explicitly loading MockFileData by calling `Refres()` enforces lazy-loading to be done. Co-authored-by: Peter Baumann <[email protected]>
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.
Only some minor changes, leaving some breadcrumbs for the next reader of the test methods.
tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
Outdated
Show resolved
Hide resolved
tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
Outdated
Show resolved
Hide resolved
tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
Outdated
Show resolved
Hide resolved
tests/System.IO.Abstractions.TestingHelpers.Tests/MockFileInfoTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Peter Baumann <[email protected]>
Thinking aloud, now that I have a little more time for this PR: With this change, we would actually regress in regards to the Can't we fix this regression by simply calling We don't have any tests for the "initalize FileInfo when going through these methods", that is why this change in behavior is not caught by the tests, but propably need them. Willing to go the extra mile? |
If we're speaking .NET 5's
Sooo … the changed behaviour caused by this PR would be a regression to the current
Therefore, we possibly don't need this? |
You need to follow the reading of this method, a few lines below, the To my understanding, this does initialize the cache, following the calls into FileSystemInfo.Init |
This moves the initialization of
cachedMockFileData
to the first time that it is actually used. Apparently, this is more closely to how it works in .NET 6.Closes #899