< Summary

Information
Class: Elsa.Secrets.Repositories.SecretRepositoryTenant
Assembly: Elsa.Secrets
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Secrets/Repositories/SecretRepositoryTenant.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 38
Line coverage: 100%
Branch coverage
83%
Covered branches: 20
Total branches: 24
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CurrentTenantId(...)50%44100%
Stamp(...)100%88100%
IsVisible(...)100%22100%
CanReplace(...)100%22100%
HasName(...)100%11100%
HasSameTenantName(...)75%88100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Secrets/Repositories/SecretRepositoryTenant.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using Elsa.Secrets.Contracts;
 3
 4namespace Elsa.Secrets.Repositories;
 5
 6/// <summary>
 7/// Applies the same ambient-tenant visibility and write rules used by EF Core persistence to the
 8/// default secret repositories.
 9/// </summary>
 10internal static class SecretRepositoryTenant
 11{
 12    public static string CurrentTenantId(ITenantAccessor? tenantAccessor) =>
 14813        tenantAccessor?.TenantId ?? Tenant.DefaultTenantId;
 14
 15    public static void Stamp(Secret secret, ITenantAccessor? tenantAccessor, bool tenancyEnabled)
 16    {
 17417        if (!tenancyEnabled || tenantAccessor is null || secret.TenantId == Tenant.AgnosticTenantId)
 9418            return;
 19
 8020        secret.TenantId ??= tenantAccessor.TenantId;
 8021    }
 22
 23    public static bool IsVisible(Secret secret, ITenantAccessor? tenantAccessor, bool tenancyEnabled) =>
 29824        !tenancyEnabled || TenantVisibility.IsVisible(secret.TenantId, CurrentTenantId(tenantAccessor));
 25
 26    public static bool CanReplace(Secret existing, Secret incoming, ITenantAccessor? tenantAccessor, bool tenancyEnabled
 3527        !tenancyEnabled || TenantVisibility.CanReplaceOwnedRow(existing.TenantId, incoming.TenantId, CurrentTenantId(ten
 28
 29    public static bool HasName(Secret secret, string name, ISecretNameValidator nameValidator) =>
 25830        string.Equals(nameValidator.Normalize(secret.Name), nameValidator.Normalize(name), StringComparison.Ordinal);
 31
 32    public static bool HasSameTenantName(Secret existing, Secret incoming, ISecretNameValidator nameValidator, bool tena
 5233        HasName(existing, incoming.Name, nameValidator)
 5234        && (!tenancyEnabled || string.Equals(
 5235            existing.TenantId ?? Tenant.DefaultTenantId,
 5236            incoming.TenantId ?? Tenant.DefaultTenantId,
 5237            StringComparison.Ordinal));
 38}