< Summary

Information
Class: Elsa.Workflows.Runtime.Handlers.ValidateWorkflowRequestHandler
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Handlers/ValidateWorkflowRequestHandler.cs
Line coverage
90%
Covered lines: 18
Uncovered lines: 2
Coverable lines: 20
Total lines: 58
Line coverage: 90%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
HandleAsync()83.33%6684.61%
ValidateInternalAsync()100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Handlers/ValidateWorkflowRequestHandler.cs

#LineLine coverage
 1using System.Reflection;
 2using Elsa.Mediator.Contracts;
 3using Elsa.Workflows.Activities;
 4using Elsa.Workflows.Management.Models;
 5using Elsa.Workflows.Management.Notifications;
 6using Elsa.Workflows.Runtime.Contracts;
 7using Elsa.Workflows.Runtime.Entities;
 8using JetBrains.Annotations;
 9using Microsoft.Extensions.DependencyInjection;
 10
 11namespace Elsa.Workflows.Runtime.Handlers;
 12
 13/// <summary>
 14/// A <see cref="WorkflowDefinitionValidating"/> handler that validates a workflow path and return any errors.
 15/// </summary>
 16[UsedImplicitly]
 46717public class ValidateWorkflowRequestHandler(
 46718    ITriggerIndexer triggerIndexer,
 46719    IServiceProvider serviceProvider) : INotificationHandler<WorkflowDefinitionValidating>
 20{
 21    public async Task HandleAsync(WorkflowDefinitionValidating notification, CancellationToken cancellationToken)
 22    {
 5423        Workflow workflow = notification.Workflow;
 5424        ICollection<WorkflowValidationError> validationErrors = notification.ValidationErrors;
 13625        foreach (StoredTrigger trigger in await triggerIndexer.GetTriggersAsync(workflow, cancellationToken))
 26        {
 1427            if (trigger.Payload is null)
 28            {
 029                validationErrors.Add(new($"Trigger should have a payload",
 030                    trigger.ActivityId));
 31            }
 32            else
 33            {
 1434                MethodInfo method = typeof(ValidateWorkflowRequestHandler)
 1435                    .GetMethod(nameof(ValidateInternalAsync), BindingFlags.Instance | BindingFlags.NonPublic)!
 1436                    .MakeGenericMethod(trigger.Payload.GetType());
 37
 1438                object? result = method.Invoke(this, [trigger.Payload, workflow, trigger, validationErrors, cancellation
 1439                if (result is Task task)
 40                {
 1441                    await task;
 42                }
 43            }
 44        }
 5445    }
 46
 47    private async Task ValidateInternalAsync<TPayload>(TPayload instance,
 48        Workflow workflow,
 49        StoredTrigger trigger,
 50        ICollection<WorkflowValidationError> validationErrors,
 51        CancellationToken cancellationToken)
 52    {
 1453        ITriggerPayloadValidator<TPayload>? payloadValidator = serviceProvider.GetService<ITriggerPayloadValidator<TPayl
 54
 1455        if (payloadValidator != null)
 1256            await payloadValidator.ValidateAsync(instance, workflow, trigger, validationErrors, cancellationToken);
 1457    }
 58}