< Summary

Information
Class: Elsa.Tenants.DefaultTenantResolverPipelineInvoker
Assembly: Elsa.Tenants
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Services/DefaultTenantResolverPipelineInvoker.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 41
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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%
InvokePipelineAsync()0%4260%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Services/DefaultTenantResolverPipelineInvoker.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using Elsa.Tenants.Options;
 3using Microsoft.Extensions.Logging;
 4using Microsoft.Extensions.Options;
 5
 6namespace Elsa.Tenants;
 7
 8/// <summary>
 9/// Resolves the tenant using a pipeline of resolvers.
 10/// </summary>
 011public class DefaultTenantResolverPipelineInvoker(
 012    IOptions<MultitenancyOptions> options,
 013    ITenantsProvider tenantsProvider,
 014    IServiceProvider serviceProvider,
 015    ILogger<DefaultTenantResolverPipelineInvoker> logger) : ITenantResolverPipelineInvoker
 16{
 17    public async Task<Tenant?> InvokePipelineAsync(CancellationToken cancellationToken = default)
 18    {
 019        var resolutionPipeline = options.Value.TenantResolverPipelineBuilder.Build(serviceProvider);
 020        var tenantsDictionary = (await tenantsProvider.ListAsync(cancellationToken)).ToDictionary(x => x.Id);
 021        var context = new TenantResolverContext(tenantsDictionary, cancellationToken);
 22
 023        foreach (var resolver in resolutionPipeline)
 24        {
 025            var result = await resolver.ResolveAsync(context);
 26
 027            if (result.IsResolved)
 28            {
 029                var resolvedTenantId = result.ResolveTenantId();
 30
 031                if (tenantsDictionary.TryGetValue(resolvedTenantId, out var tenant))
 032                    return tenant;
 33
 034                logger.LogWarning("Tenant with ID {TenantId} was resolved but could not be found in the tenant store.", 
 035                return null;
 36            }
 37        }
 38
 039        return null;
 040    }
 41}