Table of Contents

Class TestAuthorizationContext

Namespace
Bunit.TestDoubles
Assembly
Bunit.Web.dll

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

public class TestAuthorizationContext
Inheritance
TestAuthorizationContext
Inherited Members
Extension Methods

Constructors

TestAuthorizationContext()

public TestAuthorizationContext()

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

RegisterAuthorizationServices(IServiceCollection)

Registers authorization services with the specified service provider.

public void RegisterAuthorizationServices(IServiceCollection services)

Parameters

services IServiceCollection

Service provider to use.

SetAuthenticationType(string)

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

public TestAuthorizationContext SetAuthenticationType(string authenticationType)

Parameters

authenticationType string

The authentication type to set.

Returns

TestAuthorizationContext

SetAuthorized(string, AuthorizationState)

Authenticates the user with specified name and authorization state.

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

Parameters

userName string

User name for the principal identity.

state AuthorizationState

Authorization state.

Returns

TestAuthorizationContext

SetAuthorizing()

Puts the authorization services into the authorizing state.

public TestAuthorizationContext SetAuthorizing()

Returns

TestAuthorizationContext

SetClaims(params Claim[])

Sets the claims on the current user/principal.

public TestAuthorizationContext SetClaims(params Claim[] claims)

Parameters

claims Claim[]

Claims to set.

Returns

TestAuthorizationContext

SetNotAuthorized()

Puts the authorization services into an unauthenticated and unauthorized state.

public TestAuthorizationContext SetNotAuthorized()

Returns

TestAuthorizationContext

SetPolicies(params string[])

Sets the authorization policies supported for the current user.

public TestAuthorizationContext SetPolicies(params string[] policies)

Parameters

policies string[]

Supported authorization policies.

Returns

TestAuthorizationContext

SetRoles(params string[])

Sets the user roles in this context..

public TestAuthorizationContext SetRoles(params string[] roles)

Parameters

roles string[]

Roles for the claims principal.

Returns

TestAuthorizationContext
Progress Telerik

Premium sponsor: Progress Telerik.

Packt

Editorial support provided by Packt.

.NET Foundation

Supported by the .NET Foundation.