2013-10-03 75 views
0

我已经看了这些线很好的内容,并没有解决我的问题。 MSTEST PrincipalPermissionMSTest的请求主体权限失败

我的类:

public class SecurityUsingAttributes 
{ 
    [PrincipalPermission(SecurityAction.Demand, Role = "SomeRole")] 
    public int MyMethod1() 
    { 
     return 5; 
    } 
} 

我的测试:

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

这就是现在的工作。

回答

0

我失踪了CurrentPrincipal分配。上面的代码现在可以工作。

相关问题