< Summary

Information
Class: Elsa.Persistence.EFCore.EntityHandlers.ApplyTenantId
Assembly: Elsa.Persistence.EFCore.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Common/EntityHandlers/ApplyTenantId.cs
Line coverage
83%
Covered lines: 5
Uncovered lines: 1
Coverable lines: 6
Total lines: 28
Line coverage: 83.3%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
HandleAsync(...)87.5%8883.33%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Common/EntityHandlers/ApplyTenantId.cs

#LineLine coverage
 1using Elsa.Common.Entities;
 2using Elsa.Common.Multitenancy;
 3using Microsoft.EntityFrameworkCore.ChangeTracking;
 4
 5namespace Elsa.Persistence.EFCore.EntityHandlers;
 6
 7/// <summary>
 8/// Represents a handler for applying the tenant ID to an entity before saving changes.
 9/// </summary>
 10public class ApplyTenantId : IEntitySavingHandler
 11{
 12    /// <inheritdoc />
 13    public ValueTask HandleAsync(ElsaDbContextBase dbContext, EntityEntry entry, CancellationToken cancellationToken = d
 14    {
 3490815        if (entry.Entity is Entity entity)
 16        {
 17            // Don't touch tenant-agnostic entities (marked with "*")
 3490818            if (entity.TenantId == Tenant.AgnosticTenantId)
 019                return default;
 20
 21            // Apply current tenant ID to entities without one
 3490822            if (entity.TenantId == null && dbContext.TenantId != null)
 581123                entity.TenantId = dbContext.TenantId;
 24        }
 25
 3490826        return default;
 27    }
 28}