-
-
Notifications
You must be signed in to change notification settings - Fork 801
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
Issue with selecting a constructor with null value #969
Comments
Note that this exception is expected. The missed opportunity is if you call: var fooMock = new Mock<Foo>(() => new Foo("Hello, World", (A)null, new Bar())); you still get the same exception, even though the constructor to call is known unambiguously. (A workaround was already posted as an answer on SO) |
I agree with @canton7, while there is no way to get this to work if you pass the ctor parameters via a |
@stakx Thanks for the follow-up. It would be an awesome feature. |
Had a somewhat closer look, this isn't strictly a bug but a current limitation caused by DynamicProxy's API; see castleproject/Core#480. |
@amir734jj I don't understand the real world situation why do you ever need this feature? I.e. using Mock(constructorArgs). In most use cases I am familiar with all is around Moq Setup. In this situation you can use It.Is(a => a == null) or It.IsIn(null). |
@r-pankevicius, this is about a mocked type's constructor, not its regular methods. You cannot set up a constructor; it will get called when instantiating a In other words, you can only create setups when you have first created a |
@stakx OK, I understood. I probably work in a very religious shop that separates interfaces from implementations. So I only have an experience mocking interfaces, not classes. Therefore I did not run into such issue. |
Development over at the Castle DynamicProxy repo is a little slow-going these days, and I'm doubting that this issue with DynamicProxy will be fixed anytime soon. In the meantime, there's nothing we can do here, so I am going to close this issue for now... but I'll mark it as "unresolved" so that if and when DynamicProxy offers a way to select a specific constructor to use, we can easily find and reactive this present issue. |
I have the following setup and using Moq version 4.13.1. I am not sure this is a bug or not but I am wondering how can I get around this problem and pass null to the constructor argument.
I am getting the following error:
Stacktrace:
Original StackOverFlow question
The text was updated successfully, but these errors were encountered: