How do you unit test code decorated with the PrincipalPermission attribute?
For example, this works:
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
var c = new MyClass();
}
}
[PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Users")]
class MyClass
{
public MyClass()
{
Console.WriteLine("This works.");
}
}
This throws a SecurityException:
[TestClass]
public class UnitTest1
{
[TestInitialize]
public void TestInitialize()
{
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
}
[TestMethod]
public void TestMethod1()
{
var c = new MyClass();
}
}
Any ideas?