10

I'm using this resource authorization in my controller:

var result = await _authorizationService.AuthorizeAsync(User, document, operation);

I need to test my controller, and I need the authorization to pass in the test.

I tried:

_substituteAuthorizationService.AuthorizeAsync(Arg.Any<ClaimsPrincipal>(), null, Arg.Any<IEnumerable<IAuthorizationRequirement>>())
            .ReturnsForAnyArgs(new AuthorizationResult(......));

but I can't new an AuthorizationResult because it doesn't have a public constructor.

Any ideas? Thanks!

2

1 Answer 1

11

Not much detail here https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authorization.authorizationresult?view=aspnetcore-2.0

But you can return from the static method(s)

AuthorizationResult.Success()
AuthorizationResult.Failed()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.