< Summary - Code Coverage

Information
Class: Plainquire.Filter.PropertyFilterExpressions.PropertyFilterExpression
Assembly: Plainquire.Filter
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Filter/Plainquire.Filter/PropertyFilterExpressions/PropertyFilterExpression.cs
Tag: 64_13932151703
Line coverage
96%
Covered lines: 26
Uncovered lines: 1
Coverable lines: 27
Total lines: 99
Line coverage: 96.2%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage
83%
Covered methods: 5
Total methods: 6
Method coverage: 83.3%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
CanCreateFilterFor(...)100%11100%
CreateFilter(...)83.33%66100%
CreateFilter(...)100%11100%
CreateFilter(...)100%11100%
EmptyFilter()100%110%

File(s)

/home/runner/work/plainquire/plainquire/Plainquire.Filter/Plainquire.Filter/PropertyFilterExpressions/PropertyFilterExpression.cs

#LineLine coverage
 1using Plainquire.Filter.Abstractions;
 2using Plainquire.Filter.ValueFilterExpressions;
 3using System;
 4using System.Collections.Generic;
 5using System.Diagnostics.CodeAnalysis;
 6using System.Linq;
 7using System.Linq.Expressions;
 8using System.Reflection;
 9
 10namespace Plainquire.Filter.PropertyFilterExpressions;
 11
 12/// <summary>
 13/// Converter to create lambda filter expressions for a given property and a <see cref="ValueFilter"/>.
 14/// </summary>
 15[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "Provided as library, can be used from outside")]
 16public static class PropertyFilterExpression
 17{
 218    private static readonly IValueFilterExpression _defaultValueFilterExpressionCreator = new DefaultFilterExpression();
 219    private static readonly MethodInfo _createFilterMethod = typeof(PropertyFilterExpression).GetMethods(BindingFlags.St
 20
 221    private static readonly IValueFilterExpression[] _valueFilterExpressionCreators =
 222    [
 223        new StringFilterExpression(),
 224        new GuidFilterExpression(),
 225        new DateTimeFilterExpression(),
 226        new BooleanFilterExpression(),
 227        new NumericFilterExpression(),
 228        new EnumFilterExpression()
 229    ];
 30
 31    /// <summary>
 32    /// Determines whether a property of type <paramref name="propertyType"/> can be filtered.
 33    /// </summary>
 34    /// <param name="propertyType">The type to filter.</param>
 35    public static bool CanCreateFilterFor(Type propertyType)
 1684636        => _valueFilterExpressionCreators.Any(x => x.CanCreateExpressionFor(propertyType));
 37
 38    /// <summary>
 39    /// Creates a lambda expression for the given property and <see cref="ValueFilter"/>.
 40    /// </summary>
 41    /// <typeparam name="TEntity">The type of the entity.</typeparam>
 42    /// <typeparam name="TProperty">The type of the property.</typeparam>
 43    /// <param name="propertySelector">The property selector.</param>
 44    /// <param name="valueFilters">The filters to use.</param>
 45    /// <param name="configuration">The filter configuration to use.</param>
 46    /// <param name="interceptor">An interceptor to manipulate the generated filters.</param>
 47    public static Expression<Func<TEntity, bool>>? CreateFilter<TEntity, TProperty>(Expression<Func<TEntity, TProperty>>
 48    {
 1819449        var valueFilterExpressionCreator = _valueFilterExpressionCreators.FirstOrDefault(x => x.CanCreateExpressionFor<T
 1819450        var propertyExpression = valueFilterExpressionCreator.CreateExpression(propertySelector, valueFilters, configura
 1631451        if (propertyExpression == null)
 20552            return null;
 53
 1610954        var result = propertySelector.CreateLambda<TEntity, TProperty, bool>(propertyExpression);
 1610955        return result;
 56    }
 57
 58    /// <summary>
 59    /// Creates a lambda expression for the given property and <see cref="ValueFilter"/>.
 60    /// </summary>
 61    /// <typeparam name="TEntity">The type of the entity.</typeparam>
 62    /// <param name="propertyType">The type of the property.</param>
 63    /// <param name="propertySelector">The property selector.</param>
 64    /// <param name="valueFilters">The filters to use.</param>
 65    /// <param name="configuration">The filter configuration.</param>
 66    /// <param name="interceptor">An interceptor to manipulate the generated filters.</param>
 67    public static Expression<Func<TEntity, bool>>? CreateFilter<TEntity>(Type propertyType, LambdaExpression propertySel
 68    {
 69        try
 70        {
 1819471            var genericMethod = _createFilterMethod.MakeGenericMethod(typeof(TEntity), propertyType);
 1819472            var propertyExpression = (Expression<Func<TEntity, bool>>?)genericMethod.Invoke(null, [propertySelector, val
 1631473            return propertyExpression;
 74        }
 188075        catch (TargetInvocationException ex) when (ex.InnerException != null)
 76        {
 188077            throw ex.InnerException;
 78        }
 1631479    }
 80
 81    /// <summary>
 82    /// Creates a lambda expression for the given property and <see cref="ValueFilter"/>.
 83    /// </summary>
 84    /// <param name="propertyInfo">The property to filter.</param>
 85    /// <param name="filters">The filters to use.</param>
 86    /// <param name="configuration">The filter configuration.</param>
 87    /// <param name="interceptor">An interceptor to manipulate the generated filters.</param>
 88    public static Expression<Func<TEntity, bool>>? CreateFilter<TEntity>(PropertyInfo propertyInfo, IEnumerable<ValueFil
 89    {
 1818890        var propertySelector = typeof(TEntity).CreatePropertySelector(propertyInfo.Name);
 1818891        return CreateFilter<TEntity>(propertyInfo.PropertyType, propertySelector, filters, configuration, interceptor);
 92    }
 93
 94    /// <summary>
 95    /// Creates no-operation filter.
 96    /// </summary>
 97    public static Expression<Func<TEntity, bool>> EmptyFilter<TEntity>()
 098        => x => true;
 99}