< Summary

Information
Class: Fluorite.Extensions.StrainerProcessorQueryableExtensions
Assembly: Fluorite.Strainer
File(s): /builds/fluorite/strainer/src/Strainer/Extensions/StrainerProcessorQueryableExtensions.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 191
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Apply(...)100%22100%
ApplyFiltering(...)100%22100%
ApplyPagination(...)100%22100%
ApplySorting(...)100%22100%

File(s)

/builds/fluorite/strainer/src/Strainer/Extensions/StrainerProcessorQueryableExtensions.cs

#LineLine coverage
 1using Fluorite.Strainer.Models;
 2using Fluorite.Strainer.Services;
 3
 4namespace Fluorite.Extensions;
 5
 6/// <summary>
 7/// Provides extension methods for appling Strainer processing to <see cref="IQueryable{T}"/>.
 8/// </summary>
 9public static class StrainerProcessorQueryableExtensions
 10{
 11    /// <summary>
 12    /// Processes current <see cref="IQueryable{T}"/> (applies filtering,
 13    /// sorting and pagination) using provided processor and model data.
 14    /// </summary>
 15    /// <typeparam name="T">
 16    /// The type of entity being processed.
 17    /// </typeparam>
 18    /// <param name="source">
 19    /// The current <see cref="IQueryable{T}"/> instance.
 20    /// </param>
 21    /// <param name="strainerModel">
 22    /// The <see cref="IStrainerModel"/> containing i.a. filtering data.
 23    /// </param>
 24    /// <param name="strainerProcessor">
 25    /// The see <see cref="IStrainerProcessor"/> which will apply filtering.
 26    /// </param>
 27    /// <param name="applyFiltering">
 28    /// A <see cref="bool"/> value indicating whether provided
 29    /// <see cref="IQueryable{T}"/> should be filtered.
 30    /// </param>
 31    /// <param name="applySorting">
 32    /// A <see cref="bool"/> value indicating whether provided
 33    /// <see cref="IQueryable{T}"/> should be ordered.
 34    /// </param>
 35    /// <param name="applyPagination">
 36    /// A <see cref="bool"/> value indicating whether provided
 37    /// <see cref="IQueryable{T}"/> should be paginated.
 38    /// </param>
 39    /// <returns>
 40    /// An instance of <see cref="IQueryable{T}"/> with filtering applied.
 41    /// </returns>
 42    /// <exception cref="ArgumentNullException">
 43    /// <paramref name="source"/> is <see langword="null"/>.
 44    /// </exception>
 45    /// <exception cref="ArgumentNullException">
 46    /// <paramref name="strainerProcessor"/> is <see langword="null"/>.
 47    /// </exception>
 48    public static IQueryable<T> Apply<T>(
 49        this IQueryable<T> source,
 50        IStrainerModel strainerModel,
 51        IStrainerProcessor strainerProcessor,
 52        bool applyFiltering = true,
 53        bool applySorting = true,
 54        bool applyPagination = true)
 55    {
 256        Guard.Against.Null(source);
 257        Guard.Against.Null(strainerProcessor);
 58
 259        if (strainerModel is null)
 60        {
 161            return source;
 62        }
 63
 164        source = strainerProcessor.Apply(strainerModel, source, applyFiltering, applySorting, applyPagination);
 65
 166        return source;
 67    }
 68
 69    /// <summary>
 70    /// Applies filtering to current <see cref="IQueryable{T}"/> using
 71    /// provided processor and model data.
 72    /// </summary>
 73    /// <typeparam name="T">
 74    /// The type of entity being processed.
 75    /// </typeparam>
 76    /// <param name="source">
 77    /// The current <see cref="IQueryable{T}"/> instance.
 78    /// </param>
 79    /// <param name="strainerModel">
 80    /// The <see cref="IStrainerModel"/> containing i.a. filtering data.
 81    /// </param>
 82    /// <param name="strainerProcessor">
 83    /// The see <see cref="IStrainerProcessor"/> which will apply filtering.
 84    /// </param>
 85    /// <returns>
 86    /// An instance of <see cref="IQueryable{T}"/> with filtering applied.
 87    /// </returns>
 88    /// <exception cref="ArgumentNullException">
 89    /// <paramref name="source"/> is <see langword="null"/>.
 90    /// </exception>
 91    /// <exception cref="ArgumentNullException">
 92    /// <paramref name="strainerProcessor"/> is <see langword="null"/>.
 93    /// </exception>
 94    public static IQueryable<T> ApplyFiltering<T>(
 95        this IQueryable<T> source,
 96        IStrainerModel strainerModel,
 97        IStrainerProcessor strainerProcessor)
 98    {
 299        Guard.Against.Null(source);
 2100        Guard.Against.Null(strainerProcessor);
 101
 2102        if (strainerModel is null)
 103        {
 1104            return source;
 105        }
 106
 1107        return strainerProcessor.ApplyFiltering(strainerModel, source);
 108    }
 109
 110    /// <summary>
 111    /// Applies pagination to current <see cref="IQueryable{T}"/> using
 112    /// provided processor and model data.
 113    /// </summary>
 114    /// <typeparam name="T">
 115    /// The type of entity being processed.
 116    /// </typeparam>
 117    /// <param name="source">
 118    /// The current <see cref="IQueryable{T}"/> instance.
 119    /// </param>
 120    /// <param name="strainerModel">
 121    /// The <see cref="IStrainerModel"/> containing i.a. pagination data.
 122    /// </param>
 123    /// <param name="strainerProcessor">
 124    /// The see <see cref="IStrainerProcessor"/> which will apply pagination.
 125    /// </param>
 126    /// <returns>
 127    /// An instance of <see cref="IQueryable{T}"/> with pagination applied.
 128    /// </returns>
 129    /// <exception cref="ArgumentNullException">
 130    /// <paramref name="source"/> is <see langword="null"/>.
 131    /// </exception>
 132    /// <exception cref="ArgumentNullException">
 133    /// <paramref name="strainerProcessor"/> is <see langword="null"/>.
 134    /// </exception>
 135    public static IQueryable<T> ApplyPagination<T>(
 136        this IQueryable<T> source,
 137        IStrainerModel strainerModel,
 138        IStrainerProcessor strainerProcessor)
 139    {
 2140        Guard.Against.Null(source);
 2141        Guard.Against.Null(strainerProcessor);
 142
 2143        if (strainerModel is null)
 144        {
 1145            return source;
 146        }
 147
 1148        return strainerProcessor.ApplyPagination(strainerModel, source);
 149    }
 150
 151    /// <summary>
 152    /// Applies sorting to current <see cref="IQueryable{T}"/> using
 153    /// provided processor and model data.
 154    /// </summary>
 155    /// <typeparam name="T">
 156    /// The type of entity being processed.
 157    /// </typeparam>
 158    /// <param name="source">
 159    /// The current <see cref="IQueryable{T}"/> instance.
 160    /// </param>
 161    /// <param name="strainerModel">
 162    /// The <see cref="IStrainerModel"/> containing i.a. sorting.
 163    /// </param>
 164    /// <param name="strainerProcessor">
 165    /// The see <see cref="IStrainerProcessor"/> which will apply sorting.
 166    /// </param>
 167    /// <returns>
 168    /// An instance of <see cref="IQueryable{T}"/> with sorting applied.
 169    /// </returns>
 170    /// <exception cref="ArgumentNullException">
 171    /// <paramref name="source"/> is <see langword="null"/>.
 172    /// </exception>
 173    /// <exception cref="ArgumentNullException">
 174    /// <paramref name="strainerProcessor"/> is <see langword="null"/>.
 175    /// </exception>
 176    public static IQueryable<T> ApplySorting<T>(
 177        this IQueryable<T> source,
 178        IStrainerModel strainerModel,
 179        IStrainerProcessor strainerProcessor)
 180    {
 2181        Guard.Against.Null(source);
 2182        Guard.Against.Null(strainerProcessor);
 183
 2184        if (strainerModel is null)
 185        {
 1186            return source;
 187        }
 188
 1189        return strainerProcessor.ApplySorting(strainerModel, source);
 190    }
 191}