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
IsAuthenticated
Gets a value indicating whether user is authenticated.
public bool IsAuthenticated { get; }
Property Value
Policies
Gets the set of authentication policies for the current user.
public IEnumerable<string> Policies { get; }
Property Value
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
Roles
Gets the set of roles for the current user.
public IEnumerable<string> Roles { get; }
Property Value
State
Gets the authorization state for the user.
public AuthorizationState State { get; }
Property Value
UserName
Gets the authorization context user name.
public string UserName { get; }
Property Value
Methods
RegisterAuthorizationServices(IServiceCollection)
Registers authorization services with the specified service provider.
public void RegisterAuthorizationServices(IServiceCollection services)
Parameters
services
IServiceCollectionService provider to use.
SetAuthenticationType(string)
Sets the Identity.AuthenticationType for the current user/principa;.
public TestAuthorizationContext SetAuthenticationType(string authenticationType)
Parameters
authenticationType
stringThe authentication type to set.
Returns
SetAuthorized(string, AuthorizationState)
Authenticates the user with specified name and authorization state.
public TestAuthorizationContext SetAuthorized(string userName, AuthorizationState state = AuthorizationState.Authorized)
Parameters
userName
stringUser name for the principal identity.
state
AuthorizationStateAuthorization state.
Returns
SetAuthorizing()
Puts the authorization services into the authorizing state.
public TestAuthorizationContext SetAuthorizing()
Returns
SetClaims(params Claim[])
Sets the claims on the current user/principal.
public TestAuthorizationContext SetClaims(params Claim[] claims)
Parameters
claims
Claim[]Claims to set.
Returns
SetNotAuthorized()
Puts the authorization services into an unauthenticated and unauthorized state.
public TestAuthorizationContext SetNotAuthorized()
Returns
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
SetRoles(params string[])
Sets the user roles in this context..
public TestAuthorizationContext SetRoles(params string[] roles)
Parameters
roles
string[]Roles for the claims principal.