< Summary

Information
Class: Elsa.Http.SendHttpRequest
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Activities/SendHttpRequest.cs
Line coverage
88%
Covered lines: 16
Uncovered lines: 2
Coverable lines: 18
Total lines: 72
Line coverage: 88.8%
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_ExpectedStatusCodes()100%11100%
get_UnmatchedStatusCode()100%11100%
get_FailedToConnect()100%11100%
get_Timeout()100%11100%
HandleResponseAsync()100%22100%
HandleRequestExceptionAsync()100%11100%
HandleTaskCanceledExceptionAsync()100%11100%
OnChildActivityCompletedAsync()100%210%

File(s)

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

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2using Elsa.Workflows;
 3using Elsa.Workflows.Attributes;
 4
 5namespace Elsa.Http;
 6
 7/// <summary>
 8/// Send an HTTP request.
 9/// </summary>
 10[Activity("Elsa", "HTTP", "Send an HTTP request.", DisplayName = "HTTP Request", Kind = ActivityKind.Task)]
 11public class SendHttpRequest : SendHttpRequestBase
 12{
 13    /// <inheritdoc />
 1314    public SendHttpRequest([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, l
 15    {
 1316    }
 17
 18    /// <summary>
 19    /// A list of expected status codes to handle and the corresponding activity to execute when the status code matches
 20    /// </summary>
 21    [Input(
 22        Description = "A list of expected status codes to handle and the corresponding activity to execute when the stat
 23        UIHint = "http-status-codes"
 24    )]
 4725    public ICollection<HttpStatusCodeCase> ExpectedStatusCodes { get; set; } = new List<HttpStatusCodeCase>();
 26
 27    /// <summary>
 28    /// The activity to execute when the HTTP status code does not match any of the expected status codes.
 29    /// </summary>
 30    [Port]
 2431    public IActivity? UnmatchedStatusCode { get; set; }
 32
 33    /// <summary>
 34    /// The activity to execute when the HTTP request fails to connect.
 35    /// </summary>
 36    [Port]
 1537    public IActivity? FailedToConnect { get; set; }
 38
 39    /// <summary>
 40    /// The activity to execute when the HTTP request times out.
 41    /// </summary>
 42    [Port]
 1543    public IActivity? Timeout { get; set; }
 44
 45    /// <inheritdoc />
 46    protected override async ValueTask HandleResponseAsync(ActivityExecutionContext context, HttpResponseMessage respons
 47    {
 1048        var expectedStatusCodes = ExpectedStatusCodes;
 1049        var statusCode = (int)response.StatusCode;
 1550        var matchingCase = expectedStatusCodes.FirstOrDefault(x => x.StatusCode == statusCode);
 1051        var activity = matchingCase != null ? matchingCase.Activity : UnmatchedStatusCode;
 52
 1053        await context.ScheduleActivityAsync(activity, OnChildActivityCompletedAsync);
 1054    }
 55
 56    /// <inheritdoc />
 57    protected override async ValueTask HandleRequestExceptionAsync(ActivityExecutionContext context, HttpRequestExceptio
 58    {
 159        await context.ScheduleActivityAsync(FailedToConnect, OnChildActivityCompletedAsync);
 160    }
 61
 62    /// <inheritdoc />
 63    protected override async ValueTask HandleTaskCanceledExceptionAsync(ActivityExecutionContext context, TaskCanceledEx
 64    {
 165        await context.ScheduleActivityAsync(Timeout, OnChildActivityCompletedAsync);
 166    }
 67
 68    private async ValueTask OnChildActivityCompletedAsync(ActivityCompletedContext context)
 69    {
 070        await context.TargetContext.CompleteActivityAsync();
 071    }
 72}