Faking out [PrincipalPermission]

Depending on how your unit tests are setup, you may not be running as the proper user and won't have the necessary permissions to invoke a method. If this happens, you can easily alter the principle thread's identity with the following code.

For instance, if you user needs to belong to a certain role (or group) called 'DesiredGroup', this would emulate that fact.

 GenericIdentity identity = new GenericIdentity("boo");      
GenericPrincipal principal =       
           new GenericPrincipal(identity, new string[] {"DesiredGroup"});       
      
Thread.CurrentPrincipal = principal;