Skip to content
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

Make DefaultValue.Mock inherit property stubbing #1074

Merged
merged 3 commits into from Oct 13, 2020

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Oct 13, 2020

This should fix #1071.

Note: While this introduces a small breaking change (at least in theory), it is one that fulfills a promise made by the pre-existing XML documentation for SetupAllProperties:

https://github.com/moq/moq4/blob/947c6a0aa1bbf265b5555ad0a84beb5bfc53b4e2/src/Moq/Mock.Generic.cs#L671-L674

Since that commit, inner mocks created by `Mock.Of<>()` no longer have
their properties stubbed. `SetupAllProperties` is now only called for
the root (outermost) mock. That's why nested properties can no longer
be overridden simply by assigning to them.
The XML doc comment for `Mock<T>.SetupAllProperties()` states that:

> If the mock's `DefaultValue` is set to `DefaultValue.Mock`, the
> mocked default values will also get all properties setup recursively.

But this does not actually happen! This commit changes the behavior of
`DefaultValue.Mock` such that it does what it says on the tin.

In theory, this could be a breaking change; let's see how many users
have relied on behavior that contradicts the documentation.

References:
https://github.com/moq/moq4/blob/947c6a0aa1bbf265b5555ad0a84beb5bfc53b4e2/src/Moq/Mock.Generic.cs#L671-L674
@stakx stakx force-pushed the inner-mocks-inherit-setupallproperties branch from df0797b to ce2eb98 Compare October 13, 2020 19:30
@stakx stakx force-pushed the inner-mocks-inherit-setupallproperties branch from ce2eb98 to 6abbc9a Compare October 13, 2020 19:32
@stakx stakx merged commit 40b78a8 into devlooped:master Oct 13, 2020
@stakx stakx deleted the inner-mocks-inherit-setupallproperties branch October 13, 2020 19:42
@stakx stakx modified the milestones: 4.15.0, 4.14.7 Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setters on deep mocks no longer work after updating to 4.14.6 from old version
1 participant