Unit Testing Private Static Methods in C#

I had never needed to unit test a private static class method in C# before, but it turns out that Microsoft created a special object type to handle just such a case.

To test the private static method DetermineFilename (that takes filePath as a string parameter and returns a string) in the FileManager class, do the following:

[sourcecode language="csharp"]
PrivateType privateFileManagerObject = new PrivateType(typeof(FileManager));
string filename = (string)privateFileManagerObject.InvokeStatic("DetermineFilename", filePath);

Thanks to Venkat for posting this solution on his web site here: