< Summary

Information
Class: Elsa.Workflows.Runtime.Filters.BookmarkFilter
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Filters/BookmarkFilter.cs
Line coverage
86%
Covered lines: 38
Uncovered lines: 6
Coverable lines: 44
Total lines: 130
Line coverage: 86.3%
Branch coverage
79%
Covered branches: 27
Total branches: 34
Branch coverage: 79.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get_BookmarkId()100%11100%
get_BookmarkIds()100%11100%
get_WorkflowInstanceId()100%11100%
get_WorkflowInstanceIds()100%11100%
get_Hash()100%11100%
get_Hashes()100%11100%
get_CorrelationId()100%11100%
get_Name()100%11100%
get_Names()100%11100%
get_ActivityInstanceId()100%11100%
get_TenantAgnostic()100%11100%
Apply(...)85%2020100%
ByActivityTypeNames(...)100%11100%
GetHashableString()64.28%241462.5%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Filters/BookmarkFilter.cs

#LineLine coverage
 1using System.Collections;
 2using System.Text;
 3using Elsa.Workflows.Runtime.Entities;
 4
 5namespace Elsa.Workflows.Runtime.Filters;
 6
 7/// <summary>
 8/// A filter for bookmarks.
 9/// </summary>
 10public class BookmarkFilter
 11{
 12    // Cache the properties of BookmarkFilter for performance.
 213    private static readonly System.Reflection.PropertyInfo[] CachedProperties = typeof(BookmarkFilter).GetProperties();
 14
 15    /// <summary>
 16    /// Gets or sets the ID of the bookmark.
 17    /// </summary>
 351318    public string? BookmarkId { get; set; }
 19
 20    /// <summary>
 21    /// Gets or sets the IDs of the bookmark.
 22    /// </summary>
 265323    public ICollection<string>? BookmarkIds { get; set; }
 24
 25    /// <summary>
 26    /// Gets or sets the IDs of the workflow instance.
 27    /// </summary>
 471828    public string? WorkflowInstanceId { get; set; }
 29
 30    /// <summary>
 31    /// Gets or sets the IDs of the workflow instances.
 32    /// </summary>
 244233    public ICollection<string>? WorkflowInstanceIds { get; set; }
 34
 35    /// <summary>
 36    /// Gets or sets the hash of the bookmark to find.
 37    /// </summary>
 461738    public string? Hash { get; set; }
 39
 40    /// <summary>
 41    /// Gets or sets the hashes of the bookmarks to find.
 42    /// </summary>
 240343    public ICollection<string>? Hashes { get; set; }
 44
 45    /// <summary>
 46    /// Gets or sets the correlation ID of the bookmark to find.
 47    /// </summary>
 359048    public string? CorrelationId { get; set; }
 49
 50    /// <summary>
 51    /// Gets or sets the name of the bookmark to find.
 52    /// </summary>
 452853    public string? Name { get; set; }
 54
 55    /// <summary>
 56    /// Gets or sets the names of the bookmarks to find.
 57    /// </summary>
 240758    public ICollection<string>? Names { get; set; }
 59
 60    /// <summary>
 61    /// Gets or sets the activity instance ID of the bookmark to find.
 62    /// </summary>
 350963    public string? ActivityInstanceId { get; set; }
 64
 65    /// <summary>
 66    /// Get or sets if the triggers to find is a tenant agnostic search
 67    /// </summary>
 231568    public bool TenantAgnostic { get; set; }
 69
 70    /// <summary>
 71    /// Applies the filter to the specified query.
 72    /// </summary>
 73    public IQueryable<StoredBookmark> Apply(IQueryable<StoredBookmark> query)
 74    {
 129775        var filter = this;
 130076        if (filter.BookmarkId != null) query = query.Where(x => x.Id == filter.BookmarkId);
 143377        if (filter.BookmarkIds != null) query = query.Where(x => filter.BookmarkIds.Contains(x.Id));
 137578        if (filter.CorrelationId != null) query = query.Where(x => x.CorrelationId == filter.CorrelationId);
 240379        if (filter.Hash != null) query = query.Where(x => x.Hash == filter.Hash);
 129780        if (filter.Hashes != null) query = query.Where(x => filter.Hashes.Contains(x.Hash));
 243281        if (filter.WorkflowInstanceId != null) query = query.Where(x => x.WorkflowInstanceId == filter.WorkflowInstanceI
 132382        if (filter.WorkflowInstanceIds != null) query = query.Where(x => filter.WorkflowInstanceIds.Contains(x.WorkflowI
 232183        if (filter.Name != null) query = query.Where(x => x.Name == filter.Name);
 129984        if (filter.Names != null) query = query.Where(x => filter.Names.Contains(x.Name!));
 129785        if (filter.ActivityInstanceId != null) query = query.Where(x => x.ActivityInstanceId == filter.ActivityInstanceI
 86
 129787        return query;
 88    }
 89
 190    public static BookmarkFilter ByActivityTypeNames(IEnumerable<string> activityTypeNames) => new()
 191    {
 192        Names = activityTypeNames.ToList()
 193    };
 94
 95    public string GetHashableString()
 96    {
 97        // Return a hashable string representation of the filter, excluding null values.
 110698        var sb = new StringBuilder();
 2654499        foreach (var prop in CachedProperties)
 100        {
 12166101            var value = prop.GetValue(this);
 12166102            if (value == null)
 103                continue;
 104
 105            string valueString;
 106            // Handle collections (excluding string)
 4339107            if (value is IEnumerable enumerable and not string)
 108            {
 0109                var items = new List<string>();
 0110                foreach (var item in enumerable)
 111                {
 0112                    if (item != null)
 0113                        items.Add(item.ToString()!);
 114                }
 0115                items.Sort(StringComparer.Ordinal);
 0116                valueString = string.Join(",", items);
 117            }
 118            else
 119            {
 4339120                var toStringResult = value.ToString();
 4339121                if (toStringResult == null)
 122                    continue;
 4339123                valueString = toStringResult;
 124            }
 4339125            sb.Append($"{prop.Name}:{valueString};");
 126        }
 127
 1106128        return sb.ToString();
 129    }
 130}