-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
On-demand SetupAllProperties #826
Conversation
Hi @vanashimko, I likely won't have time to review your PR until sometime in June due to being very busy this month, but I'll eventually get to it. I'd like to ask you to be patient, though. It would've been good to discuss this in an issue first, since there are some finer (and AFAIK undocumented) points you might not yet be aware of which, if we're unlucky, make the whole idea of a lazy That being said, judging from your description, you definitely seem to be on the correct track here. Ideally, I'll try to review in detail soon. |
Thanks for you response, @stakx! Even if you'll find that due to some "finer points" lazy |
To give some more context for the ominous "finer points" (should you choose to look into it): You might have noticed code that gathers all properties in topological ("depth-first") order. I only took a quick look at your first commit and saw that you removed this logic (and I'm glad you did, as it's part of why I suspect that things still work (i.e. all tests pass) despite the removal of the topological search due to the recently introduced (In fact, this problem is not specific to just properties: What Moq is still lacking is a clearly defined algorithm that maps between invoked methods and declared methods (setups). That algorithm needs to work in a variety of cases: interface methods implemented by a class, methods of reimplemented interfaces ( |
Thanks, I'll try to get a closer look and add more tests. My thoughts were that if we already have calling method (which represents accessing property) in If there are some nifty moments with the method we have in |
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.
@vanashimko, thanks for waiting, and for this PR. This looks like really solid work 💪 and I am definitely in favour of merging it! Below you'll find a few review comments on things that we might be able to refine or simplify a little further.
Once again, thanks for the great work! 👍
@stakx, thanks for the so detailed review! I'll be looking into the comments. |
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.
Awesome work! ❤️ I think this is ready for merging.
If you want to clean up / polish your commits any more (but that's totally optional, feel free to leave it as is), now would be a good time. I'll wait a little longer before merging.
Also, in case that you want your contribution to be more publicly acknowledged, you could add a new changelog entry, e.g.:
The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
+## Unreleased
+
+#### Changed
+
+* Improved performance for `Mock.Of<T>` and `SetupAllProperties` as the latter now performs property setups just-in-time, instead of as an ahead-of-time batch operation. (@vanashimko, #826)
+
+
## 4.11.0 (2019-05-28)
Thanks @stakx! I've added changelog entry as you suggested. I'm OK with squashing all my commits into one automatically by GitHub during merge. |
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.
Just one more baby change request for the changelog.
…Provider as a switch
…aultValue_behaviour_for_inner_mocks
ed3eee9
to
4d2e1dd
Compare
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.
🚀
It is implementation of lazy
SetupAllProperties
, as described in #740 by @stakx.New switch
AutoSetupProperties
is added, currentSetupAllProperties
implementation is slightly hacked to behave the same as it was before. Eager setup is moved to interceptor to setup properties being accessed on-demand.New code passed all existing tests and I've added some more based on comments in the existing code about corner cases.
As the word "switch" was mentioned in the discussion, I decided to go via existing
Switches
enum. What bothers me is that now there are two ways of doing almost the same:SetupAllProperties
call as before and enablingAutoSetupProperties
switch directly.SetupAllProperties
is hacked to behave like eager version before (by savingDefaultValueProvider
) and switch doesn't have this (I just decided so, but we can actually saveDefaultValueProvider
in the setter ofSwitches
...). It looks logically to me, that switch does not saveDefaultValueProvider
, since switch is more declarative, whileSetupAllProperties
is imperative (even though it is implemented in a new way).What do you think?