< Summary

Information
Class: Elsa.Workflows.Runtime.EventPublisher
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/EventPublisher.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 45
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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%
PublishAsync()100%44100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/EventPublisher.cs

#LineLine coverage
 1using Elsa.Workflows.Helpers;
 2using Elsa.Workflows.Runtime.Activities;
 3using Elsa.Workflows.Runtime.Stimuli;
 4
 5namespace Elsa.Workflows.Runtime;
 6
 7/// <inheritdoc />
 68public class EventPublisher(IStimulusSender stimulusSender, IStimulusDispatcher stimulusDispatcher) : IEventPublisher
 9{
 10    /// <inheritdoc />
 11    public async Task PublishAsync(
 12        string eventName,
 13        string? correlationId = null,
 14        string? workflowInstanceId = null,
 15        string? activityInstanceId = null,
 16        object? payload = null,
 17        bool asynchronous = false,
 18        CancellationToken cancellationToken = default)
 19    {
 520        var stimulus = new EventStimulus(eventName);
 521        var workflowInput = new Dictionary<string, object>
 522        {
 523            [Event.EventInputWorkflowInputKey] = payload ?? new Dictionary<string, object>()
 524        };
 525        var metadata = new StimulusMetadata
 526        {
 527            CorrelationId = correlationId,
 528            ActivityInstanceId = activityInstanceId,
 529            WorkflowInstanceId = workflowInstanceId,
 530            Input = workflowInput
 531        };
 532        var triggerName = ActivityTypeNameHelper.GenerateTypeName<Event>();
 533        if (asynchronous)
 34        {
 335            await stimulusDispatcher.SendAsync(new()
 336            {
 337                ActivityTypeName = triggerName,
 338                Stimulus = stimulus,
 339                Metadata = metadata
 340            }, cancellationToken);
 41        }
 42        else
 243            await stimulusSender.SendAsync(triggerName, stimulus, metadata, cancellationToken);
 544    }
 45}