< Summary

Information
Class: Elsa.Common.Multitenancy.TenantEventsManager
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Multitenancy/Implementations/TenantEventsManager.cs
Line coverage
70%
Covered lines: 21
Uncovered lines: 9
Coverable lines: 30
Total lines: 56
Line coverage: 70%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
TenantActivatedAsync()100%11100%
TenantDeactivatedAsync()100%11100%
TenantDeletedAsync()100%210%
ExecuteEventHandlersAsync()100%2257.14%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Multitenancy/Implementations/TenantEventsManager.cs

#LineLine coverage
 1using Microsoft.Extensions.Logging;
 2
 3namespace Elsa.Common.Multitenancy;
 4
 15public class TenantEventsManager(
 16    IEnumerable<ITenantActivatedEvent> tenantActivatedEvents,
 17    IEnumerable<ITenantDeactivatedEvent> tenantDeactivatedEvents,
 18    IEnumerable<ITenantDeletedEvent> tenantDeletedEvents,
 19    ILogger<TenantEventsManager> logger)
 10{
 11    public async Task TenantActivatedAsync(TenantActivatedEventArgs args)
 12    {
 113        await ExecuteEventHandlersAsync(
 114            tenantActivatedEvents,
 415            (handler, eventArgs) => handler.TenantActivatedAsync(eventArgs),
 116            args,
 117            "activated");
 118    }
 19
 20    public async Task TenantDeactivatedAsync(TenantDeactivatedEventArgs args)
 21    {
 122        await ExecuteEventHandlersAsync(
 123            tenantDeactivatedEvents,
 224            (handler, eventArgs) => handler.TenantDeactivatedAsync(eventArgs),
 125            args,
 126            "deactivated");
 127    }
 28
 29    public async Task TenantDeletedAsync(TenantDeletedEventArgs args)
 30    {
 031        await ExecuteEventHandlersAsync(
 032            tenantDeletedEvents,
 033            (handler, eventArgs) => handler.TenantDeletedAsync(eventArgs),
 034            args,
 035            "deleted");
 036    }
 37
 38    private async Task ExecuteEventHandlersAsync<THandler, TArgs>(
 39        IEnumerable<THandler> handlers,
 40        Func<THandler, TArgs, Task> handlerAction,
 41        TArgs args,
 42        string eventType)
 43    {
 1644        foreach (var handler in handlers)
 45        {
 46            try
 47            {
 648                await handlerAction(handler, args);
 649            }
 050            catch (Exception e)
 51            {
 052                logger.LogError(e, "Error occurred while processing tenant {EventType} event.", eventType);
 053            }
 54        }
 255    }
 56}