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

Information
Class: Microsoft.EntityFrameworkCore.DbSeederDbContextOptionsExtensions
Assembly: ZhEaIsNsAaBn.DbSeeder
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder/Extensions/DbSeederDbContextOptionsExtensions.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 57
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
UseDbSeeder(...)100%11100%
RunAsync(...)50%22100%
Throw(...)100%22100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder/Extensions/DbSeederDbContextOptionsExtensions.cs

#LineLine coverage
 1#region Usings
 2using ZhEaIsNsAaBn.DbSeeder;
 3using ZhEaIsNsAaBn.DbSeeder.Registrations;
 4#endregion
 5
 6// ReSharper disable once CheckNamespace
 7namespace Microsoft.EntityFrameworkCore;
 8
 9/// <summary>Runs the seed migrations from EF's own seeding step.</summary>
 10public static class DbSeederDbContextOptionsExtensions
 11{
 12    /// <summary>
 13    /// Sets <b>both</b> <c>UseSeeding</c> and <c>UseAsyncSeeding</c> (EF tools and migration bundles call the sync one)
 14    /// <c>Database.Migrate[Async]()</c> / <c>EnsureCreated[Async]()</c> apply the pending seed migrations of the contex
 15    /// passes in. No seed lock is taken: EF already holds its migration lock. When EF has a transaction open, every mig
 16    /// The context type must be registered with <c>AddDbSeeder&lt;TDbContext&gt;()…Build()</c>.
 17    /// </summary>
 18    /// <param name="optionsBuilder">The context options.</param>
 19    /// <param name="serviceProvider">The provider from the <c>AddDbContext( ( serviceProvider, options ) =&gt; … )</c> 
 20    /// <returns>The options builder.</returns>
 21    /// <exception cref="ArgumentNullException">An argument is <see langword="null"/>.</exception>
 22    /// <remarks>
 23    /// During seeding: <see cref="DbSeederException"/> (with the errors) when a seed migration fails, so <c>Migrate()</
 24    /// <see cref="InvalidOperationException"/> when the context type has no <c>AddDbSeeder</c> registration.
 25    /// </remarks>
 26    /// <example>
 27    /// <code>
 28    /// services.AddDbContext&lt;AppDbContext&gt;( ( serviceProvider, options ) =&gt;
 29    ///                                          options.UseSqlServer( connectionString )
 30    ///                                                 .UseDbSeeder( serviceProvider ) );
 31    /// </code>
 32    /// </example>
 33    public static DbContextOptionsBuilder UseDbSeeder( this DbContextOptionsBuilder optionsBuilder, IServiceProvider ser
 34    {
 3635        ArgumentNullException.ThrowIfNull( optionsBuilder );
 3636        ArgumentNullException.ThrowIfNull( serviceProvider );
 37
 3638        return optionsBuilder.UseSeeding( ( context, _ ) => Throw( SyncPath.Result( RunAsync( context, serviceProvider, 
 3639                             .UseAsyncSeeding( async ( context, _, cancellationToken ) => Throw( await RunAsync( context
 40    }
 41
 42
 43    private static Task<LayerResponse<SeedRunResult>> RunAsync( DbContext context, IServiceProvider serviceProvider, boo
 44    {
 2445        var registration = serviceProvider.GetServices<SeedContextRegistration>().FirstOrDefault( r => r.ContextType == 
 2446                        ?? throw new InvalidOperationException( $"UseDbSeeder: {context.GetType().Name} has no AddDbSeed
 47
 2448        var configuration = registration.Configuration;
 49
 2450        return SeedEngine.UpAsync( context, configuration, configuration.CreateProvider( serviceProvider ), null, takeLo
 51    }
 52
 53    private static void Throw( LayerResponse<SeedRunResult> result )
 54    {
 2755        if ( result.IsFailure ) { throw new DbSeederException( result.Errors ); }
 2156    }
 57}