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

Breaking Change Moq 4.11 - SetupAllProperties() (includes Mock.Of<T>) fails in cases it didn't before #845

Closed
Mexe13 opened this issue Jun 6, 2019 · 3 comments · Fixed by #847
Assignees
Labels
Milestone

Comments

@Mexe13
Copy link

Mexe13 commented Jun 6, 2019

Case:

public class Foo {
     public virtual object Bar { get; internal set; }
}

Mock.Of<Foo>();

previously worked. Now it throws:

Cannot set up Foo.set_Bar because it is not accessible to the proxy generator used by Moq:
Can not create proxy for method Void set_Bar(Foo) because it or its declaring type is not accessible. Make it public, or internal and mark your assembly with [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] attribute, because assembly Opc.Ua.Client is not strong-named.
at Moq.Guard.IsVisibleToProxyFactory(MethodInfo method)
at Moq.InvocationShape..ctor(LambdaExpression expression, MethodInfo method, IReadOnlyList1 arguments) at Moq.AutoImplementedPropertySetterSetup..ctor(LambdaExpression originalExpression, MethodInfo method, Action1 setter)
at Moq.Mock.SetupAllProperties(Mock mock, DefaultValueProvider defaultValueProvider)
at Moq.Mock.OfT

I assume that previously this was mocked as "readonly property" where get could be setuped.
Now Moq tries to mock the same property as a get + set property.

Is this an intended change "here to stay" or will this be reverted?


Also note that when the property is not virtual, SetupAllProperties() will succeed. The property is just not mocked.

public class Foo {
     public object Bar { get; internal set; }
}

Mock.Of<Foo>();

This creates a precedent for "just mock everything mockable". Seems for consistency reasons it might make sense to revert back to the old behavior and "ignore" internal setters?

Thanks!

@stakx
Copy link
Contributor

stakx commented Jun 6, 2019

revert back to the old behavior and "ignore" internal setters

Yes, I believe that's what should happen. (Or more precisely, ignore everything that is not visible to the proxy generator.)

Thanks for reporting this regression!

@BrunoJuchli
Copy link

BrunoJuchli commented Jun 19, 2019

Sorry for the previous comment, I was being stupid - didn't notice the fix hasn't been released yet and re-tested it against 4.11, again, and of course found it didn't work...

Thanks for fixing it!

@stakx
Copy link
Contributor

stakx commented Jun 20, 2019

@BrunoJuchli, no worries. I've just released Moq 4.12.0, it should become available on NuGet.org in a few minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants