Class InMemoryTenantMembershipStore
Thread-safe in-memory ITenantMembershipStore for tests — the drop-in double for the EF-backed membership store, mirroring its contract semantics: upsert on SetMembershipAsync(TenantMembership, CancellationToken), erasure sweeps per user and per tenant, and the membership-guarded active-tenant selection (selecting a tenant without an active membership throws, removals clear a now-dangling selection).
public sealed class InMemoryTenantMembershipStore : ITenantMembershipStore
- Inheritance
-
InMemoryTenantMembershipStore
- Implements
- Inherited Members
- Extension Methods
Methods
GetActiveTenantAsync(Guid, CancellationToken)
Gets the tenant the user has explicitly selected as the active one for sign-in, or
null when the user never made a selection (callers fall back to the user's only —
or first — active membership).
public Task<Guid?> GetActiveTenantAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user whose selection to load.
cancellationTokenCancellationTokenToken to observe while loading.
Returns
GetMembersAsync(Guid, CancellationToken)
Gets every membership of the tenant — the reverse lookup ("who belongs to this tenant").
public Task<IReadOnlyList<TenantMembership>> GetMembersAsync(Guid tenantId, CancellationToken cancellationToken = default)
Parameters
tenantIdGuidThe tenant whose members to load.
cancellationTokenCancellationTokenToken to observe while loading.
Returns
- Task<IReadOnlyList<TenantMembership>>
The tenant's memberships; empty when the tenant has no members.
GetMembershipAsync(Guid, Guid, CancellationToken)
Gets the user's membership in one specific tenant.
public Task<TenantMembership?> GetMembershipAsync(Guid userId, Guid tenantId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user whose membership to load.
tenantIdGuidThe tenant to look the membership up in.
cancellationTokenCancellationTokenToken to observe while loading.
Returns
- Task<TenantMembership>
The membership, or
nullwhen the user does not belong to the tenant.
GetMembershipsAsync(Guid, CancellationToken)
Gets every membership the user holds, regardless of status.
public Task<IReadOnlyList<TenantMembership>> GetMembershipsAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user whose memberships to load.
cancellationTokenCancellationTokenToken to observe while loading.
Returns
- Task<IReadOnlyList<TenantMembership>>
The user's memberships; empty when the user belongs to no tenant.
RemoveAllMembersAsync(Guid, CancellationToken)
Removes every membership of the tenant — the membership-plane step of a tenant-erasure sweep. No-op when the tenant has no members.
public Task RemoveAllMembersAsync(Guid tenantId, CancellationToken cancellationToken = default)
Parameters
tenantIdGuidThe tenant whose memberships to remove.
cancellationTokenCancellationTokenToken to observe while removing.
Returns
RemoveAllMembershipsAsync(Guid, CancellationToken)
Removes every membership the user holds — the membership-plane step of a user-erasure (GDPR) sweep. No-op when the user holds none.
public Task RemoveAllMembershipsAsync(Guid userId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user whose memberships to remove.
cancellationTokenCancellationTokenToken to observe while removing.
Returns
RemoveMembershipAsync(Guid, Guid, CancellationToken)
Removes the user's membership in one tenant. No-op when no such membership exists.
public Task RemoveMembershipAsync(Guid userId, Guid tenantId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user whose membership to remove.
tenantIdGuidThe tenant to remove the membership from.
cancellationTokenCancellationTokenToken to observe while removing.
Returns
SetActiveTenantAsync(Guid, Guid, CancellationToken)
Persists the user's active-tenant selection — the tenant-switch operation for users with more than one membership. Implementations enforce the membership guard: the selection is rejected when the user holds no Active membership in the target tenant.
public Task SetActiveTenantAsync(Guid userId, Guid tenantId, CancellationToken cancellationToken = default)
Parameters
userIdGuidThe user switching tenants.
tenantIdGuidThe tenant to make active.
cancellationTokenCancellationTokenToken to observe while persisting.
Returns
Exceptions
- InvalidOperationException
The user holds no active membership in
tenantId.
SetMembershipAsync(TenantMembership, CancellationToken)
public Task SetMembershipAsync(TenantMembership membership, CancellationToken cancellationToken = default)
Parameters
membershipTenantMembershipThe membership to persist; its role set and status replace any existing values.
cancellationTokenCancellationTokenToken to observe while persisting.