< 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: 52
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.Abstractions;
 2using Elsa.Workflows.Models;
 3using Elsa.Workflows.Runtime;
 4using JetBrains.Annotations;
 5
 6namespace Elsa.Workflows.Api.Endpoints.Events.TriggerAuthenticated;
 7
 8/// <summary>
 9/// Triggers all workflows that are waiting for the specified event.
 10/// </summary>
 11[PublicAPI]
 12internal class Trigger : ElsaEndpoint<Request>
 13{
 14    private readonly IEventPublisher _eventPublisher;
 15
 16    /// <inheritdoc />
 117    public Trigger(IEventPublisher eventPublisher)
 18    {
 119        _eventPublisher = eventPublisher;
 120    }
 21
 22    /// <inheritdoc />
 23    public override void Configure()
 24    {
 125        Post("/events/{eventName}/trigger");
 126        ConfigurePermissions("trigger:event");
 127    }
 28
 29    /// <inheritdoc />
 30    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 31    {
 032        var input = (IDictionary<string, object>?)request.Input;
 033        var eventName = request.EventName;
 034        var correlationId = request.CorrelationId;
 035        var workflowInstanceId = request.WorkflowInstanceId;
 036        var activityInstanceId = request.ActivityInstanceId;
 037        var workflowExecutionMode = request.WorkflowExecutionMode;
 38
 039        if (workflowExecutionMode == WorkflowExecutionMode.Asynchronous)
 40        {
 041            await _eventPublisher.PublishAsync(eventName, correlationId, workflowInstanceId, activityInstanceId, input, 
 042            await Send.OkAsync(cancellationToken);
 43        }
 44        else
 45        {
 046            await _eventPublisher.PublishAsync(eventName, correlationId, workflowInstanceId, activityInstanceId, input, 
 47
 048            if (!HttpContext.Response.HasStarted)
 049                await Send.OkAsync(cancellationToken);
 50        }
 051    }
 52}