< Summary

Information
Class: Elsa.Common.Multitenancy.TenantResolverContext
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Multitenancy/Contexts/TenantResolverContext.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 7
Coverable lines: 7
Total lines: 47
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
get_CancellationToken()100%210%
FindTenant(...)0%620%
FindTenant(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Multitenancy/Contexts/TenantResolverContext.cs

#LineLine coverage
 1namespace Elsa.Common.Multitenancy;
 2
 3/// <summary>
 4/// Represents the context for resolving a tenant in a tenant resolution strategy pipeline.
 5/// </summary>
 6/// <remarks>
 7/// This class provides the necessary information for resolving a tenant, including a cancellation token
 8/// to allow for cancelling the resolution process.
 9/// </remarks>
 10public class TenantResolverContext
 11{
 12    private readonly IDictionary<string, Tenant> _tenantsDictionary;
 13
 14    /// <summary>
 15    /// Initializes a new instance of the <see cref="TenantResolverContext"/> class.
 16    /// </summary>
 017    public TenantResolverContext(IDictionary<string, Tenant> tenants, CancellationToken cancellationToken)
 18    {
 019        CancellationToken = cancellationToken;
 020        _tenantsDictionary = tenants;
 021    }
 22
 23    /// <summary>
 24    /// Gets the cancellation token.
 25    /// </summary>
 026    public CancellationToken CancellationToken { get; }
 27
 28    /// <summary>
 29    /// Finds a tenant based on the provided tenant ID.
 30    /// </summary>
 31    /// <param name="tenantId">The tenant ID.</param>
 32    /// <returns>The found tenant or null if no tenant with the provided ID exists.</returns>
 33    public Tenant? FindTenant(string tenantId)
 34    {
 035        return _tenantsDictionary.TryGetValue(tenantId, out var tenant) ? tenant : null;
 36    }
 37
 38    /// <summary>
 39    /// Finds a tenant based on the provided predicate.
 40    /// </summary>
 41    /// <param name="predicate">The predicate used to filter the tenants.</param>
 42    /// <returns>The found tenant or null if no tenant satisfies the predicate.</returns>
 43    public Tenant? FindTenant(Func<Tenant, bool> predicate)
 44    {
 045        return _tenantsDictionary.Values.FirstOrDefault(predicate);
 46    }
 47}