< Summary - Code Coverage

Information
Class: Plainquire.Filter.ValueFilterExpressions.GuidFilterExpression
Assembly: Plainquire.Filter
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Filter/Plainquire.Filter/ValueFilterExpressions/GuidFilterExpression.cs
Tag: 64_13932151703
Line coverage
95%
Covered lines: 40
Uncovered lines: 2
Coverable lines: 42
Total lines: 120
Line coverage: 95.2%
Branch coverage
73%
Covered branches: 22
Total branches: 30
Branch coverage: 73.3%
Method coverage
100%
Covered methods: 7
Total methods: 7
Method coverage: 100%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CanCreateExpressionFor(...)100%11100%
CreateExpressionForValue(...)90%101090.9%
CreateGuidExpressionByFilterOperator(...)87.5%8875%
CreateGuidContainsExpression(...)50%44100%
CreateGuidStartsWithExpression(...)50%44100%
CreateGuidEndsWithExpression(...)50%44100%

File(s)

/home/runner/work/plainquire/plainquire/Plainquire.Filter/Plainquire.Filter/ValueFilterExpressions/GuidFilterExpression.cs

#LineLine coverage
 1using Plainquire.Filter.Abstractions;
 2using System;
 3using System.Collections.Generic;
 4using System.Diagnostics.CodeAnalysis;
 5using System.Globalization;
 6using System.Linq.Expressions;
 7
 8namespace Plainquire.Filter.ValueFilterExpressions;
 9
 10/// <inheritdoc cref="IGuidFilterExpression"/>
 11[SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "Provided as library, can be used from outsid
 12public class GuidFilterExpression : DefaultFilterExpression, IGuidFilterExpression
 13{
 14    /// <inheritdoc />
 15    public override ICollection<FilterOperator> SupportedFilterOperators
 16        =>
 93617        [
 93618            FilterOperator.Default,
 93619            FilterOperator.Contains,
 93620            FilterOperator.StartsWith,
 93621            FilterOperator.EndsWith,
 93622            FilterOperator.EqualCaseSensitive,
 93623            FilterOperator.EqualCaseInsensitive,
 93624            FilterOperator.NotEqual,
 93625            FilterOperator.IsNull,
 93626            FilterOperator.NotNull
 93627        ];
 28
 29    /// <inheritdoc />
 30    public override bool CanCreateExpressionFor(Type type)
 2016731        => type.GetUnderlyingType() == typeof(Guid);
 32
 33    /// <inheritdoc />
 34    protected internal override Expression? CreateExpressionForValue<TEntity, TProperty>(Expression<Func<TEntity, TPrope
 35    {
 55236        if (Guid.TryParse(value, out var guidValue))
 36037            return CreateGuidExpressionByFilterOperator(propertySelector, filterOperator, guidValue);
 19238        if (filterOperator == FilterOperator.Contains)
 4839            return CreateGuidContainsExpression(propertySelector, value);
 14440        if (filterOperator == FilterOperator.StartsWith)
 2441            return CreateGuidStartsWithExpression(propertySelector, value);
 12042        if (filterOperator == FilterOperator.EndsWith)
 2443            return CreateGuidEndsWithExpression(propertySelector, value);
 44
 9645        if (configuration.IgnoreParseExceptions)
 046            return null;
 47
 9648        throw CreateFilterExpressionCreationException("Unable to parse given filter value", propertySelector, filterOper
 49    }
 50
 51    private Expression CreateGuidExpressionByFilterOperator<TEntity, TProperty>(Expression<Func<TEntity, TProperty>> pro
 52    {
 53        switch (filterOperator)
 54        {
 55            case FilterOperator.Default:
 56            case FilterOperator.StartsWith:
 57            case FilterOperator.EndsWith:
 58            case FilterOperator.EqualCaseSensitive:
 59            case FilterOperator.EqualCaseInsensitive:
 26460                return CreateEqualExpression(propertySelector, value);
 61            case FilterOperator.NotEqual:
 7262                return CreateNotEqualExpression(propertySelector, value);
 63            case FilterOperator.Contains:
 2464                return CreateGuidContainsExpression(propertySelector, value);
 65            default:
 066                throw CreateFilterExpressionCreationException($"Filter operator '{filterOperator}' not allowed for prope
 67        }
 68    }
 69
 70    /// <summary>
 71    /// Creates unique identifier contains expression.
 72    /// </summary>
 73    /// <typeparam name="TEntity">Type of the entity.</typeparam>
 74    /// <typeparam name="TProperty">Type of the property.</typeparam>
 75    /// <param name="propertySelector">The property selector.</param>
 76    /// <param name="value">The value to check for.</param>
 77    /// <returns>
 78    /// The new unique identifier contains expression.
 79    /// </returns>
 80    public static Expression CreateGuidContainsExpression<TEntity, TProperty>(Expression<Func<TEntity, TProperty>> prope
 81    {
 7282        var valueToUpper = Expression.Constant(value?.ToString()?.ToUpper(CultureInfo.InvariantCulture), typeof(string))
 7283        var propertyToString = propertySelector.Body.ObjectToString();
 7284        var propertyToUpper = propertyToString.StringToUpper();
 7285        var propertyContainsValue = propertyToUpper.StringContains(valueToUpper);
 7286        return propertyContainsValue;
 87    }
 88
 89    /// <summary>
 90    /// Creates unique identifier starts with expression.
 91    /// </summary>
 92    /// <typeparam name="TEntity">Type of the entity.</typeparam>
 93    /// <typeparam name="TProperty">Type of the property.</typeparam>
 94    /// <param name="propertySelector">The property selector.</param>
 95    /// <param name="value">The value to check for.</param>
 96    public static Expression CreateGuidStartsWithExpression<TEntity, TProperty>(Expression<Func<TEntity, TProperty>> pro
 97    {
 2498        var valueToUpper = Expression.Constant(value?.ToString()?.ToUpper(CultureInfo.InvariantCulture), typeof(string))
 2499        var propertyToString = propertySelector.Body.ObjectToString();
 24100        var propertyToUpper = propertyToString.StringToUpper();
 24101        var propertyStartsWithValue = propertyToUpper.StringStartsWith(valueToUpper);
 24102        return propertyStartsWithValue;
 103    }
 104
 105    /// <summary>
 106    /// Creates unique identifier ends with expression.
 107    /// </summary>
 108    /// <typeparam name="TEntity">Type of the entity.</typeparam>
 109    /// <typeparam name="TProperty">Type of the property.</typeparam>
 110    /// <param name="propertySelector">The property selector.</param>
 111    /// <param name="value">The value to check for.</param>
 112    public static Expression CreateGuidEndsWithExpression<TEntity, TProperty>(Expression<Func<TEntity, TProperty>> prope
 113    {
 24114        var valueToUpper = Expression.Constant(value?.ToString()?.ToUpper(CultureInfo.InvariantCulture), typeof(string))
 24115        var propertyToString = propertySelector.Body.ObjectToString();
 24116        var propertyToUpper = propertyToString.StringToUpper();
 24117        var propertyEndsWithValue = propertyToUpper.StringEndsWith(valueToUpper);
 24118        return propertyEndsWithValue;
 119    }
 120}