Class TestAuthorizationContext
Backward-compatible wrapper around Bunit.TestDoubles.BunitAuthorizationContext.
Inherited Members
Namespace: Bunit.TestDoubles
Assembly: FastMoq.Web.dll
Syntax
public sealed class TestAuthorizationContext
Remarks
This wrapper preserves the older FastMoq-facing helper name while the underlying bUnit authorization implementation comes from the current bUnit 2 package line.
Constructors
TestAuthorizationContext(BunitAuthorizationContext)
Initializes a new instance of the TestAuthorizationContext class.
Declaration
public TestAuthorizationContext(BunitAuthorizationContext inner)
Parameters
| Type | Name | Description |
|---|---|---|
| BunitAuthorizationContext | inner | The underlying bUnit authorization context. |
Properties
Claims
Gets the active claims.
Declaration
public IEnumerable<Claim> Claims { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<Claim> |
InnerContext
Gets the underlying bUnit authorization context.
Declaration
public BunitAuthorizationContext InnerContext { get; }
Property Value
| Type | Description |
|---|---|
| BunitAuthorizationContext |
IsAuthenticated
Gets a value indicating whether the current user is authenticated.
Declaration
public bool IsAuthenticated { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Policies
Gets the active policies.
Declaration
public IEnumerable<string> Policies { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<string> |
PolicySchemeName
Gets the configured policy scheme name.
Declaration
public string PolicySchemeName { get; }
Property Value
| Type | Description |
|---|---|
| string |
Roles
Gets the active roles.
Declaration
public IEnumerable<string> Roles { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<string> |
State
Gets the current authorization state.
Declaration
public AuthorizationState State { get; }
Property Value
| Type | Description |
|---|---|
| AuthorizationState |
UserName
Gets the current user name.
Declaration
public string UserName { get; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
SetAuthenticationType(string)
Sets the authentication type for the current identity.
Declaration
public void SetAuthenticationType(string authenticationType)
Parameters
| Type | Name | Description |
|---|---|---|
| string | authenticationType | The authentication type. |
SetAuthorized(string)
Sets an authenticated user with the default authorized state.
Declaration
public void SetAuthorized(string userName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userName | The user name. |
Examples
AuthContext.SetAuthorized("migration.user");
SetAuthorized(string, AuthorizationState)
Sets an authenticated user with the specified authorization state.
Declaration
public void SetAuthorized(string userName, AuthorizationState state)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userName | The user name. |
| AuthorizationState | state | The authorization state. |
SetAuthorizing()
Puts the authorization services into the authorizing state.
Declaration
public void SetAuthorizing()
SetClaims(params Claim[])
Sets the active claims.
Declaration
public void SetClaims(params Claim[] claims)
Parameters
| Type | Name | Description |
|---|---|---|
| Claim[] | claims | The claims to apply. |
SetNotAuthorized()
Puts the authorization services into the unauthenticated state.
Declaration
public void SetNotAuthorized()
SetPolicies(params string[])
Sets the active policies.
Declaration
public void SetPolicies(params string[] policies)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | policies | The policies to apply. |
SetRoles(params string[])
Sets the active roles.
Declaration
public void SetRoles(params string[] roles)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | roles | The roles to apply. |