Here is a little bit of knowledge that lots of people are not aware of. There is an Attribute that is InternalsVisibleToAttribute that allows access to a specific external project (the unit test project).
This attribute, once inserted inside AssemblyInfo.cs, will grant “public” visibility to all internal members of the project to the project specified within the attribute.
Here is how it is shown on MSDN:
1 | [assembly:InternalsVisibleTo("MyAssembly, PublicKey=32ab4ba45e0a69a1")] |
It is however wrong and will never work. The main reason is that what is there let us believe that it’s the PublicKeyToken but it is in fact the PublicKey as clearly typed there.
So… how do we get this PublicKey? By executing the following command: sn -Tp MyAssembly.dll
The result is going to be something like the following:
1 | Public key is |
Here is the end result to make it properly visible:
1 | [assembly: InternalsVisibleTo("AssemblyB, PublicKey=" |
After this step is done, all reference to internal members are considered “public” for this specific project. This simple trick allows you to complete your tests and don’t gives any excuse not to test.