I've looked at the very good content at this thread and it hasn't solved my problem. MSTEST PrincipalPermission
My class:
public class SecurityUsingAttributes
{
[PrincipalPermission(SecurityAction.Demand, Role = "SomeRole")]
public int MyMethod1()
{
return 5;
}
}
My test:
[TestClass]
public class SecurityUsingAttributesTests
{
[TestMethod]
public void TestMethod1()
{
IIdentity identity = new GenericIdentity(@"MyDomain\MyName");
string[] roles = new string[] { "SomeRole"};
IPrincipal genericPrincipal = new GenericPrincipal(identity, roles);
Thread.CurrentPrincipal = genericPrincipal;
SecurityUsingAttributes target = new SecurityUsingAttributes();
Assert.IsTrue(5 == target.MyMethod1());
}
}
This works now.