The other day I was trying to write some unit tests on a public class with an internal constructor. In order for the test project to get access to the internal constructor (primarily used for testing) I had to add the assembly: InternalsVisibleTo to the AssemblyInfo.cs file and specify the class library I was testing would expose its internals to the test class library, for example:
This got me close, next issue was the parameter of the internal constructor was an internal interface referencing a dependency of the class under test. No big deal. I figured I would use Moq to mock out the dependency and I got the following error when trying to run the test:
Test method SomeNamespace.SomeClass.SomeTestMethod threw exception:
Castle.DynamicProxy.Generators.GeneratorException: Type SomeNamespace.SomeInterface is not public. Can not create proxy for types that are not accessible.
Hmm, it seems like Moq does not have access to the internals. Adding the following to the class libraries AssemblyInfo.cs file solved the problem
Next time I ran the test Moq was able to access the internal interface and my test passed.
Thanks, this saved me a bit of time. Dealing with accessors and dependency injection is just too much trouble. To expand on what you've done here, though, if you're signing your assembly you will have to specify the public key for your DynamicProxyGenAssembly2. It looks a little like this:ReplyDelete
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000" +
Good catch, that is good to know, thanks for the comment.Delete
Very little playing is permitted in Vermont to start with, however there is a proposed invoice to legalize cell sports activities wagering in-state. Missouri had quantity of} sports activities betting 토토사이트 bills launched current years|in recent times|lately} however the state hasn't taken motion on them but. Decide earlier than you start betting how much money and time you might be} keen to spend on playing.ReplyDelete