且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Asp.Net MVC中模拟My.User.IsInRole()错误

更新时间:2023-02-13 17:02:20

您需要将模拟原理分配给当前线程原理,(下面是c#代码,希望您能解释它)

You need to assign principle mock to current thread principle, (Below is c# code I hope you can interpret it)

    // Make fack principle instance
    var fackPrinciple = new Mock<IPrinciple>();

    // Setup fack data
    fackPrinciple.Setup(e => e.IsInRole(It.IsAny<String>)).Returns(true);

    // Assign to current thread principle
    Thread.CurrentPrincipal = fackPrinciple.Object;   

请让我知道是否有问题?

Please let me know if have any issue?