< Summary

Information
Class: Elsa.Workflows.Runtime.Activities.PublishEvent
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Activities/PublishEvent.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 53
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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%
get_EventName()100%11100%
get_CorrelationId()100%11100%
get_IsLocalEvent()100%11100%
get_Payload()100%11100%
ExecuteAsync()100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Activities/PublishEvent.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using JetBrains.Annotations;
 3using System.Runtime.CompilerServices;
 4using Elsa.Workflows.Attributes;
 5using Elsa.Workflows.Models;
 6
 7namespace Elsa.Workflows.Runtime.Activities;
 8
 9/// <summary>
 10/// Faults the workflow.
 11/// </summary>
 12[Activity("Elsa", "Primitives", "Publishes an event.")]
 13[UsedImplicitly]
 3914public class PublishEvent([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : Activity(source
 15{
 16    /// <summary>
 17    /// The name of the event to publish.
 18    /// </summary>
 19    [Input(Description = "The name of the event to publish.")]
 14120    public Input<string> EventName { get; set; } = null!;
 21
 22    /// <summary>
 23    /// The correlation ID to scope the event to.
 24    /// </summary>
 25    [Input(Description = "The correlation ID to scope the event to.")]
 12026    public Input<string?> CorrelationId { get; set; } = null!;
 27
 28    /// <summary>
 29    /// Whether the event is local to the workflow.
 30    /// </summary>
 31    [Input(DisplayName = "Local event", Description = "Whether the event is local to the workflow. When checked, the eve
 13832    public Input<bool> IsLocalEvent { get; set; } = null!;
 33
 34    /// <summary>
 35    /// The input to send as the event body.
 36    /// </summary>
 37    [Input(Description = "The payload to send as the event body.")]
 13838    public Input<object> Payload { get; set; } = null!;
 39
 40    /// <inheritdoc />
 41    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
 42    {
 343        var eventName = EventName.Get(context);
 344        var correlationId = CorrelationId.GetOrDefault(context).NullIfWhiteSpace();
 345        var isLocalEvent = IsLocalEvent.GetOrDefault(context);
 346        var workflowInstanceId = isLocalEvent ? context.WorkflowExecutionContext.Id : null;
 347        var payload = Payload.GetOrDefault(context);
 348        var publisher = context.GetRequiredService<IEventPublisher>();
 49
 350        await publisher.PublishAsync(eventName, correlationId, workflowInstanceId, null, payload, true, context.Cancella
 351        await context.CompleteActivityAsync();
 352    }
 53}