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

Information
Class: ZhEaIsNsAaBn.Infrastructure.Specifications.BaseSpecificationRepository<T1, T2, T3>
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
70%
Covered lines: 17
Uncovered lines: 7
Coverable lines: 24
Total lines: 122
Line coverage: 70.8%
Branch coverage
25%
Covered branches: 2
Total branches: 8
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
get_ErrorClassifier()100%11100%
ApplySpecification(...)0%620%
ApplySpecificationAsync()0%620%
ApplySpecificationAsync()50%22100%
ApplySpecificationAsync()50%22100%

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 />
 13    protected BaseSpecificationRepository( IDbContextProvider<TDbContext> dbContextProvider ) : base( dbContextProvider 
 14
 15    /// <inheritdoc />
 16    protected BaseSpecificationRepository( IDbContextProvider<TDbContext> dbContextProvider, ISpecificationEvaluator spe
 17        : 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>
 30431    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
 20037    protected BaseSpecificationRepository( IDbContextProvider<TDbContext> dbContextProvider, ISpecificationEvaluator spe
 38    {
 20039        ArgumentNullException.ThrowIfNull( specificationEvaluator );
 40
 20041        SpecificationEvaluator = specificationEvaluator;
 20042    }
 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
 13249    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    {
 058        ArgumentNullException.ThrowIfNull( specification );
 59
 060        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    {
 072        ArgumentNullException.ThrowIfNull( specification );
 73
 074        if ( !specification.IsValid.IsSuccess ) { return null; }
 75
 76
 077        var context = await GetDbContextAsync( cancellationToken ).ConfigureAwait( false );
 78
 79
 080        return SpecificationEvaluator.GetQuery( context.Set<TEntity>().AsQueryable(), specification, evaluateCriteriaOnl
 081    }
 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    {
 4890        ArgumentNullException.ThrowIfNull( specification );
 91
 4892        if ( specification.IsValid.IsFailure ) { return LayerResponse<IQueryable<TResult>>.Failure( specification.IsVali
 93
 94
 4895        var context = await GetDbContextAsync( cancellationToken ).ConfigureAwait( false );
 96
 97
 4898        return SafeExecution.ExecuteSafe( () => SpecificationEvaluator.GetQuery( context.Set<TEntity>().AsQueryable(), s
 4899    }
 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    {
 48111        ArgumentNullException.ThrowIfNull( specification );
 48112        ArgumentNullException.ThrowIfNull( project );
 113
 48114        if ( specification.IsValid.IsFailure ) { return LayerResponse<IQueryable<TResult>>.Failure( specification.IsVali
 115
 116
 48117        var context = await GetDbContextAsync( cancellationToken ).ConfigureAwait( false );
 118
 119
 48120        return SafeExecution.ExecuteSafe( () => project( SpecificationEvaluator.GetQuery( context.Set<TEntity>().AsQuery
 48121    }
 122}