< Summary

Information
Class: Elsa.Http.Services.RouteTable
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Services/RouteTable.cs
Line coverage
66%
Covered lines: 14
Uncovered lines: 7
Coverable lines: 21
Total lines: 59
Line coverage: 66.6%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.cctor()100%11100%
get_Routes()100%11100%
Add(...)100%210%
Add(...)50%2271.42%
Remove(...)100%11100%
AddRange(...)0%620%
RemoveRange(...)100%22100%
GetEnumerator()100%11100%
System.Collections.IEnumerable.GetEnumerator()100%210%

File(s)

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

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Concurrent;
 3using Elsa.Extensions;
 4using Microsoft.Extensions.Caching.Memory;
 5using Microsoft.Extensions.Logging;
 6
 7namespace Elsa.Http.Services;
 8
 9/// <inheritdoc />
 32910public class RouteTable(IMemoryCache cache, ILogger<RouteTable> logger) : IRouteTable
 11{
 212    private static readonly object Key = new();
 13
 52114    private ConcurrentDictionary<string, HttpRouteData> Routes => cache.GetOrCreate(Key, _ => new ConcurrentDictionary<s
 15
 16    /// <inheritdoc />
 17    public void Add(string route)
 18    {
 019        Add(new HttpRouteData(route));
 020    }
 21
 22    /// <inheritdoc />
 23    public void Add(HttpRouteData httpRouteData)
 24    {
 6225        var route = httpRouteData.Route;
 6226        if (route.Contains("//"))
 27        {
 028            logger.LogWarning("Path cannot contain double slashes. Ignoring path: {Path}", route);
 029            return;
 30        }
 31
 6232        var normalizedRoute = route.NormalizeRoute();
 6233        Routes.TryAdd(normalizedRoute, httpRouteData);
 6234    }
 35
 36    /// <inheritdoc />
 37    public void Remove(string route)
 38    {
 639        var normalizedRoute = route.NormalizeRoute();
 640        Routes.TryRemove(normalizedRoute, out _);
 641    }
 42
 43    /// <inheritdoc />
 44    public void AddRange(IEnumerable<string> routes)
 45    {
 046        foreach (var route in routes) Add(route);
 047    }
 48
 49    /// <inheritdoc />
 50    public void RemoveRange(IEnumerable<string> routes)
 51    {
 165252        foreach (var route in routes) Remove(route);
 81753    }
 54
 55    /// <inheritdoc />
 45056    public IEnumerator<HttpRouteData> GetEnumerator() => Routes.Values.GetEnumerator();
 57
 058    IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
 59}