Table of Contents

Class FakeAuthorizationService

Namespace
Bunit.TestDoubles
Assembly
Bunit.Web.dll

Test class that provides an implementation of IAuthorizationService that assists user in testing components by allowing them to set the authorization expected authorization response.

public class FakeAuthorizationService : IAuthorizationService
Inheritance
FakeAuthorizationService
Implements
Inherited Members
Extension Methods

Constructors

FakeAuthorizationService(AuthorizationState)

Initializes a new instance of the FakeAuthorizationService class.

public FakeAuthorizationService(AuthorizationState state = AuthorizationState.Authorized)

Parameters

state AuthorizationState

Initial authorization state.

Methods

AuthorizeAsync(ClaimsPrincipal, object?, IEnumerable<IAuthorizationRequirement>)

Authorizes the Principal user based solely on the current authorization state.

public Task<AuthorizationResult> AuthorizeAsync(ClaimsPrincipal user, object? resource, IEnumerable<IAuthorizationRequirement> requirements)

Parameters

user ClaimsPrincipal

Principal user to authorize.

resource object

Resource being authorized.

requirements IEnumerable<IAuthorizationRequirement>

Authorization requirements.

Returns

Task<AuthorizationResult>

Result of authorize request.

AuthorizeAsync(ClaimsPrincipal, object?, string)

Authorizes the Principal user based solely on the current authorization state.

public Task<AuthorizationResult> AuthorizeAsync(ClaimsPrincipal user, object? resource, string policyName)

Parameters

user ClaimsPrincipal

Principal user to authorize.

resource object

Resource being authorized.

policyName string

Policy to use for authorization.

Returns

Task<AuthorizationResult>

Result of authorize request.

SetAuthorizationState(AuthorizationState)

Method to explicitly set the authorization state.

public void SetAuthorizationState(AuthorizationState state)

Parameters

state AuthorizationState

New state to set.

SetPolicies(IEnumerable<string>)

Sets the supported policies in the Authorization service for current user.

public void SetPolicies(IEnumerable<string> policies)

Parameters

policies IEnumerable<string>

List of supported policies.

SetRoles(IEnumerable<string>)

Sets the supported roles in the Authorization service for current user.

public void SetRoles(IEnumerable<string> roles)

Parameters

roles IEnumerable<string>

List of supported roles.

.NET Foundation

Supported by the .NET Foundation.