One of the annoying things about unit testing, is that not all members of the target code class are accessibly to the test fixtures.
There are limited options to work around this (as you really don’t want to put the unit tests within the code assembly).
In the past, the usual method has been to open up the access levels of the code class members. This isn’t ideal from a best practices and security point of view.
However, as of .Net 2.0 a better method has been introduced. This is to use the InternalsVisibleTo attribute on the code assembly. This makes any code members with an accessibility level of internal or above (internal, protected internal and public) available to the specified assemblies.
To use this attribute add the following line to the AssemblyInfo.cs file of the code assembly:
[assembly: InternalsVisibleTo("MyAssembly.UnitTests")]
where MyAssembly.UnitTests is the unit test assembly name.
Tim