< Summary

Information
Class: Elsa.Http.FlowSendHttpRequest
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Activities/FlowSendHttpRequest.cs
Line coverage
95%
Covered lines: 19
Uncovered lines: 1
Coverable lines: 20
Total lines: 70
Line coverage: 95%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
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_ExpectedStatusCodes()100%11100%
HandleResponseAsync()87.5%88100%
HandleRequestExceptionAsync()100%11100%
HandleTaskCanceledExceptionAsync()100%11100%
Elsa.Workflows.IActivityPropertyDefaultValueProvider.GetDefaultValue(...)50%2266.66%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Activities/FlowSendHttpRequest.cs

#LineLine coverage
 1using System.Reflection;
 2using System.Runtime.CompilerServices;
 3using Elsa.Extensions;
 4using Elsa.Workflows;
 5using Elsa.Workflows.Attributes;
 6using Elsa.Workflows.UIHints;
 7using Elsa.Workflows.Models;
 8
 9namespace Elsa.Http;
 10
 11/// <summary>
 12/// Send an HTTP request.
 13/// </summary>
 14[Activity("Elsa", "HTTP", "Send an HTTP request.", DisplayName = "HTTP Request (flow)", Kind = ActivityKind.Task)]
 15public class FlowSendHttpRequest : SendHttpRequestBase, IActivityPropertyDefaultValueProvider
 16{
 17    /// <inheritdoc />
 7018    public FlowSendHttpRequest([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(sourc
 19    {
 7020    }
 21
 22    /// <summary>
 23    /// A list of expected status codes to handle.
 24    /// </summary>
 25    [Input(
 26        Description = "A list of expected status codes to handle.",
 27        UIHint = InputUIHints.MultiText,
 28        DefaultValueProvider = typeof(FlowSendHttpRequest),
 29        Order = 5.1f
 30    )]
 6331    public Input<ICollection<int>> ExpectedStatusCodes { get; set; } = null!;
 32
 33    /// <inheritdoc />
 34    protected override async ValueTask HandleResponseAsync(ActivityExecutionContext context, HttpResponseMessage respons
 35    {
 1236        var expectedStatusCodes = ExpectedStatusCodes.GetOrDefault(context) ?? new List<int>(0);
 1237        var statusCode = (int)response.StatusCode;
 1238        var hasMatchingStatusCode = expectedStatusCodes.Contains(statusCode);
 1239        var outcome = expectedStatusCodes.Any() ? hasMatchingStatusCode ? statusCode.ToString() : "Unmatched status code
 1240        var outcomes = new List<string>();
 41
 1242        if (outcome != null)
 1143            outcomes.Add(outcome);
 44
 1245        outcomes.Add("Done");
 1246        await context.CompleteActivityWithOutcomesAsync(outcomes.ToArray());
 1247    }
 48
 49    /// <inheritdoc />
 50    protected override async ValueTask HandleRequestExceptionAsync(ActivityExecutionContext context, HttpRequestExceptio
 51    {
 152        await context.CompleteActivityWithOutcomesAsync("Failed to connect");
 153    }
 54
 55    /// <inheritdoc />
 56    protected override async ValueTask HandleTaskCanceledExceptionAsync(ActivityExecutionContext context, TaskCanceledEx
 57    {
 158        await context.CompleteActivityWithOutcomesAsync("Timeout");
 159    }
 60
 61    object IActivityPropertyDefaultValueProvider.GetDefaultValue(PropertyInfo property)
 62    {
 5563        if (property.Name == nameof(ExpectedStatusCodes))
 64        {
 5565            return new List<int> { 200 };
 66        }
 67
 068        return null!;
 69    }
 70}