< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.Tests.Activities.Endpoint
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/Tests/Activities/Endpoint.cs
Line coverage
23%
Covered lines: 7
Uncovered lines: 23
Coverable lines: 30
Total lines: 83
Line coverage: 23.3%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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%4260%

File(s)

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

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Workflows.Management;
 3using Elsa.Workflows.Models;
 4using Elsa.Workflows.Runtime;
 5using Elsa.Workflows.State;
 6
 7namespace Elsa.Workflows.Api.Endpoints.Tests.Activities;
 8
 9/// <summary>
 10/// Represents an endpoint for testing activities in workflows. This endpoint is responsible for handling requests
 11/// that test the execution of a specific activity in a workflow and returning the results.
 12/// </summary>
 13/// <remarks>
 14/// This endpoint is used to perform operations such as:
 15/// - Finding a workflow graph based on a provided workflow definition handle.
 16/// - Locating and executing a specific activity within the workflow graph.
 17/// - Capturing the execution results and returning them as a response.
 18/// </remarks>
 119internal class Endpoint(
 120    IWorkflowDefinitionService workflowDefinitionService,
 121    IActivityTestRunner activityTestRunner,
 122    IActivityExecutionMapper activityExecutionMapper)
 23    : ElsaEndpoint<Request>
 24{
 25    /// <inheritdoc />
 26    public override void Configure()
 27    {
 128        Post("/tests/activities");
 129        ConfigurePermissions("exec:tests");
 130    }
 31
 32    /// <inheritdoc />
 33    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 34    {
 035        var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(request.WorkflowDefinitionHandle, can
 36
 037        if (workflowGraph == null)
 38        {
 039            AddError("Workflow definition not found.");
 040            await Send.ErrorsAsync(cancellation: cancellationToken);
 041            return;
 42        }
 43
 044        var activity = workflowGraph.FindActivity(request.ActivityHandle);
 45
 046        if (activity == null)
 47        {
 048            AddError("Activity not found.");
 049            await Send.ErrorsAsync(cancellation: cancellationToken);
 050            return;
 51        }
 52
 053        var activityExecutionContext = await activityTestRunner.RunAsync(workflowGraph, activity, cancellationToken);
 054        var record = await activityExecutionMapper.MapAsync(activityExecutionContext);
 055        var activityState = record.ActivityState ?? new Dictionary<string, object?>();
 56
 057        var response = new Response
 058        {
 059            ActivityState = activityState,
 060            Outputs = record.Outputs,
 061            Payload = record.Payload,
 062            Exception = record.Exception,
 063            Status = record.Status
 064        };
 65
 066        await Send.OkAsync(response, cancellationToken);
 067    }
 68}
 69
 70public class Request
 71{
 72    public WorkflowDefinitionHandle WorkflowDefinitionHandle { get; set; } = null!;
 73    public ActivityHandle ActivityHandle { get; set; } = null!;
 74}
 75
 76public class Response
 77{
 78    public IDictionary<string, object?> ActivityState { get; set; } = null!;
 79    public IDictionary<string, object?>? Outputs { get; set; }
 80    public IDictionary<string, object>? Payload { get; set; }
 81    public ExceptionState? Exception { get; set; }
 82    public ActivityStatus Status { get; set; }
 83}