我在我的 Controller 中使用这个资源授权:
var result = await _authorizationService.AuthorizeAsync(User, document, operation);
我需要测试我的 Controller ,我需要授权才能通过测试。
我试过:
_substituteAuthorizationService.AuthorizeAsync(Arg.Any<ClaimsPrincipal>(), null, Arg.Any<IEnumerable<IAuthorizationRequirement>>())
.ReturnsForAnyArgs(new AuthorizationResult(......));
但我无法新建 AuthorizationResult,因为它没有公共(public)构造函数。
有什么想法吗?谢谢!
最佳答案
但是你可以从静态方法返回
AuthorizationResult.Success()
AuthorizationResult.Failed()
关于c# - 如何在 .net core 2.0 中模拟 IAuthorizationService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46922341/