< Summary - ZhEaIsNsAaBn.Libraries coverage (affected: 23 packages)

Information
Class: ZhEaIsNsAaBn.Infrastructure.Specifications.BaseSpecificationRepository<T1, T2>
Assembly: ZhEaIsNsAaBn.Infrastructure.Specifications
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.Infrastructure.Specifications/Repositories/BaseSpecificationRepository.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 2
Coverable lines: 2
Total lines: 122
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
.ctor(...)100%210%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.Infrastructure.Specifications/Repositories/BaseSpecificationRepository.cs

#LineLine coverage
 1using Ardalis.Specification.EntityFrameworkCore;
 2
 3namespace ZhEaIsNsAaBn.Infrastructure.Specifications;
 4
 5/// <summary><see cref="BaseSpecificationRepository{TDbContext, TEntity, TId}"/> for <see cref="int"/>-keyed entities.</
 6/// <typeparam name="TDbContext">The application's context.</typeparam>
 7/// <typeparam name="TEntity">The entity type.</typeparam>
 8public abstract class BaseSpecificationRepository< TDbContext, TEntity > : BaseSpecificationRepository<TDbContext, TEnti
 9    where TDbContext : DbContext
 10    where TEntity : class, IBaseEntity
 11{
 12    /// <inheritdoc />
 013    protected BaseSpecificationRepository( IDbContextProvider<TDbContext> dbContextProvider ) : base( dbContextProvider 
 14
 15    /// <inheritdoc />
 16    protected BaseSpecificationRepository( IDbContextProvider<TDbContext> dbContextProvider, ISpecificationEvaluator spe
 017        : base( dbContextProvider, specificationEvaluator ) { }
 18}
 19
 20/// <summary>Core <see cref="BaseRepository{TDbContext, TEntity, TId}"/> plus helpers that apply a specification.</summa
 21/// <typeparam name="TDbContext">The application's context.</typeparam>
 22/// <typeparam name="TEntity">The entity type.</typeparam>
 23/// <typeparam name="TId">The key type.</typeparam>
 24public abstract class BaseSpecificationRepository< TDbContext, TEntity, TId > : BaseRepository<TDbContext, TEntity, TId>
 25    where TDbContext : DbContext
 26    where TEntity : class, IBaseEntity<TId>
 27    where TId : struct, IEquatable<TId>
 28{
 29    /// <summary>Creates the repository with Ardalis' default evaluator.</summary>
 30    /// <param name="dbContextProvider">The context provider.</param>
 31    protected BaseSpecificationRepository( IDbContextProvider<TDbContext> dbContextProvider ) : this( dbContextProvider,
 32
 33    /// <summary>Creates the repository.</summary>
 34    /// <param name="dbContextProvider">The context provider.</param>
 35    /// <param name="specificationEvaluator">The specification evaluator.</param>
 36    /// <exception cref="ArgumentNullException"><paramref name="specificationEvaluator"/> is <see langword="null"/>.</ex
 37    protected BaseSpecificationRepository( IDbContextProvider<TDbContext> dbContextProvider, ISpecificationEvaluator spe
 38    {
 39        ArgumentNullException.ThrowIfNull( specificationEvaluator );
 40
 41        SpecificationEvaluator = specificationEvaluator;
 42    }
 43
 44
 45    /// <summary>The specification evaluator.</summary>
 46    protected ISpecificationEvaluator SpecificationEvaluator { get; }
 47
 48    /// <summary>The shared context's error classifier (from its provider package); <see langword="null"/> when it has n
 49    protected IDbErrorClassifier? ErrorClassifier => GetDbContext().GetDbErrorClassifier();
 50
 51
 52    /// <summary>The shared context's rows matching <paramref name="specification"/>.</summary>
 53    /// <param name="specification">The specification.</param>
 54    /// <param name="evaluateCriteriaOnly"><see langword="true"/> to apply only the criteria.</param>
 55    /// <returns>The query, or <see langword="null"/> when the specification is invalid.</returns>
 56    protected IQueryable<TEntity>? ApplySpecification( BaseSpecification<TEntity> specification, bool evaluateCriteriaOn
 57    {
 58        ArgumentNullException.ThrowIfNull( specification );
 59
 60        return specification.IsValid.IsSuccess ? SpecificationEvaluator.GetQuery( GetDbContext().Set<TEntity>().AsQuerya
 61    }
 62
 63    /// <summary>Async version of <see cref="ApplySpecification(BaseSpecification{TEntity}, bool)"/>.</summary>
 64    /// <param name="specification">The specification.</param>
 65    /// <param name="evaluateCriteriaOnly"><see langword="true"/> to apply only the criteria.</param>
 66    /// <param name="cancellationToken">Token to cancel waiting for the context.</param>
 67    /// <returns>The query, or <see langword="null"/> when the specification is invalid.</returns>
 68    protected async Task<IQueryable<TEntity>?> ApplySpecificationAsync(
 69            BaseSpecification<TEntity> specification, bool evaluateCriteriaOnly = false, CancellationToken cancellationT
 70        )
 71    {
 72        ArgumentNullException.ThrowIfNull( specification );
 73
 74        if ( !specification.IsValid.IsSuccess ) { return null; }
 75
 76
 77        var context = await GetDbContextAsync( cancellationToken ).ConfigureAwait( false );
 78
 79
 80        return SpecificationEvaluator.GetQuery( context.Set<TEntity>().AsQueryable(), specification, evaluateCriteriaOnl
 81    }
 82
 83    /// <summary>The shared context's rows matching <paramref name="specification"/>, projected by its <c>Query.Select</
 84    /// <typeparam name="TResult">The read model.</typeparam>
 85    /// <param name="specification">The specification.</param>
 86    /// <param name="cancellationToken">Token to cancel waiting for the context.</param>
 87    /// <returns>The query; the specification's failure; or <see cref="Error.Unknown"/> when the query can't be built (e
 88    protected async Task<LayerResponse<IQueryable<TResult>>> ApplySpecificationAsync< TResult >( BaseSpecification<TEnti
 89    {
 90        ArgumentNullException.ThrowIfNull( specification );
 91
 92        if ( specification.IsValid.IsFailure ) { return LayerResponse<IQueryable<TResult>>.Failure( specification.IsVali
 93
 94
 95        var context = await GetDbContextAsync( cancellationToken ).ConfigureAwait( false );
 96
 97
 98        return SafeExecution.ExecuteSafe( () => SpecificationEvaluator.GetQuery( context.Set<TEntity>().AsQueryable(), s
 99    }
 100
 101    /// <summary>The shared context's rows matching <paramref name="specification"/>, projected by <paramref name="proje
 102    /// <typeparam name="TResult">The read model.</typeparam>
 103    /// <param name="specification">The specification.</param>
 104    /// <param name="project">Turns the filtered query into the read model.</param>
 105    /// <param name="cancellationToken">Token to cancel waiting for the context.</param>
 106    /// <returns>The query; the specification's failure; or <see cref="Error.Unknown"/> when the query can't be built (e
 107    protected async Task<LayerResponse<IQueryable<TResult>>> ApplySpecificationAsync< TResult >(
 108            BaseSpecification<TEntity> specification, Func<IQueryable<TEntity>, IQueryable<TResult>> project, Cancellati
 109        )
 110    {
 111        ArgumentNullException.ThrowIfNull( specification );
 112        ArgumentNullException.ThrowIfNull( project );
 113
 114        if ( specification.IsValid.IsFailure ) { return LayerResponse<IQueryable<TResult>>.Failure( specification.IsVali
 115
 116
 117        var context = await GetDbContextAsync( cancellationToken ).ConfigureAwait( false );
 118
 119
 120        return SafeExecution.ExecuteSafe( () => project( SpecificationEvaluator.GetQuery( context.Set<TEntity>().AsQuery
 121    }
 122}