< Summary

Information
Class: Elsa.Workflows.Runtime.Providers.ClrWorkflowsProvider
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Providers/ClrWorkflowsProvider.cs
Line coverage
100%
Covered lines: 30
Uncovered lines: 0
Coverable lines: 30
Total lines: 56
Line coverage: 100%
Branch coverage
85%
Covered branches: 12
Total branches: 14
Branch coverage: 85.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Name()100%11100%
<GetWorkflowsAsync()100%11100%
GetWorkflowsAsync()100%11100%
BuildWorkflowAsync()85.71%1414100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Providers/ClrWorkflowsProvider.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using Elsa.Extensions;
 3using Elsa.Workflows.Management.Materializers;
 4using Elsa.Workflows.Runtime.Features;
 5using Elsa.Workflows.Runtime.Options;
 6using JetBrains.Annotations;
 7using Microsoft.Extensions.Options;
 8
 9namespace Elsa.Workflows.Runtime.Providers;
 10
 11/// <summary>
 12/// Provides workflows to the system that are registered with <see cref="WorkflowRuntimeFeature"/>
 13/// </summary>
 14[UsedImplicitly]
 40315public class ClrWorkflowsProvider(
 40316    IOptions<RuntimeOptions> options,
 40317    IWorkflowBuilderFactory workflowBuilderFactory,
 40318    ITenantAccessor tenantAccessor,
 40319    IServiceProvider serviceProvider) : IWorkflowsProvider
 20{
 21    /// <inheritdoc />
 41622    public string Name => "CLR";
 23
 24    /// <inheritdoc />
 25    public async ValueTask<IEnumerable<MaterializedWorkflow>> GetWorkflowsAsync(CancellationToken cancellationToken = de
 26    {
 70027        var buildWorkflowTasks = options.Value.Workflows.Values.Select(async x => await BuildWorkflowAsync(x, cancellati
 28428        var workflowDefinitions = await Task.WhenAll(buildWorkflowTasks);
 28429        return workflowDefinitions;
 28430    }
 31
 32    private async Task<MaterializedWorkflow> BuildWorkflowAsync(Func<IServiceProvider, ValueTask<IWorkflow>> workflowFac
 33    {
 41634        var builder = workflowBuilderFactory.CreateBuilder();
 41635        var workflowBuilder = await workflowFactory(serviceProvider);
 41636        var workflowBuilderType = workflowBuilder.GetType();
 41637        var tenant = tenantAccessor.Tenant;
 41638        var tenantPrefix = !string.IsNullOrEmpty(tenant?.Id) ? $"{tenant.Id}:" : string.Empty;
 41639        await workflowBuilder.BuildAsync(builder, cancellationToken);
 41640        var workflow = await builder.BuildWorkflowAsync(cancellationToken);
 41641        var versionSuffix = $"v{workflow.Version}";
 41642        var definitionId = string.IsNullOrEmpty(workflow.Identity.DefinitionId) ? tenantPrefix + workflowBuilderType.Nam
 41643        var id = string.IsNullOrEmpty(workflow.Identity.Id) ? $"{tenantPrefix}{workflowBuilderType.Name}:{versionSuffix}
 41644        var tenantId = string.IsNullOrEmpty(workflow.Identity.TenantId) ? tenant?.Id : workflow.Identity.TenantId;
 45
 41646        workflow.Identity = workflow.Identity with
 41647        {
 41648            Id = id,
 41649            DefinitionId = definitionId,
 41650            TenantId = tenantId?.NullIfEmpty()
 41651        };
 52
 41653        var materializerContext = new ClrWorkflowMaterializerContext(workflowBuilder.GetType());
 41654        return new(workflow, Name, ClrWorkflowMaterializer.MaterializerName, materializerContext);
 41655    }
 56}