Welcome to MSDN Blogs Sign in | Join | Help
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;

Posted: Wednesday, September 26, 2007 1:24 PM by casper
Filed under:

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker