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

Information
Class: ZhEaIsNsAaBn.DbSeeder.Design.SeedExporter
Assembly: ZhEaIsNsAaBn.DbSeeder.Design
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder.Design/Export/SeedExporter.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 50
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
ExportAsync(...)100%11100%
ExportCoreAsync()100%1010100%
ToProvider(...)100%66100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder.Design/Export/SeedExporter.cs

#LineLine coverage
 1namespace ZhEaIsNsAaBn.DbSeeder.Design;
 2
 3/// <summary>
 4/// Reads the seed rows of a table from the dev database (§8.3): <c>AsNoTracking()</c> + <c>IgnoreQueryFilters()</c> (so
 5/// too), every column through <c>EF.Property</c> (shadow properties included), values turned into <b>provider values</b
 6/// converters. Only the data columns the runtime accepts are read (<see cref="SeedEntityShape"/>), plus the soft-delete
 7/// </summary>
 8internal static class SeedExporter
 9{
 310    private static readonly System.Reflection.MethodInfo ExportCoreMethod = typeof( SeedExporter ).GetMethod( nameof( Ex
 11
 12
 13    public static Task<ExportedTable> ExportAsync( DbContext dbContext, SeedEntityShape shape, CancellationToken cancell
 63014        => (Task<ExportedTable>) ExportCoreMethod.MakeGenericMethod( shape.EntityType.ClrType ).Invoke( null, [ dbContex
 15
 16
 17    private static async Task<ExportedTable> ExportCoreAsync< TEntity >( DbContext dbContext, SeedEntityShape shape, Can
 18        where TEntity : class
 19    {
 63020        var flag       = shape.Table.SoftDeleteFlag;
 63021        var properties = shape.DataColumns.Select( c => c.Property ).Concat( flag is null ? [] : [ flag.Property ] ).ToL
 63022        var entity     = Expression.Parameter( typeof( TEntity ), "e" );
 63023        var values     = properties.Select( p => (Expression) Expression.Convert( Expression.Call( typeof( EF ), nameof(
 63024                                                                                  typeof( object ) ) );
 63025        var projection = Expression.Lambda<Func<TEntity, object[]>>( Expression.NewArrayInit( typeof( object ), values )
 26
 63027        var raw = await dbContext.Set<TEntity>().AsNoTracking().IgnoreQueryFilters().Select( projection ).ToListAsync( c
 28
 29
 63030        var match       = shape.Table.MatchColumns.Select( m => shape.DataColumns.Select( c => c.ColumnName ).ToList().I
 63031        var rows        = new List<DesignRow>( raw.Count );
 63032        var softDeleted = new HashSet<string>( StringComparer.Ordinal );
 33
 453034        foreach ( var record in raw )
 35        {
 163536            var json = shape.DataColumns.Select( ( c, i ) => SeedJsonValue.Format( ToProvider( c.Property, record[ i ] )
 163537            var key  = SeedKeyComparer.Key( match.Select( i => json[ i ] ) );
 38
 163539            rows.Add( new DesignRow( key, shape.DataColumns.Select( ( c, i ) => (c.PropertyName, json[ i ]) ).ToList() )
 40
 179141            if ( flag is not null && record[ ^1 ] is true ) { softDeleted.Add( key ); }
 42        }
 43
 44
 63045        return new ExportedTable { Shape = shape, Rows = rows.OrderBy( r => r.Key, SeedKeyComparer.Instance ).ToList(), 
 63046    }
 47
 48    private static object? ToProvider( IProperty property, object? value )
 542749        => value is null ? null : property.GetTypeMapping().Converter?.ConvertToProvider( value ) ?? value;
 50}