< Summary

Information
Class: Elsa.Identity.Services.MemoryIdentityUniqueness
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/MemoryIdentityUniqueness.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 35
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
EnsureAvailable(...)100%66100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Services/MemoryIdentityUniqueness.cs

#LineLine coverage
 1using Elsa.Common.Entities;
 2using Elsa.Common.Services;
 3
 4namespace Elsa.Identity.Services;
 5
 6/// <summary>
 7/// Memory counterpart of the EF <c>PerTenantIdentityUniqueness</c> indexes on
 8/// <c>(TenantId, Name)</c> and <c>(TenantId, ClientId)</c>.
 9/// </summary>
 10internal static class MemoryIdentityUniqueness
 11{
 12    /// <summary>
 13    /// Throws when another Id in the same tenant already owns <paramref name="keySelector"/>.
 14    /// Same-Id upserts are allowed so a row can rename itself.
 15    /// </summary>
 16    public static void EnsureAvailable<T>(
 17        MemoryStore<T> store,
 18        T entity,
 19        Func<T, string?> keySelector,
 20        string keyName)
 21        where T : Entity
 22    {
 16323        var key = keySelector(entity);
 16324        var existing = store.Find(candidate =>
 26125            candidate.TenantId == entity.TenantId
 26126            && candidate.Id != entity.Id
 26127            && keySelector(candidate) == key);
 28
 16329        if (existing is not null)
 30        {
 1131            throw new InvalidOperationException(
 1132                $"A {typeof(T).Name.ToLowerInvariant()} already exists with {keyName} '{key}' in tenant '{entity.TenantI
 33        }
 15234    }
 35}