Table of Contents

Class BunitAuthorizationContext

Namespace
Bunit.TestDoubles
Assembly
bunit.dll

Root authorization service that manages different authentication/authorization state in the system.

public class BunitAuthorizationContext
Inheritance
BunitAuthorizationContext
Inherited Members
Extension Methods

Properties

Claims

Gets the set of principal claims for the current user.

public IEnumerable<Claim> Claims { get; }

Property Value

IEnumerable<Claim>

IsAuthenticated

Gets a value indicating whether user is authenticated.

public bool IsAuthenticated { get; }

Property Value

bool

Policies

Gets the set of authentication policies for the current user.

public IEnumerable<string> Policies { get; }

Property Value

IEnumerable<string>

PolicySchemeName

Gets or sets the policy schemeName. Defaults to TestScheme and usually doesn't need to be changed by user.

public string PolicySchemeName { get; set; }

Property Value

string

Roles

Gets the set of roles for the current user.

public IEnumerable<string> Roles { get; }

Property Value

IEnumerable<string>

State

Gets the authorization state for the user.

public AuthorizationState State { get; }

Property Value

AuthorizationState

UserName

Gets the authorization context user name.

public string UserName { get; }

Property Value

string

Methods

SetAuthenticationType(string)

Sets the Identity.AuthenticationType for the current user/principa;.

public BunitAuthorizationContext SetAuthenticationType(string authenticationType)

Parameters

authenticationType string

The authentication type to set.

Returns

BunitAuthorizationContext

SetAuthorized(string, AuthorizationState)

Authenticates the user with specified name and authorization state.

public BunitAuthorizationContext SetAuthorized(string userName, AuthorizationState state = AuthorizationState.Authorized)

Parameters

userName string

User name for the principal identity.

state AuthorizationState

Authorization state.

Returns

BunitAuthorizationContext

SetAuthorizing()

Puts the authorization services into the authorizing state.

public BunitAuthorizationContext SetAuthorizing()

Returns

BunitAuthorizationContext

SetClaims(params Claim[])

Sets the claims on the current user/principal.

public BunitAuthorizationContext SetClaims(params Claim[] claims)

Parameters

claims Claim[]

Claims to set.

Returns

BunitAuthorizationContext

SetNotAuthorized()

Puts the authorization services into an unauthenticated and unauthorized state.

public BunitAuthorizationContext SetNotAuthorized()

Returns

BunitAuthorizationContext

SetPolicies(params string[])

Sets the authorization policies supported for the current user.

public BunitAuthorizationContext SetPolicies(params string[] policies)

Parameters

policies string[]

Supported authorization policies.

Returns

BunitAuthorizationContext

SetRoles(params string[])

Sets the user roles in this context..

public BunitAuthorizationContext SetRoles(params string[] roles)

Parameters

roles string[]

Roles for the claims principal.

Returns

BunitAuthorizationContext
.NET Foundation

Supported by the .NET Foundation.