< Summary

Information
Class: Elsa.Workflows.Management.Handlers.Notifications.ValidateWorkflow
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Handlers/Notifications/ValidateWorkflow.cs
Line coverage
81%
Covered lines: 9
Uncovered lines: 2
Coverable lines: 11
Total lines: 31
Line coverage: 81.8%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
HandleAsync(...)100%11100%
ValidateUniqueNames(...)50%2260%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Handlers/Notifications/ValidateWorkflow.cs

#LineLine coverage
 1using Elsa.Mediator.Contracts;
 2using Elsa.Workflows.Management.Models;
 3using Elsa.Workflows.Management.Notifications;
 4using Elsa.Workflows.Models;
 5
 6namespace Elsa.Workflows.Management.Handlers.Notifications;
 7
 8public class ValidateWorkflow : INotificationHandler<WorkflowDefinitionValidating>
 9{
 10    public Task HandleAsync(WorkflowDefinitionValidating notification, CancellationToken cancellationToken)
 11    {
 512        var workflow = notification.Workflow;
 513        var inputs = workflow.Inputs;
 514        var outputs = workflow.Outputs;
 15
 516        ValidateUniqueNames(inputs, "inputs", notification.ValidationErrors);
 517        ValidateUniqueNames(outputs, "outputs", notification.ValidationErrors);
 18
 519        return Task.CompletedTask;
 20    }
 21
 22    private void ValidateUniqueNames(IEnumerable<ArgumentDefinition> variables, string variableType, ICollection<Workflo
 23    {
 1024        var duplicateNames = variables.GroupBy(x => x.Name).Where(x => x.Count() > 1).Select(x => x.Key).ToList();
 1025        if (duplicateNames.Any())
 26        {
 027            var message = $"The following {variableType} are defined more than once: {string.Join(", ", duplicateNames)}
 028            validationErrors.Add(new(message));
 29        }
 1030    }
 31}