-
-
Notifications
You must be signed in to change notification settings - Fork 794
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
SetupAllProperties
no longer overrides pre-existing property setups
#837
Comments
Ah, and still I broke something! Disappointed but not surprised 😄 How about removing all property accessors setups inside How do you think? |
Don't worry, that's no fault of yours. And no harm has been done. :)
Good idea! I hadn't thought of that, but this should work.
In principle, that would be OK, although I had hoped to keep it strictly add-or-clear-only (as that would in principle allow concurrency optimizations similar to those found in
That'd be one way to do it, but perhaps it wouldn't even be necessary. (We could go further and remove those setups known to be There's another, somewhat less elegant solution which I'm mentioning only for completeness' sake: Instead of removing existing property setups, we could keep them but somehow "reset" them to use different backing fields and default value providers. One could go through the list of all setups, and when encountering a setup of type |
Good news on
I'm afraid that looking for Earlier you could also do: var mock = new Mock<IBar>();
mock.Setup(x => x.Value).Returns(1);
mock.SetupAllProperties(); // reset all the setups added previously
Assert.Equal(0, mock.Object.Value); Even though we can filter against |
... and you're right! I don't think I can come up with an alternative solution that beats your proposal in terms of simplicity and correctness, so if you're interested to work on this, another PR would be welcome! |
After #826,
mock.SetupAllProperties()
no longer overrides pre-existing property setups, as it would have up until 4.11.0.Steps to reproduce:
Actual behavior (output):
Expected behavior (output):
Notes:
According to the reasoning I used in #196 (comment):
... this qualifies as a regression / bug, esp. for people who are using it to pave over existing setups.
It would be good to restore the previous behavior, for overall API consistency. However, that might be fairly non-trivial (one possible solution might require that all setups be timestamped).
That being said, fixing this regression is probably not super-important, since
SetupAllProperties
should typically happen as the first, or one of the first, setups performed on a fresh mock, and calling the method repeatedly is probably not a very common pattern./cc @vanashimko
The text was updated successfully, but these errors were encountered: