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

Information
Line coverage
93%
Covered lines: 27
Uncovered lines: 2
Coverable lines: 29
Total lines: 100
Line coverage: 93.1%
Branch coverage
75%
Covered branches: 9
Total branches: 12
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
MigrateAsync(...)100%11100%
Migrate()100%11100%
MigrateToAsync(...)100%11100%
MigrateTo(...)100%1150%
MigrateDownAsync(...)100%11100%
MigrateDown(...)100%11100%
MigrateDownToAsync(...)100%11100%
MigrateDownTo(...)100%1150%
PlanRollbackAsync(...)100%11100%
PlanRollback(...)100%11100%
GetMigrationsAsync(...)100%11100%
GetMigrations()100%11100%
Dispose()66.66%66100%
DisposeAsync()83.33%66100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder/Running/SeedMigrator.cs

#LineLine coverage
 1namespace ZhEaIsNsAaBn.DbSeeder;
 2
 3/// <summary>
 4/// The standalone runner: takes the database seed lock, then applies. Works on a context from <see cref="IDbContextFact
 5/// (owned and disposed here) when one is registered, otherwise on the scoped context.
 6/// </summary>
 7internal sealed class SeedMigrator< TDbContext > : ISeedMigrator<TDbContext>, IDisposable, IAsyncDisposable
 8    where TDbContext : DbContext
 9{
 10    private readonly SeedConfiguration                  _configuration;
 11    private readonly ISeedDatabaseProvider              _provider;
 12    private readonly Lazy<(TDbContext Context, bool Owned)> _context;
 13
 14
 17415    public SeedMigrator( SeedConfiguration configuration, ISeedDatabaseProvider provider, Func<(TDbContext Context, bool
 16    {
 17417        _configuration = configuration;
 17418        _provider      = provider;
 17419        _context       = new Lazy<(TDbContext, bool)>( contextFactory );
 17420    }
 21
 22
 23    public Task<LayerResponse<SeedRunResult>> MigrateAsync( CancellationToken cancellationToken = default )
 6824        => SeedEngine.UpAsync( _context.Value.Context, _configuration, _provider, null, takeLock: true, async: true, can
 25
 26    public LayerResponse<SeedRunResult> Migrate()
 1327        => SyncPath.Result( SeedEngine.UpAsync( _context.Value.Context, _configuration, _provider, null, takeLock: true,
 28
 29    public Task<LayerResponse<SeedRunResult>> MigrateToAsync( string targetMigrationId, CancellationToken cancellationTo
 30    {
 6031        ArgumentException.ThrowIfNullOrWhiteSpace( targetMigrationId );
 32
 6033        return SeedEngine.UpAsync( _context.Value.Context, _configuration, _provider, targetMigrationId, takeLock: true,
 34    }
 35
 36    public LayerResponse<SeedRunResult> MigrateTo( string targetMigrationId )
 37    {
 338        ArgumentException.ThrowIfNullOrWhiteSpace( targetMigrationId );
 39
 040        return SyncPath.Result( SeedEngine.UpAsync( _context.Value.Context, _configuration, _provider, targetMigrationId
 41    }
 42
 43    public Task<LayerResponse<SeedRunResult>> MigrateDownAsync( int steps, SeedDeleteMode? deleteMode = null, Cancellati
 44    {
 2545        ArgumentOutOfRangeException.ThrowIfLessThan( steps, 1 );
 46
 2247        return SeedRollback.DownAsync( _context.Value.Context, _configuration, _provider, steps, null, deleteMode, async
 48    }
 49
 50    public LayerResponse<SeedRunResult> MigrateDown( int steps, SeedDeleteMode? deleteMode = null )
 51    {
 452        ArgumentOutOfRangeException.ThrowIfLessThan( steps, 1 );
 53
 454        return SyncPath.Result( SeedRollback.DownAsync( _context.Value.Context, _configuration, _provider, steps, null, 
 55    }
 56
 57    public Task<LayerResponse<SeedRunResult>> MigrateDownToAsync( string targetMigrationId, SeedDeleteMode? deleteMode =
 58    {
 859        ArgumentException.ThrowIfNullOrWhiteSpace( targetMigrationId );
 60
 861        return SeedRollback.DownAsync( _context.Value.Context, _configuration, _provider, null, targetMigrationId, delet
 62    }
 63
 64    public LayerResponse<SeedRunResult> MigrateDownTo( string targetMigrationId, SeedDeleteMode? deleteMode = null )
 65    {
 366        ArgumentException.ThrowIfNullOrWhiteSpace( targetMigrationId );
 67
 068        return SyncPath.Result( SeedRollback.DownAsync( _context.Value.Context, _configuration, _provider, null, targetM
 69    }
 70
 71    public Task<LayerResponse<SeedRollbackPlan>> PlanRollbackAsync( int steps, SeedDeleteMode? deleteMode = null, Cancel
 72    {
 473        ArgumentOutOfRangeException.ThrowIfLessThan( steps, 1 );
 74
 475        return SeedRollback.PlanAsync( _context.Value.Context, _configuration, _provider, steps, null, deleteMode, async
 76    }
 77
 78    public LayerResponse<SeedRollbackPlan> PlanRollback( int steps, SeedDeleteMode? deleteMode = null )
 79    {
 780        ArgumentOutOfRangeException.ThrowIfLessThan( steps, 1 );
 81
 482        return SyncPath.Result( SeedRollback.PlanAsync( _context.Value.Context, _configuration, _provider, steps, null, 
 83    }
 84
 85    public Task<LayerResponse<IReadOnlyList<SeedMigrationInfo>>> GetMigrationsAsync( CancellationToken cancellationToken
 386        => SeedEngine.ListAsync( _context.Value.Context, _configuration, _provider, async: true, cancellationToken );
 87
 88    public LayerResponse<IReadOnlyList<SeedMigrationInfo>> GetMigrations()
 389        => SyncPath.Result( SeedEngine.ListAsync( _context.Value.Context, _configuration, _provider, async: false, Cance
 90
 91    public void Dispose()
 92    {
 693        if ( _context is { IsValueCreated: true, Value.Owned: true } ) { _context.Value.Context.Dispose(); }
 694    }
 95
 96    public async ValueTask DisposeAsync()
 97    {
 3698        if ( _context is { IsValueCreated: true, Value.Owned: true } ) { await _context.Value.Context.DisposeAsync().Con
 3699    }
 100}