< Summary

Information
Class: Elsa.KeyValues.Models.KeyValueFilter
Assembly: Elsa.KeyValues
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.KeyValues/Models/KeyValueFilter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 10
Coverable lines: 10
Total lines: 41
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_StartsWith()100%210%
get_Key()100%210%
get_Keys()100%210%
Apply(...)0%4260%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.KeyValues/Models/KeyValueFilter.cs

#LineLine coverage
 1using Elsa.KeyValues.Entities;
 2
 3namespace Elsa.KeyValues.Models;
 4
 5public class KeyValueFilter
 6{
 7    /// <summary>
 8    /// Gets or sets whether the <see cref="Key"/> needs to match the beginning of the key found.
 9    /// </summary>
 010    public bool StartsWith { get; set; }
 11
 12    /// <summary>
 13    /// Gets or sets the key to filter for.
 14    /// </summary>
 015    public string? Key { get; set; }
 16
 17    /// <summary>
 18    /// Gets or sets the keys to filter for.
 19    /// </summary>
 020    public ICollection<string>? Keys { get; set; }
 21
 22    /// <summary>
 23    /// Applies the filter to the specified queryable.
 24    /// </summary>
 25    /// <param name="queryable">The queryable.</param>
 26    /// <returns>The filtered queryable.</returns>
 27    public IQueryable<SerializedKeyValuePair> Apply(IQueryable<SerializedKeyValuePair> queryable)
 28    {
 029        var filter = this;
 030        if (filter.Key != null)
 31        {
 032            queryable = StartsWith
 033                ? queryable.Where(x => x.Id.StartsWith(filter.Key))
 034                : queryable.Where(x => x.Id == filter.Key);
 35        }
 36
 037        if (filter.Keys != null) queryable = queryable.Where(x => filter.Keys.Contains(x.Id));
 38
 039        return queryable;
 40    }
 41}