MsTest and Principal Permission Attribute

G

Guest

I am having problems unit testing a method whic is decorated with the
[PrincipalPermission] attribute.
I always get a security exception. I have set the Thread.CurrentPrincipal
to my custom IPrincipal .IsInRole method never gets called

I have even tried
AppDomain.CurrentDomain.SetThreadPrincipal(myIPrincipal)...with no luck.

Here is a basic example

[PrincipalPermission(SecurityAction.Demand, Role="MyRole")]
public void DoWork()
{
}
[TestMethod]
public void TestDoWork()
{
GenericPrincipal principal = new GenericPrincipal(
Thread.CurrentPrincipal.Identity, new string[] { "MyRole" });
Thread.CurrentPrincipal = principal;
DoWork();
Assert(....)
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top