< Summary

Information
Class: Elsa.Http.Services.DefaultRouteTableUpdater
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Services/DefaultRouteTableUpdater.cs
Line coverage
96%
Covered lines: 49
Uncovered lines: 2
Coverable lines: 51
Total lines: 110
Line coverage: 96%
Branch coverage
78%
Covered branches: 11
Total branches: 14
Branch coverage: 78.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
UpdateAsync()100%11100%
AddRoutesAsync()100%22100%
AddRoutesAsync()50%2260%
AddRoutesAsync()100%22100%
RemoveRoutes(...)100%11100%
RemoveRoutes(...)100%11100%
AddRoutesAsync()100%22100%
Filter(...)100%22100%
Filter(...)0%22100%
Filter(...)100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Services/DefaultRouteTableUpdater.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Http.Bookmarks;
 3using Elsa.Http.Contexts;
 4using Elsa.Workflows;
 5using Elsa.Workflows.Models;
 6using Elsa.Workflows.Runtime;
 7using Elsa.Workflows.Runtime.Entities;
 8using Elsa.Workflows.Runtime.Filters;
 9
 10namespace Elsa.Http.Services;
 11
 12/// <inheritdoc />
 32313public class DefaultRouteTableUpdater(
 32314    IRouteTable routeTable,
 32315    ITriggerStore triggerStore,
 32316    IBookmarkStore bookmarkStore,
 32317    IHttpEndpointRoutesProvider httpEndpointRoutesProvider)
 18    : IRouteTableUpdater
 19{
 20    /// <inheritdoc />
 21    public async Task UpdateAsync(CancellationToken cancellationToken = default)
 22    {
 123        var stimulusName = HttpStimulusNames.HttpEndpoint;
 124        var triggerFilter = new TriggerFilter
 125        {
 126            Name = stimulusName
 127        };
 128        var bookmarkFilter = new BookmarkFilter
 129        {
 130            Name = stimulusName
 131        };
 132        var triggers = (await triggerStore.FindManyAsync(triggerFilter, cancellationToken)).ToList();
 133        var bookmarks = (await bookmarkStore.FindManyAsync(bookmarkFilter, cancellationToken)).ToList();
 34
 135        await AddRoutesAsync(triggers, cancellationToken);
 136        await AddRoutesAsync(bookmarks, cancellationToken);
 137    }
 38
 39    public async Task AddRoutesAsync(IEnumerable<StoredTrigger> triggers, CancellationToken cancellationToken = default)
 40    {
 98541        var httpEndpointTriggers = Filter(triggers).ToList();
 42
 208243        foreach (var trigger in httpEndpointTriggers)
 44        {
 5645            var payload = trigger.GetPayload<HttpEndpointBookmarkPayload>();
 5646            await AddRoutesAsync(payload, trigger.TenantId, cancellationToken);
 47        }
 98548    }
 49
 50    public async Task AddRoutesAsync(IEnumerable<StoredBookmark> bookmarks, CancellationToken cancellationToken = defaul
 51    {
 152        var httpEndpointBookmarks = Filter(bookmarks).ToList();
 53
 254        foreach (var bookmark in httpEndpointBookmarks)
 55        {
 056            var payload = bookmark.GetPayload<HttpEndpointBookmarkPayload>();
 057            await AddRoutesAsync(payload, bookmark.TenantId, cancellationToken);
 58        }
 159    }
 60
 61    public async Task AddRoutesAsync(IEnumerable<Bookmark> bookmarks, WorkflowExecutionContext workflowExecutionContext,
 62    {
 32563        var httpEndpointBookmarks = Filter(bookmarks).ToList();
 64
 66265        foreach (var bookmark in httpEndpointBookmarks)
 66        {
 667            var payload = bookmark.GetPayload<HttpEndpointBookmarkPayload>();
 668            await AddRoutesAsync(payload, workflowExecutionContext.Workflow.Identity.TenantId, cancellationToken);
 69        }
 32570    }
 71
 72    public void RemoveRoutes(IEnumerable<StoredTrigger> triggers)
 73    {
 49674        var paths = Filter(triggers).Select(x => x.GetPayload<HttpEndpointBookmarkPayload>().Path).ToList();
 49275        routeTable.RemoveRange(paths);
 49276    }
 77
 78    public void RemoveRoutes(IEnumerable<Bookmark> bookmarks)
 79    {
 32780        var paths = Filter(bookmarks).Select(x => x.GetPayload<HttpEndpointBookmarkPayload>().Path).ToList();
 32581        routeTable.RemoveRange(paths);
 32582    }
 83
 84    private async Task AddRoutesAsync(HttpEndpointBookmarkPayload payload, string? tenantId, CancellationToken cancellat
 85    {
 6286        var context = new HttpEndpointRouteProviderContext(payload, tenantId, cancellationToken);
 6287        var routes = await httpEndpointRoutesProvider.GetRoutesAsync(context);
 88
 24889        foreach (var route in routes)
 6290            routeTable.Add(route);
 6291    }
 92
 93    private static IEnumerable<StoredTrigger> Filter(IEnumerable<StoredTrigger> triggers)
 94    {
 147795        var stimulusName = HttpStimulusNames.HttpEndpoint;
 155196        return triggers.Where(x => x.Name == stimulusName && x.Payload != null);
 97    }
 98
 99    private static IEnumerable<StoredBookmark> Filter(IEnumerable<StoredBookmark> bookmarks)
 100    {
 1101        var stimulusName = HttpStimulusNames.HttpEndpoint;
 1102        return bookmarks.Where(x => x.Name == stimulusName && x.Payload != null);
 103    }
 104
 105    private static IEnumerable<Bookmark> Filter(IEnumerable<Bookmark> bookmarks)
 106    {
 650107        var stimulusName = HttpStimulusNames.HttpEndpoint;
 714108        return bookmarks.Where(x => x.Name == stimulusName && x.Payload != null);
 109    }
 110}