< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.Events.TriggerAuthenticated.Trigger
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/Events/TriggerAuthenticated/Endpoint.cs
Line coverage
31%
Covered lines: 6
Uncovered lines: 13
Coverable lines: 19
Total lines: 53
Line coverage: 31.5%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
HandleAsync()0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/Events/TriggerAuthenticated/Endpoint.cs

#LineLine coverage
 1using Elsa.Authorization;
 2using Elsa.Abstractions;
 3using Elsa.Workflows.Models;
 4using Elsa.Workflows.Runtime;
 5using JetBrains.Annotations;
 6
 7namespace Elsa.Workflows.Api.Endpoints.Events.TriggerAuthenticated;
 8
 9/// <summary>
 10/// Triggers all workflows that are waiting for the specified event.
 11/// </summary>
 12[PublicAPI]
 13internal class Trigger : ElsaEndpoint<Request>
 14{
 15    private readonly IEventPublisher _eventPublisher;
 16
 17    /// <inheritdoc />
 318    public Trigger(IEventPublisher eventPublisher)
 19    {
 320        _eventPublisher = eventPublisher;
 321    }
 22
 23    /// <inheritdoc />
 24    public override void Configure()
 25    {
 326        Post("/events/{eventName}/trigger");
 327        RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.Events, "trigger");
 328    }
 29
 30    /// <inheritdoc />
 31    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 32    {
 033        var input = (IDictionary<string, object>?)request.Input;
 034        var eventName = request.EventName;
 035        var correlationId = request.CorrelationId;
 036        var workflowInstanceId = request.WorkflowInstanceId;
 037        var activityInstanceId = request.ActivityInstanceId;
 038        var workflowExecutionMode = request.WorkflowExecutionMode;
 39
 040        if (workflowExecutionMode == WorkflowExecutionMode.Asynchronous)
 41        {
 042            await _eventPublisher.PublishAsync(eventName, correlationId, workflowInstanceId, activityInstanceId, input, 
 043            await Send.OkAsync(cancellation: cancellationToken);
 44        }
 45        else
 46        {
 047            await _eventPublisher.PublishAsync(eventName, correlationId, workflowInstanceId, activityInstanceId, input, 
 48
 049            if (!HttpContext.Response.HasStarted)
 050                await Send.OkAsync(cancellation: cancellationToken);
 51        }
 052    }
 53}