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(....)
}
[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(....)
}