< Summary

Information
Class: Elsa.Workflows.ActivityExecutionContextSchedulerStrategy
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/ActivityExecutionContextSchedulerStrategy.cs
Line coverage
42%
Covered lines: 17
Uncovered lines: 23
Coverable lines: 40
Total lines: 71
Line coverage: 42.5%
Branch coverage
25%
Covered branches: 11
Total branches: 44
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ScheduleActivityAsync()75%44100%
ScheduleActivityAsync()20%4944034.28%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/ActivityExecutionContextSchedulerStrategy.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Workflows.Models;
 3using Elsa.Workflows.Options;
 4
 5namespace Elsa.Workflows;
 6
 7/// <inheritdoc />
 8public class ActivityExecutionContextSchedulerStrategy : IActivityExecutionContextSchedulerStrategy
 9{
 10    /// <inheritdoc />
 11    public async Task ScheduleActivityAsync(ActivityExecutionContext context, IActivity? activity, ActivityExecutionCont
 12    {
 259313        var activityNode = activity != null
 259314            ? context.WorkflowExecutionContext.FindNodeByActivity(activity) ?? throw new InvalidOperationException("The 
 259315            : null;
 259316        await ScheduleActivityAsync(context, activityNode, owner, options);
 259317    }
 18
 19    /// <inheritdoc />
 20    public async Task ScheduleActivityAsync(ActivityExecutionContext context, ActivityNode? activityNode, ActivityExecut
 21    {
 259322        var workflowExecutionContext = context.WorkflowExecutionContext;
 259323        if (context.GetIsBackgroundExecution())
 24        {
 25            // Validate that the specified activity is part of the workflow.
 026            if (activityNode != null && !workflowExecutionContext.NodeActivityLookup.ContainsKey(activityNode.Activity))
 027                throw new InvalidOperationException("The specified activity is not part of the workflow.");
 28
 029            var scheduledActivity = new ScheduledActivity
 030            {
 031                ActivityNodeId = activityNode?.NodeId,
 032                OwnerActivityInstanceId = owner?.Id,
 033                Options = options != null
 034                    ? new ScheduledActivityOptions
 035                    {
 036                        CompletionCallback = options?.CompletionCallback?.Method.Name,
 037                        Tag = options?.Tag,
 038                        ExistingActivityInstanceId = options?.ExistingActivityExecutionContext?.Id,
 039                        PreventDuplicateScheduling = options?.PreventDuplicateScheduling ?? false,
 040                        Variables = options?.Variables?.ToList(),
 041                        Input = options?.Input
 042                    }
 043                    : null
 044            };
 45
 046            var scheduledActivities = context.GetBackgroundScheduledActivities().ToList();
 047            scheduledActivities.Add(scheduledActivity);
 048            context.SetBackgroundScheduledActivities(scheduledActivities);
 049            return;
 50        }
 51
 259352        var completionCallback = options?.CompletionCallback;
 259353        owner ??= context;
 54
 259355        if (activityNode == null)
 56        {
 1057            if (completionCallback != null)
 58            {
 1059                context.Tag = options?.Tag;
 1060                var completedContext = new ActivityCompletedContext(context, context);
 1061                await completionCallback(completedContext);
 62            }
 63            else
 064                await owner.CompleteActivityAsync();
 65
 1066            return;
 67        }
 68
 258369        workflowExecutionContext.Schedule(activityNode, owner, options);
 259370    }
 71}