< Summary

Information
Class: Elsa.Http.TriggerPayloadValidators.HttpEndpointTriggerPayloadValidator
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/TriggerPayloadValidators/HttpEndpointTriggerPayloadValidator.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 41
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ValidateAsync()100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/TriggerPayloadValidators/HttpEndpointTriggerPayloadValidator.cs

#LineLine coverage
 1using Elsa.Http.Bookmarks;
 2using Elsa.Workflows.Activities;
 3using Elsa.Workflows.Helpers;
 4using Elsa.Workflows.Management.Models;
 5using Elsa.Workflows.Runtime;
 6using Elsa.Workflows.Runtime.Contracts;
 7using Elsa.Workflows.Runtime.Entities;
 8using Elsa.Workflows.Runtime.Filters;
 9
 10namespace Elsa.Http.TriggerPayloadValidators;
 11
 412public class HttpEndpointTriggerPayloadValidator(ITriggerStore triggerStore) : ITriggerPayloadValidator<HttpEndpointBook
 13{
 14    public async Task ValidateAsync(
 15        HttpEndpointBookmarkPayload payload,
 16        Workflow workflow,
 17        StoredTrigger trigger,
 18        ICollection<WorkflowValidationError> validationErrors,
 19        CancellationToken cancellationToken)
 20    {
 821        var filter = new TriggerFilter
 822        {
 823            Name = ActivityTypeNameHelper.GenerateTypeName(typeof(HttpEndpoint))
 824        };
 825        var publishedWorkflowsTriggers = (await triggerStore.FindManyAsync(filter, cancellationToken)).ToList();
 26
 827        var otherWorkflowsWithSamePath = publishedWorkflowsTriggers
 828            .Where(x =>
 1829                x.WorkflowDefinitionId != workflow.Identity.DefinitionId &&
 1830                x.Payload is HttpEndpointBookmarkPayload anotherHttpEndpointPayload &&
 1831                anotherHttpEndpointPayload.Path == payload.Path &&
 1832                anotherHttpEndpointPayload.Method == payload.Method)
 833            .ToList();
 34
 835        if (otherWorkflowsWithSamePath.Count == 0)
 636            return;
 37
 238        validationErrors.Add(new($"The {payload.Path} path and {payload.Method} method are already in use by another wor
 239            trigger.ActivityId));
 840    }
 41}