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

Fix setting of nested non-overridable properties via Mock.Of #1061

Merged
merged 5 commits into from
Sep 30, 2020

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Sep 27, 2020

Fixes #1039.

@stakx stakx added this to the 4.14.6 milestone Sep 27, 2020
}
try
{
propertyToSet.SetValue(targetMock.Object, value, null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could go one step further here and add support for indexers by passing through the index arguments instead of hard-coding null as the last argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this unresolved for now. Supporting indexers for non-overridable properties would only work partly anyway, e.g. you could only use fixed values (no matchers) for the index arguments. Not sure if it's worth doing the work to support this scenario as far as is possible.

@stakx
Copy link
Contributor Author

stakx commented Sep 29, 2020

Note to self: It may be worth reconsidering whether InvocationShape should do any validation at all with regards to method overridability.

The logic inside this type should work just as well for non-overridable methods, it's external parties that add the "method must be overridable (and visible to the proxy factory)" requirement.

It might therefore be better to extract validation from InvocationShape, and move it somewhere else. (I was going to say [Castle]ProxyFactory, but that wouldn't be totally right, since it isn't just the proxy factories that require methods to be overridable, but lots of other parts of Moq, too.)

Each party that currently builds up InvocationShapes would then have to explicitly validate them as needed. This way, the allowNonOverridable… parameters being added in this PR could be dropped again.

@stakx stakx force-pushed the linq-nested-non-overridable-properties branch from 334cb6d to bbaed39 Compare September 30, 2020 21:06
@stakx stakx force-pushed the linq-nested-non-overridable-properties branch from bbaed39 to 5a424b0 Compare September 30, 2020 21:18
@stakx stakx merged commit 5aabec7 into devlooped:master Sep 30, 2020
@stakx stakx deleted the linq-nested-non-overridable-properties branch September 30, 2020 21:32
@devlooped devlooped locked and limited conversation to collaborators Sep 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mock.Of<T>((m) => ...) doesn't play well with Microsoft IOptions<T>
1 participant