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

Information
Class: Microsoft.EntityFrameworkCore.AuditingOptionsExtensions
Assembly: ZhEaIsNsAaBn.Infrastructure.Core
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.Infrastructure.Core/Auditing/AuditingOptionsExtensions.cs
Line coverage
81%
Covered lines: 9
Uncovered lines: 2
Coverable lines: 11
Total lines: 64
Line coverage: 81.8%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
UseAuditing(...)100%210%
UseSoftDeleteFilter(...)50%22100%
AuditOptionsFrom(...)100%11100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.Infrastructure.Core/Auditing/AuditingOptionsExtensions.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore.Infrastructure;
 2using ZhEaIsNsAaBn.Infrastructure.Core;
 3
 4// ReSharper disable once CheckNamespace
 5namespace Microsoft.EntityFrameworkCore;
 6
 7/// <summary>Auditing and the soft-delete filter for contexts registered without the Core builder.</summary>
 8public static class AuditingOptionsExtensions
 9{
 10    /// <summary>
 11    /// Adds an <see cref="AuditInterceptor{TId}"/> to this context. With the Core builder use <c>WithAuditing&lt;TId&gt
 12    /// which takes the user provider from DI.
 13    /// </summary>
 14    /// <typeparam name="TId">The user key type.</typeparam>
 15    /// <param name="optionsBuilder">The context options builder.</param>
 16    /// <param name="configure">Sets the system user (required), hard-delete types and the clock.</param>
 17    /// <param name="currentUser">The current user (singleton / ambient); <see langword="null"/> always stamps the syste
 18    /// <returns>The same builder.</returns>
 19    /// <exception cref="ArgumentNullException"><paramref name="optionsBuilder"/> or <paramref name="configure"/> is <se
 20    /// <exception cref="InvalidOperationException"><paramref name="configure"/> didn't set a system user.</exception>
 21    /// <example><code>options.UseSqlServer( cs ).UseAuditing&lt;int&gt;( o =&gt; o.SystemUser( 1, "system" ), currentUs
 22    public static DbContextOptionsBuilder UseAuditing< TId >( this DbContextOptionsBuilder optionsBuilder, Action<AuditO
 23        where TId : struct, IEquatable<TId>
 24    {
 025        ArgumentNullException.ThrowIfNull( optionsBuilder );
 26
 027        return optionsBuilder.AddInterceptors( new AuditInterceptor<TId>( AuditOptionsFrom( configure ), currentUser ) )
 28    }
 29
 30    /// <summary>
 31    /// Hides soft-deleted rows: every root entity with a soft-delete flag (<c>IDeletableEntity</c> or <c>[SoftDeleteFla
 32    /// filter <c>!flag</c>, joined with any filter it already has. <c>IgnoreQueryFilters()</c> shows them again. With t
 33    /// <c>WithSoftDeleteFilter()</c>.
 34    /// </summary>
 35    /// <param name="optionsBuilder">The context options builder.</param>
 36    /// <returns>The same builder.</returns>
 37    /// <exception cref="ArgumentNullException"><paramref name="optionsBuilder"/> is <see langword="null"/>.</exception>
 38    public static DbContextOptionsBuilder UseSoftDeleteFilter( this DbContextOptionsBuilder optionsBuilder )
 39    {
 440        ArgumentNullException.ThrowIfNull( optionsBuilder );
 41
 442        var extension = optionsBuilder.Options.FindExtension<SoftDeleteFilterOptionsExtension>() ?? new SoftDeleteFilter
 43
 444        ( (IDbContextOptionsBuilderInfrastructure) optionsBuilder ).AddOrUpdateExtension( extension );
 45
 46
 447        return optionsBuilder;
 48    }
 49
 50
 51    /// <summary>Runs <paramref name="configure"/> on new options and checks them.</summary>
 52    internal static AuditOptions<TId> AuditOptionsFrom< TId >( Action<AuditOptions<TId>> configure )
 53        where TId : struct, IEquatable<TId>
 54    {
 2055        ArgumentNullException.ThrowIfNull( configure );
 56
 2057        var options = new AuditOptions<TId>();
 58
 2059        configure( options );
 2060        options.Validate();
 61
 1662        return options;
 63    }
 64}