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

Information
Line coverage
95%
Covered lines: 19
Uncovered lines: 1
Coverable lines: 20
Total lines: 58
Line coverage: 95%
Branch coverage
25%
Covered branches: 1
Total branches: 4
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
For(...)50%22100%
Message(...)0%620%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder/Binding/SeedEntityShape.cs

#LineLine coverage
 1namespace ZhEaIsNsAaBn.DbSeeder;
 2
 3/// <summary>
 4/// The seed view of one entity type: its table, managed fields, data columns and match key — resolved with the same rul
 5/// uses to bind data files (seed configuration → attributes → interfaces; computed / generated-on-update / ignored colu
 6/// The design tools export through it, so what they write is exactly what the runtime accepts.
 7/// </summary>
 8internal sealed class SeedEntityShape
 9{
 10    public required IEntityType EntityType { get; init; }
 11
 12    public required SeedTable Table { get; init; }
 13
 14    public required SeedEntityRoles Roles { get; init; }
 15
 16    /// Managed fields the entity maps (role → column).
 17    public required IReadOnlyDictionary<SeedRole, SeedColumn> Managed { get; init; }
 18
 19    /// Data columns in EF model order (match key included; managed and skipped columns left out).
 20    public required IReadOnlyList<SeedColumn> DataColumns { get; init; }
 21
 22    /// Whether <see cref="SeedTable.MatchColumns"/> is a configured business key (written as <c>MatchBy</c>).
 23    public required bool IsBusinessKey { get; init; }
 24
 25
 26    /// <summary>Resolves the shape of <paramref name="entityType"/>.</summary>
 27    /// <exception cref="InvalidOperationException">Owned / shared / inheritance entity, no table, or a configured <c>Ma
 28    public static SeedEntityShape For( IEntityType entityType, SeedConfiguration configuration )
 29    {
 30        // The binder is the single source of the rules: bind an empty table file of the entity and read what it resolve
 98131        var file  = new SeedTableFile { Entity = entityType.Name };
 98132        var bound = SeedMigrationBinder.BindTable( entityType.Model, configuration, $"({entityType.Name})", file );
 33
 98134        if ( bound.IsFailure ) { throw new InvalidOperationException( Message( bound.Errors[ 0 ] ) ); }
 35
 36
 98137        var table   = bound.Result!;
 98138        var store   = StoreObjectIdentifier.Table( table.Table.Name, table.Table.Schema );
 98139        var managed = table.Managed.Values.Select( c => c.Property ).ToHashSet();
 98140        var columns = entityType.GetProperties()
 98141                                .Where( p => !managed.Contains( p ) && !SeedMigrationBinder.IsSkipped( p, store, table.R
 98142                                .Select( p => SeedMigrationBinder.Column( p, store ) )
 98143                                .ToList();
 44
 98145        return new SeedEntityShape
 98146                   {
 98147                       EntityType    = entityType,
 98148                       Table         = table.Table,
 98149                       Roles         = table.Roles,
 98150                       Managed       = table.Managed,
 98151                       DataColumns   = columns,
 98152                       IsBusinessKey = table.MatchesByBusinessKey
 98153                   };
 54    }
 55
 56
 057    private static string Message( Error error ) => error.AdditionalData.TryGetValue( "Reason", out var reason ) ? $"{er
 58}