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
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? ;-)
You were correct that I needed to pass in the arguments for the RedisConfiguration into the Mock object. Thank you.
Most helpful comment
RedisConfiguration's constructors are parameterized, so you need to pass the ctor arguments vianew Mock<RedisConfiguration>(argsForRedisConfigurationCtor). You couldn't donew RedisConfiguration()either, right? ;-)