< 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
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 48
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_CancellationToken()100%11100%
FindTenant(...)100%22100%
FindTenant(...)100%11100%

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>
 30317    public TenantResolverContext(IDictionary<string, Tenant> tenants, CancellationToken cancellationToken)
 18    {
 30319        CancellationToken = cancellationToken;
 30320        _tenantsDictionary = tenants;
 30321    }
 22
 23    /// <summary>
 24    /// Gets the cancellation token.
 25    /// </summary>
 126    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    {
 935        var normalizedId = tenantId.NormalizeTenantId();
 936        return _tenantsDictionary.TryGetValue(normalizedId, out var tenant) ? tenant : null;
 37    }
 38
 39    /// <summary>
 40    /// Finds a tenant based on the provided predicate.
 41    /// </summary>
 42    /// <param name="predicate">The predicate used to filter the tenants.</param>
 43    /// <returns>The found tenant or null if no tenant satisfies the predicate.</returns>
 44    public Tenant? FindTenant(Func<Tenant, bool> predicate)
 45    {
 346        return _tenantsDictionary.Values.FirstOrDefault(predicate);
 47    }
 48}