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

Information
Class: ZhEaIsNsAaBn.DbSeeder.Registrations.DbSeederBuilder<T>
Assembly: ZhEaIsNsAaBn.DbSeeder
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder/Registrations/DbSeederBuilder.cs
Line coverage
100%
Covered lines: 25
Uncovered lines: 0
Coverable lines: 25
Total lines: 74
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
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%
FromAssembly(...)100%11100%
Configure(...)100%11100%
UseProvider(...)100%11100%
Build()100%1010100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder/Registrations/DbSeederBuilder.cs

#LineLine coverage
 1namespace ZhEaIsNsAaBn.DbSeeder.Registrations;
 2
 3/// <summary>Records one context's seed settings and registers them in <see cref="Build"/>.</summary>
 4internal sealed class DbSeederBuilder< TDbContext > : IDbSeederBuilder<TDbContext>
 5    where TDbContext : DbContext
 6{
 7    private readonly IServiceCollection                              _services;
 5968    private readonly List<Action<SeedOptions>>                       _configure = [];
 9    private          Assembly?                                       _assembly;
 10    private          Func<IServiceProvider, ISeedDatabaseProvider>? _providerFactory;
 11    private          bool                                            _built;
 12
 13
 119214    internal DbSeederBuilder( IServiceCollection services ) => _services = services;
 15
 16
 17    public IDbSeederBuilder<TDbContext> FromAssembly( Assembly assembly )
 18    {
 59319        ArgumentNullException.ThrowIfNull( assembly );
 20
 59321        _assembly = assembly;
 22
 59323        return this;
 24    }
 25
 26    public IDbSeederBuilder<TDbContext> Configure( Action<SeedOptions> configure )
 27    {
 58128        ArgumentNullException.ThrowIfNull( configure );
 29
 58130        _configure.Add( configure );
 31
 58132        return this;
 33    }
 34
 35    public IDbSeederBuilder<TDbContext> UseProvider( Func<IServiceProvider, ISeedDatabaseProvider> providerFactory )
 36    {
 59337        ArgumentNullException.ThrowIfNull( providerFactory );
 38
 59339        _providerFactory = providerFactory;
 40
 59341        return this;
 42    }
 43
 44    public IServiceCollection Build()
 45    {
 60246        if ( _built ) { throw new InvalidOperationException( $"AddDbSeeder<{typeof( TDbContext ).Name}>().Build() was al
 47
 59948        if ( _assembly is null ) { throw new InvalidOperationException( $"AddDbSeeder<{typeof( TDbContext ).Name}>() nee
 49
 59650        if ( _providerFactory is null ) { throw new InvalidOperationException( $"AddDbSeeder<{typeof( TDbContext ).Name}
 51
 59052        if ( _services.Any( d => d.ServiceType == typeof( SeedContextRegistration ) && d.ImplementationInstance is SeedC
 53        {
 354            throw new InvalidOperationException( $"AddDbSeeder<{typeof( TDbContext ).Name}>() is registered twice." );
 55        }
 56
 57
 58758        var options = new SeedOptions();
 59
 291760        foreach ( var configure in _configure ) { configure( options ); }
 61
 62
 58763        var configuration = new SeedConfiguration( typeof( TDbContext ), _assembly, options, _providerFactory );
 64
 58165        _services.AddSingleton( new SeedContextRegistration( configuration ) );
 58166        _services.AddScoped<ISeedMigrator<TDbContext>>( serviceProvider => new SeedMigrator<TDbContext>( configuration,
 58167                                                                                                          configuration.
 58168                                                                                                          () => SeedCont
 69
 58170        _built = true;
 71
 58172        return _services;
 73    }
 74}