< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.Tests.Activities.Response
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
0%
Covered lines: 0
Uncovered lines: 5
Coverable lines: 5
Total lines: 83
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_ActivityState()100%210%
get_Outputs()100%210%
get_Payload()100%210%
get_Exception()100%210%
get_Status()100%210%

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>
 19internal class Endpoint(
 20    IWorkflowDefinitionService workflowDefinitionService,
 21    IActivityTestRunner activityTestRunner,
 22    IActivityExecutionMapper activityExecutionMapper)
 23    : ElsaEndpoint<Request>
 24{
 25    /// <inheritdoc />
 26    public override void Configure()
 27    {
 28        Post("/tests/activities");
 29        ConfigurePermissions("exec:tests");
 30    }
 31
 32    /// <inheritdoc />
 33    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 34    {
 35        var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(request.WorkflowDefinitionHandle, can
 36
 37        if (workflowGraph == null)
 38        {
 39            AddError("Workflow definition not found.");
 40            await Send.ErrorsAsync(cancellation: cancellationToken);
 41            return;
 42        }
 43
 44        var activity = workflowGraph.FindActivity(request.ActivityHandle);
 45
 46        if (activity == null)
 47        {
 48            AddError("Activity not found.");
 49            await Send.ErrorsAsync(cancellation: cancellationToken);
 50            return;
 51        }
 52
 53        var activityExecutionContext = await activityTestRunner.RunAsync(workflowGraph, activity, cancellationToken);
 54        var record = await activityExecutionMapper.MapAsync(activityExecutionContext);
 55        var activityState = record.ActivityState ?? new Dictionary<string, object?>();
 56
 57        var response = new Response
 58        {
 59            ActivityState = activityState,
 60            Outputs = record.Outputs,
 61            Payload = record.Payload,
 62            Exception = record.Exception,
 63            Status = record.Status
 64        };
 65
 66        await Send.OkAsync(response, cancellationToken);
 67    }
 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{
 078    public IDictionary<string, object?> ActivityState { get; set; } = null!;
 079    public IDictionary<string, object?>? Outputs { get; set; }
 080    public IDictionary<string, object>? Payload { get; set; }
 081    public ExceptionState? Exception { get; set; }
 082    public ActivityStatus Status { get; set; }
 83}