< Summary

Information
Class: Elsa.Tenants.AspNetCore.Services.TenantPrefixHttpEndpointBasePathProvider
Assembly: Elsa.Tenants.AspNetCore
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants.AspNetCore/Services/TenantPrefixHttpEndpointBasePathProvider.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 33
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
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%
GetBasePath()0%156120%

File(s)

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

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using Elsa.Http;
 3using Elsa.Http.Options;
 4using JetBrains.Annotations;
 5using Microsoft.Extensions.Options;
 6
 7namespace Elsa.Tenants.AspNetCore.Services;
 8
 9[UsedImplicitly]
 010public class TenantPrefixHttpEndpointBasePathProvider(
 011    IOptions<HttpActivityOptions> options,
 012    IEnumerable<ITenantResolver> tenantResolvers,
 013    ITenantAccessor tenantAccessor) : IHttpEndpointBasePathProvider
 14{
 15    public string GetBasePath()
 16    {
 017        var baseUrl = options.Value.BaseUrl.ToString();
 018        var basePath = options.Value.BasePath?.ToString().TrimStart('/');
 019        var routePrefixTenantResolverIsEnabled = tenantResolvers.Any(x => x is RoutePrefixTenantResolver);
 20
 021        if(!routePrefixTenantResolverIsEnabled)
 022            return (baseUrl + basePath).TrimEnd('/') + '/';
 23
 024        var tenant = tenantAccessor.Tenant;
 025        var tenantPrefix = tenant?.GetRoutePrefix()?.Trim('/');
 26
 027        if(string.IsNullOrWhiteSpace(tenantPrefix))
 028            return (baseUrl + basePath).TrimEnd('/') + '/';
 29
 030        var completeBaseUrl = new Uri(baseUrl + tenantPrefix + "/") + basePath;
 031        return completeBaseUrl.TrimEnd('/') + '/';
 32    }
 33}