< Summary

Information
Class: Elsa.Workflows.Management.Services.WorkflowDefinitionActivityRegistryUpdater
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionActivityRegistryUpdater.cs
Line coverage
100%
Covered lines: 26
Uncovered lines: 0
Coverable lines: 26
Total lines: 56
Line coverage: 100%
Branch coverage
75%
Covered branches: 9
Total branches: 12
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
AddToRegistry()100%22100%
RemoveDefinitionFromRegistry(...)75%44100%
RemoveDefinitionVersionFromRegistry(...)75%44100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionActivityRegistryUpdater.cs

#LineLine coverage
 1using Elsa.Workflows.Management.Activities.WorkflowDefinitionActivity;
 2using Elsa.Workflows.Management.Contracts;
 3using Elsa.Workflows.Models;
 4
 5namespace Elsa.Workflows.Management.Services;
 6
 7/// <summary>
 8/// Service responsible for updating the activity registry based on activity providers.
 9/// </summary>
 31910public class WorkflowDefinitionActivityRegistryUpdater(WorkflowDefinitionActivityProvider provider, IActivityRegistry re
 11{
 31912    private readonly Type _providerType = typeof(WorkflowDefinitionActivityProvider);
 13
 14    /// <inheritdoc />
 15    public async Task AddToRegistry(string workflowDefinitionVersionId, CancellationToken cancellationToken)
 16    {
 6317        var descriptors = await provider.GetDescriptorsAsync(cancellationToken);
 6318        var descriptorToAdd = descriptors
 6319            .FirstOrDefault(d =>
 45120                d.CustomProperties.TryGetValue("WorkflowDefinitionVersionId", out var val) &&
 45121                val.ToString() == workflowDefinitionVersionId);
 22
 6323        if (descriptorToAdd is not null)
 6324            registry.Add(_providerType, descriptorToAdd);
 6325    }
 26
 27    /// <inheritdoc />
 28    public void RemoveDefinitionFromRegistry(string workflowDefinitionId)
 29    {
 430        var providerDescriptors = registry.ListByProvider(_providerType);
 31
 432        var descriptorsToRemove = providerDescriptors
 433            .Where(d =>
 4834                d.CustomProperties.TryGetValue("WorkflowDefinitionId", out var val) &&
 4835                val.ToString() == workflowDefinitionId).ToList();
 36
 1837        foreach (ActivityDescriptor activityDescriptor in descriptorsToRemove)
 38        {
 539            registry.Remove(_providerType, activityDescriptor);
 40        }
 441    }
 42
 43    /// <inheritdoc />
 44    public void RemoveDefinitionVersionFromRegistry(string workflowDefinitionVersionId)
 45    {
 37746        var providerDescriptors = registry.ListByProvider(_providerType);
 47
 37748        var descriptorToRemove = providerDescriptors
 37749            .FirstOrDefault(d =>
 426750                d.CustomProperties.TryGetValue("WorkflowDefinitionVersionId", out var val) &&
 426751                val.ToString() == workflowDefinitionVersionId);
 52
 37753        if (descriptorToRemove is not null)
 154            registry.Remove(_providerType, descriptorToRemove);
 37755    }
 56}