< 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>
 518818    public string? BookmarkId { get; set; }
 19
 20    /// <summary>
 21    /// Gets or sets the IDs of the bookmark.
 22    /// </summary>
 379523    public ICollection<string>? BookmarkIds { get; set; }
 24
 25    /// <summary>
 26    /// Gets or sets the IDs of the workflow instance.
 27    /// </summary>
 692128    public string? WorkflowInstanceId { get; set; }
 29
 30    /// <summary>
 31    /// Gets or sets the IDs of the workflow instances.
 32    /// </summary>
 356933    public ICollection<string>? WorkflowInstanceIds { get; set; }
 34
 35    /// <summary>
 36    /// Gets or sets the hash of the bookmark to find.
 37    /// </summary>
 684838    public string? Hash { get; set; }
 39
 40    /// <summary>
 41    /// Gets or sets the hashes of the bookmarks to find.
 42    /// </summary>
 353043    public ICollection<string>? Hashes { get; set; }
 44
 45    /// <summary>
 46    /// Gets or sets the correlation ID of the bookmark to find.
 47    /// </summary>
 530248    public string? CorrelationId { get; set; }
 49
 50    /// <summary>
 51    /// Gets or sets the name of the bookmark to find.
 52    /// </summary>
 672153    public string? Name { get; set; }
 54
 55    /// <summary>
 56    /// Gets or sets the names of the bookmarks to find.
 57    /// </summary>
 355858    public ICollection<string>? Names { get; set; }
 59
 60    /// <summary>
 61    /// Gets or sets the activity instance ID of the bookmark to find.
 62    /// </summary>
 518463    public string? ActivityInstanceId { get; set; }
 64
 65    /// <summary>
 66    /// Get or sets if the triggers to find is a tenant agnostic search
 67    /// </summary>
 344368    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    {
 187675        var filter = this;
 187976        if (filter.BookmarkId != null) query = query.Where(x => x.Id == filter.BookmarkId);
 202177        if (filter.BookmarkIds != null) query = query.Where(x => filter.BookmarkIds.Contains(x.Id));
 198778        if (filter.CorrelationId != null) query = query.Where(x => x.CorrelationId == filter.CorrelationId);
 353479        if (filter.Hash != null) query = query.Where(x => x.Hash == filter.Hash);
 187680        if (filter.Hashes != null) query = query.Where(x => filter.Hashes.Contains(x.Hash));
 353281        if (filter.WorkflowInstanceId != null) query = query.Where(x => x.WorkflowInstanceId == filter.WorkflowInstanceI
 190282        if (filter.WorkflowInstanceIds != null) query = query.Where(x => filter.WorkflowInstanceIds.Contains(x.WorkflowI
 341583        if (filter.Name != null) query = query.Where(x => x.Name == filter.Name);
 189084        if (filter.Names != null) query = query.Where(x => filter.Names.Contains(x.Name!));
 187685        if (filter.ActivityInstanceId != null) query = query.Where(x => x.ActivityInstanceId == filter.ActivityInstanceI
 86
 187687        return query;
 88    }
 89
 790    public static BookmarkFilter ByActivityTypeNames(IEnumerable<string> activityTypeNames) => new()
 791    {
 792        Names = activityTypeNames.ToList()
 793    };
 94
 95    public string GetHashableString()
 96    {
 97        // Return a hashable string representation of the filter, excluding null values.
 165498        var sb = new StringBuilder();
 3969699        foreach (var prop in CachedProperties)
 100        {
 18194101            var value = prop.GetValue(this);
 18194102            if (value == null)
 103                continue;
 104
 105            string valueString;
 106            // Handle collections (excluding string)
 6492107            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            {
 6492120                var toStringResult = value.ToString();
 6492121                if (toStringResult == null)
 122                    continue;
 6492123                valueString = toStringResult;
 124            }
 6492125            sb.Append($"{prop.Name}:{valueString};");
 126        }
 127
 1654128        return sb.ToString();
 129    }
 130}