Skip to main content
Table of Contents

Class InMemoryTenantMembershipStore

Namespace
Stratara.Testing
Assembly
Stratara.Testing.dll

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

userId Guid

The user whose selection to load.

cancellationToken CancellationToken

Token to observe while loading.

Returns

Task<Guid?>

The selected tenant, or null when no explicit selection exists.

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

tenantId Guid

The tenant whose members to load.

cancellationToken CancellationToken

Token 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

userId Guid

The user whose membership to load.

tenantId Guid

The tenant to look the membership up in.

cancellationToken CancellationToken

Token to observe while loading.

Returns

Task<TenantMembership>

The membership, or null when 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

userId Guid

The user whose memberships to load.

cancellationToken CancellationToken

Token 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

tenantId Guid

The tenant whose memberships to remove.

cancellationToken CancellationToken

Token to observe while removing.

Returns

Task

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

userId Guid

The user whose memberships to remove.

cancellationToken CancellationToken

Token to observe while removing.

Returns

Task

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

userId Guid

The user whose membership to remove.

tenantId Guid

The tenant to remove the membership from.

cancellationToken CancellationToken

Token to observe while removing.

Returns

Task

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

userId Guid

The user switching tenants.

tenantId Guid

The tenant to make active.

cancellationToken CancellationToken

Token to observe while persisting.

Returns

Task

Exceptions

InvalidOperationException

The user holds no active membership in tenantId.

SetMembershipAsync(TenantMembership, CancellationToken)

Creates or replaces the membership identified by the record's UserId and TenantId (upsert).

public Task SetMembershipAsync(TenantMembership membership, CancellationToken cancellationToken = default)

Parameters

membership TenantMembership

The membership to persist; its role set and status replace any existing values.

cancellationToken CancellationToken

Token to observe while persisting.

Returns

Task