G
Guest
I am reposting this for a colleague because he has had some problems setting
up his subscriber Nospam alias:
I am having problems unit testing a method which 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(....)
}
Environment: (all current with MicrosoftUpdate SPs and patches)
* VS2005 Team Suite
* .NET 2.0 and 3.0 redist and SDK
* Team Foundation Server
up his subscriber Nospam alias:
I am having problems unit testing a method which 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(....)
}
Environment: (all current with MicrosoftUpdate SPs and patches)
* VS2005 Team Suite
* .NET 2.0 and 3.0 redist and SDK
* Team Foundation Server