< Summary

Information
Class: Elsa.Workflows.Management.Activities.WorkflowDefinitionActivity.WorkflowDefinitionActivityDescriptorFactory
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Activities/WorkflowDefinitionActivity/WorkflowDefinitionActivityDescriptorFactory.cs
Line coverage
97%
Covered lines: 94
Uncovered lines: 2
Coverable lines: 96
Total lines: 121
Line coverage: 97.9%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CreateDescriptor(...)100%88100%
DescribeInputs()100%22100%
DescribeOutputs(...)100%1194.11%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Activities/WorkflowDefinitionActivity/WorkflowDefinitionActivityDescriptorFactory.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Workflows.Management.Entities;
 3using Elsa.Workflows.Models;
 4using Humanizer;
 5
 6namespace Elsa.Workflows.Management.Activities.WorkflowDefinitionActivity;
 7
 8public class WorkflowDefinitionActivityDescriptorFactory
 9{
 10    public ActivityDescriptor CreateDescriptor(WorkflowDefinition definition, WorkflowDefinition? latestPublishedDefinit
 11    {
 76512        var typeName = definition.Name!.Pascalize();
 13
 76514        var ports = definition.Outcomes.Select(outcome => new Port
 76515        {
 76516            Name = outcome,
 76517            DisplayName = outcome,
 76518            IsBrowsable = true,
 76519            Type = PortType.Flow
 76520        }).ToList();
 21
 76522        var rootPort = new Port
 76523        {
 76524            Name = nameof(WorkflowDefinitionActivity.Root),
 76525            DisplayName = "Root",
 76526            IsBrowsable = false,
 76527            Type = PortType.Embedded
 76528        };
 29
 76530        ports.Insert(0, rootPort);
 31
 76532        return new()
 76533        {
 76534            TypeName = typeName,
 76535            ClrType = typeof(WorkflowDefinitionActivity),
 76536            Name = typeName,
 76537            Version = definition.Version,
 76538            DisplayName = definition.Name,
 76539            Description = definition.Description,
 76540            Category = definition.Options.ActivityCategory ?? "Workflows",
 76541            Kind = ActivityKind.Action,
 76542            IsBrowsable = definition.IsPublished,
 76543            Inputs = DescribeInputs(definition).ToList(),
 76544            Outputs = DescribeOutputs(definition).ToList(),
 76545            Ports = ports,
 76546            CustomProperties =
 76547            {
 76548                ["RootType"] = nameof(WorkflowDefinitionActivity),
 76549                ["WorkflowDefinitionId"] = definition.DefinitionId,
 76550                ["WorkflowDefinitionVersionId"] = definition.Id
 76551            },
 76552            ConstructionProperties = new Dictionary<string, object>
 76553            {
 76554                [nameof(WorkflowDefinitionActivity.WorkflowDefinitionId)] = definition.DefinitionId,
 76555                [nameof(WorkflowDefinitionActivity.WorkflowDefinitionVersionId)] = definition.Id,
 76556                [nameof(WorkflowDefinitionActivity.Version)] = definition.Version,
 76557            },
 76558            Constructor = context =>
 76559            {
 52060                var activity = context.CreateActivity<WorkflowDefinitionActivity>();
 52061                activity.Type = typeName;
 52062                activity.WorkflowDefinitionId = definition.DefinitionId;
 52063                activity.WorkflowDefinitionVersionId = definition.Id;
 52064                activity.Version = definition.Version;
 52065                activity.LatestAvailablePublishedVersion = latestPublishedDefinition?.Version ?? definition.Version;
 52066                activity.LatestAvailablePublishedVersionId = latestPublishedDefinition?.Id ?? definition.Id;
 76567
 52068                return activity;
 76569            }
 76570        };
 71    }
 72
 73    private static IEnumerable<InputDescriptor> DescribeInputs(WorkflowDefinition definition)
 74    {
 76575        var inputs = definition.Inputs.Select(inputDefinition =>
 76576        {
 6477            var nakedType = inputDefinition.Type;
 6478            var inputName = inputDefinition.Name;
 6479            var safeInputName = PropertyNameHelper.GetSafePropertyName(typeof(WorkflowDefinitionActivity), inputName);
 76580
 6481            return new InputDescriptor
 6482            {
 6483                Type = nakedType,
 6484                IsWrapped = true,
 1685                ValueGetter = activity => activity.SyntheticProperties.GetValueOrDefault(safeInputName),
 086                ValueSetter = (activity, value) => activity.SyntheticProperties[safeInputName] = value!,
 6487                Name = safeInputName,
 6488                DisplayName = inputDefinition.DisplayName,
 6489                Description = inputDefinition.Description,
 6490                Category = inputDefinition.Category,
 6491                UIHint = inputDefinition.UIHint,
 6492                StorageDriverType = inputDefinition.StorageDriverType,
 6493                IsSynthetic = true
 6494            };
 76595        });
 96
 165897        foreach (var input in inputs)
 6498            yield return input;
 76599    }
 100
 101    private static IEnumerable<OutputDescriptor> DescribeOutputs(WorkflowDefinition definition)
 102    {
 765103        return definition.Outputs.Select(outputDefinition =>
 765104        {
 192105            var nakedType = outputDefinition.Type;
 192106            var outputName = outputDefinition.Name;
 192107            var safeOutputName = PropertyNameHelper.GetSafePropertyName(typeof(WorkflowDefinitionActivity), outputName);
 765108
 192109            return new OutputDescriptor
 192110            {
 192111                Type = nakedType,
 9112                ValueGetter = activity => activity.SyntheticProperties.GetValueOrDefault(safeOutputName),
 0113                ValueSetter = (activity, value) => activity.SyntheticProperties[safeOutputName] = value!,
 192114                Name = safeOutputName,
 192115                DisplayName = outputDefinition.DisplayName,
 192116                Description = outputDefinition.Description,
 192117                IsSynthetic = true
 192118            };
 765119        });
 120    }
 121}