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

Information
Class: ZhEaIsNsAaBn.Infrastructure.Core.AuditOptions<T>
Assembly: ZhEaIsNsAaBn.Infrastructure.Core
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.Infrastructure.Core/Auditing/AuditOptions.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 68
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_TimeProvider()100%11100%
set_TimeProvider(...)100%11100%
SystemUser(...)100%11100%
HardDelete()100%11100%
IsHardDelete(...)100%11100%
Validate()100%44100%

File(s)

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

#LineLine coverage
 1namespace ZhEaIsNsAaBn.Infrastructure.Core;
 2
 3/// <summary>Settings for <see cref="AuditInterceptor{TId}"/> and the audited bulk operations.</summary>
 4/// <typeparam name="TId">The user key type.</typeparam>
 5public sealed class AuditOptions< TId >
 6    where TId : struct, IEquatable<TId>
 7{
 248    private readonly HashSet<Type> _hardDelete = [];
 249    private          TimeProvider  _timeProvider = TimeProvider.System;
 10
 11
 12    /// <summary>The clock; audit times are <c>TimeProvider.GetLocalNow().DateTime</c>. Default <see cref="TimeProvider.
 13    /// <exception cref="ArgumentNullException">The value is <see langword="null"/>.</exception>
 14    public TimeProvider TimeProvider
 15    {
 18416        get => _timeProvider;
 17        set
 18        {
 419            ArgumentNullException.ThrowIfNull( value );
 20
 421            _timeProvider = value;
 422        }
 23    }
 24
 25    internal TId?    SystemUserId   { get; private set; }
 26    internal string? SystemUserName { get; private set; }
 27
 28
 29    /// <summary>The user stamped when <see cref="ICurrentUserProvider{TId}"/> has no user (or none is registered). Requ
 30    /// <param name="id">The system user's key.</param>
 31    /// <param name="name">The system user's name.</param>
 32    /// <returns>These options.</returns>
 33    /// <exception cref="ArgumentException"><paramref name="name"/> is <see langword="null"/>, empty or white space.</ex
 34    public AuditOptions<TId> SystemUser( TId id, string name )
 35    {
 2036        ArgumentException.ThrowIfNullOrWhiteSpace( name );
 37
 1638        SystemUserId   = id;
 1639        SystemUserName = name;
 40
 1641        return this;
 42    }
 43
 44    /// <summary>
 45    /// Deletes <typeparamref name="TEntity"/> (and types derived from it) for real even when it has a soft-delete flag
 46    /// (<c>IDeletableEntity</c> or <c>[SoftDeleteFlag]</c>).
 47    /// </summary>
 48    /// <typeparam name="TEntity">The entity type.</typeparam>
 49    /// <returns>These options.</returns>
 50    public AuditOptions<TId> HardDelete< TEntity >()
 51        where TEntity : class
 52    {
 853        _hardDelete.Add( typeof( TEntity ) );
 54
 855        return this;
 56    }
 57
 58
 4859    internal bool IsHardDelete( Type entityType ) => _hardDelete.Any( type => type.IsAssignableFrom( entityType ) );
 60
 61    internal void Validate()
 62    {
 3263        if ( SystemUserId is null || SystemUserName is null )
 64        {
 465            throw new InvalidOperationException( "Auditing needs a system user for saves without a current user: call o.
 66        }
 2867    }
 68}