< Summary

Information
Class: Pozitron.QuerySpecification.OrderEvaluator
Assembly: Pozitron.QuerySpecification
File(s): /home/runner/work/QuerySpecification/QuerySpecification/src/QuerySpecification/Evaluators/OrderEvaluator.cs
Tag: 52_11740816328
Line coverage
100%
Covered lines: 31
Uncovered lines: 0
Coverable lines: 31
Total lines: 86
Line coverage: 100%
Branch coverage
100%
Covered branches: 32
Total branches: 32
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor()100%11100%
Evaluate(...)100%1616100%
Evaluate(...)100%1616100%

File(s)

/home/runner/work/QuerySpecification/QuerySpecification/src/QuerySpecification/Evaluators/OrderEvaluator.cs

#LineLine coverage
 1namespace Pozitron.QuerySpecification;
 2
 3/// <summary>
 4/// Represents an evaluator for order expressions.
 5/// </summary>
 6public sealed class OrderEvaluator : IEvaluator, IInMemoryEvaluator
 7{
 8    /// <summary>
 9    /// Gets the singleton instance of the <see cref="OrderEvaluator"/> class.
 10    /// </summary>
 211    public static OrderEvaluator Instance = new();
 412    private OrderEvaluator() { }
 13
 14    /// <inheritdoc/>
 15    public IQueryable<T> Evaluate<T>(IQueryable<T> source, Specification<T> specification) where T : class
 16    {
 6017        IOrderedQueryable<T>? orderedQuery = null;
 18
 63619        foreach (var item in specification.Items)
 20        {
 25821            if (item.Type == ItemType.Order && item.Reference is Expression<Func<T, object?>> expr)
 22            {
 4023                if (item.Bag == (int)OrderType.OrderBy)
 24                {
 2225                    orderedQuery = source.OrderBy(expr);
 26                }
 1827                else if (item.Bag == (int)OrderType.OrderByDescending)
 28                {
 429                    orderedQuery = source.OrderByDescending(expr);
 30                }
 1431                else if (item.Bag == (int)OrderType.ThenBy)
 32                {
 433                    orderedQuery = orderedQuery!.ThenBy(expr);
 34                }
 1035                else if (item.Bag == (int)OrderType.ThenByDescending)
 36                {
 1037                    orderedQuery = orderedQuery!.ThenByDescending(expr);
 38                }
 39            }
 40        }
 41
 6042        if (orderedQuery is not null)
 43        {
 2544            source = orderedQuery;
 45        }
 46
 6047        return source;
 48    }
 49
 50    /// <inheritdoc/>
 51    public IEnumerable<T> Evaluate<T>(IEnumerable<T> source, Specification<T> specification)
 52    {
 1953        var compiledItems = specification.GetCompiledItems();
 1954        IOrderedEnumerable<T>? orderedQuery = null;
 55
 10656        foreach (var item in compiledItems)
 57        {
 3458            if (item.Type == ItemType.Order && item.Reference is Func<T, object?> compiledExpr)
 59            {
 2260                if (item.Bag == (int)OrderType.OrderBy)
 61                {
 1562                    orderedQuery = source.OrderBy(compiledExpr);
 63                }
 764                else if (item.Bag == (int)OrderType.OrderByDescending)
 65                {
 366                    orderedQuery = source.OrderByDescending(compiledExpr);
 67                }
 468                else if (item.Bag == (int)OrderType.ThenBy)
 69                {
 270                    orderedQuery = orderedQuery!.ThenBy(compiledExpr);
 71                }
 272                else if (item.Bag == (int)OrderType.ThenByDescending)
 73                {
 274                    orderedQuery = orderedQuery!.ThenByDescending(compiledExpr);
 75                }
 76            }
 77        }
 78
 1979        if (orderedQuery is not null)
 80        {
 1881            source = orderedQuery;
 82        }
 83
 1984        return source;
 85    }
 86}