You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create mock for IServiceInterface with implementations for several methods.
Hovewer my DefaultImplementationClass not implemented all methods from IServiceInterface, so when I call methods that don't exists in DefaultImplementationClass program throws exception like:
System.NotImplementedException: This is a DynamicProxy2 error: The interceptor attempted to 'Proceed' for method 'MethodThatNotExistsInDefaultImplementationClass(Int64)' which has no target. When calling method without target there is no implementation to 'proceed' to and it is the responsibility of the interceptor to mimic the implementation (set return value, out arguments etc)
Example of my code:
varmock=newMock<DefaultImplementationClass>().As<IServiceInterface>();
mock.Callbase =true;
mock.Object.MethodThatExistsInDefaultImplementationClass();// all good, calling real implementation
mock.Object.MethodThatNotExistsInDefaultImplementationClass();// throws exception
So the question, can I somehow make it so that it simply returns the default value,
not to throw exception in this case?
thanks in advance
The text was updated successfully, but these errors were encountered:
@stakx
sorry, when I tried to reproduce this error, I created a new project with latest version of Moq, and everything worked out! I though that I have updated Moq to latest version in my real project, my mistake =(
Now everything is works, thank you very much!
Hello!
I'm trying to create mock for
IServiceInterface
with implementations for several methods.Hovewer my
DefaultImplementationClass
not implemented all methods fromIServiceInterface
, so when I call methods that don't exists inDefaultImplementationClass
program throws exception like:System.NotImplementedException: This is a DynamicProxy2 error: The interceptor attempted to 'Proceed' for method 'MethodThatNotExistsInDefaultImplementationClass(Int64)' which has no target. When calling method without target there is no implementation to 'proceed' to and it is the responsibility of the interceptor to mimic the implementation (set return value, out arguments etc)
Example of my code:
So the question, can I somehow make it so that it simply returns the default value,
not to throw exception in this case?
thanks in advance
The text was updated successfully, but these errors were encountered: