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

Mock.Object throwing "Castle.DynamicProxy.InvalidProxyConstructorArgumentsException" #589

Closed
nathvi opened this issue Feb 21, 2018 · 2 comments

Comments

@nathvi
Copy link

nathvi commented Feb 21, 2018

Context:
OS: Windows 10 Version 10.0.16299 Build 16299
.Net Project Version: 4.6.1
Visual Studio Version: Microsoft Visual Studio Professional 2017 Version 15.5.5
Visual Studio Project Type: MSTest/ClassLibrary
Installed Moq Nuget Version: 4.8.1

Expected Behavior:
Create a mock of a custom class named RedisConfiguration without having the object property on the mock property throw an exception.

Steps For Reproducing Behavior
Create a new MSTest project with the custom class RedisConfiguration defined as in the RedisConfiguration.txt

The test project should look like
KeyLoggingConsumerService.txt

Set a breakpoint on the line right after the statement:
RedisConfigurationMock = new Mock<RedisConfiguration>();

Debug the test. Navigate to the the Object property on the RedisConfigurationMock instance.

Observe the error that is thrown. It should be Castle.DynamicProxy.InvalidProxyConstructorArgumentsException

@stakx
Copy link
Contributor

stakx commented Feb 21, 2018

RedisConfiguration's constructors are parameterized, so you need to pass the ctor arguments via new Mock<RedisConfiguration>(argsForRedisConfigurationCtor). You couldn't do new RedisConfiguration() either, right? ;-)

@stakx stakx closed this as completed Feb 21, 2018
@nathvi
Copy link
Author

nathvi commented Feb 21, 2018

You were correct that I needed to pass in the arguments for the RedisConfiguration into the Mock object. Thank you.

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

No branches or pull requests

2 participants