I’m coming from Java and I’m fairly new to C#, so please bear with me in case I don’t use the correct terms or I’m thinking to “java-ish”.
Situation
I’m working on a package (all classes in the same namespace) that provides facades to consume data from a few remote services. For each facade there is an interface (like IEventServiceGateway) and an implementation (like EventServiceGateway), all declared public. Each of these implementations consumes data from at least one service, all a bit verbose, so I wrote a client class (like UserServiceClient) for each that provides common operations to all implementations. Because nobody outside of the package should use them, I declared them internal. Furthermore, I did the same with the WCF proxies.
I have two assemblies, one for the facades and the clients and one for the unit tests, the namespace of both is the same.
Problems
- I cannot unit test the internal classes, because they are not accessible in the assembly containing the unit tests. I know there are “hacks” to circumvent these restrictions, but using such hacks usually means that I’m using things not as supposed. Not testing the clients does not seem like a sensible solution, because the code paths would be much to complex when just testing the facades. Furthermore, I would test the same things like edge cases over and over again.
- I cannot inject the internal classes into the facades using constructor injection, because visibility of the argument is “lower” than the visibility of the constructor. But hard coding of the WCF proxies reduces the testability.
So I have the feeling that either my design is borked because I totally misunderstood the thing with the facades (that only the facades and their implementations should be accessible, nothing else), that my project setup is flawed or that something else is wrong.
I would greatly appreciate if somebody could enlighten me.
You could use the InternalsVisibleToAttribute attribute:
When you add that to your assembly that’s internal, you can specify other assemblies that can have access that normally wouldn’t be able to.