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

Information
Class: ZhEaIsNsAaBn.DbSeeder.Design.SeedFileWriter
Assembly: ZhEaIsNsAaBn.DbSeeder.Design
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder.Design/Files/SeedFileWriter.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 62
Line coverage: 100%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Manifest(...)50%22100%
Table(...)50%22100%
Normalize(...)100%11100%
Section(...)100%22100%
Row(...)100%11100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder.Design/Files/SeedFileWriter.cs

#LineLine coverage
 1namespace ZhEaIsNsAaBn.DbSeeder.Design;
 2
 3/// <summary>
 4/// Writes manifests and table files deterministically (§4.4): fixed property order, rows sorted by key with one row per
 5/// indent, CRLF line endings and a final newline — the same input always gives the same bytes, so an unchanged export i
 6/// </summary>
 7internal static class SeedFileWriter
 8{
 9    private const string NewLine = "\r\n";
 10
 11
 12    public static string Manifest( SeedManifest manifest )
 13    {
 11714        var lines = new List<string>
 11715                        {
 11716                            "{",
 11717                            $"  \"Id\": {SeedJsonValue.Text( manifest.Id )},",
 11718                            $"  \"ContextType\": {SeedJsonValue.Text( manifest.ContextType )},"
 11719                        };
 20
 11721        if ( manifest.RequiresSchemaMigration is not null ) { lines.Add( $"  \"RequiresSchemaMigration\": {SeedJsonValue
 22
 11723        lines.Add( $"  \"Tables\": [ {string.Join( ", ", manifest.Tables.Select( SeedJsonValue.Text ) )} ]" );
 11724        lines.Add( "}" );
 25
 26
 11727        return string.Join( NewLine, lines ) + NewLine;
 28    }
 29
 30    public static string Table( DesignTable table )
 31    {
 93332        var members = new List<string> { $"  \"Entity\": {SeedJsonValue.Text( table.Entity )}" };
 33
 93334        if ( table.MatchBy.Count > 0 ) { members.Add( $"  \"MatchBy\": [ {string.Join( ", ", table.MatchBy.Select( SeedJ
 35
 93336        Section( members, nameof( DesignTable.Upsert ), table.Upsert );
 93337        Section( members, nameof( DesignTable.Delete ), table.Delete );
 93338        Section( members, nameof( DesignTable.SoftDelete ), table.SoftDelete );
 93339        Section( members, nameof( DesignTable.Restore ), table.Restore );
 93340        Section( members, nameof( DesignTable.Before ), table.Before );
 41
 42
 93343        return "{" + NewLine + string.Join( "," + NewLine, members ) + NewLine + "}" + NewLine;
 44    }
 45
 46    /// Text with any line ending turned into CRLF and exactly one final newline (for other files the tools write).
 47    public static string Normalize( string text )
 8448        => text.Replace( "\r\n", "\n", StringComparison.Ordinal ).Replace( '\r', '\n' ).TrimEnd( '\n' ).Replace( "\n", N
 49
 50
 51    private static void Section( List<string> members, string name, List<DesignRow> rows )
 52    {
 816653        if ( rows.Count == 0 ) { return; }
 54
 55
 116456        var ordered = rows.OrderBy( r => r.Key, SeedKeyComparer.Instance ).Select( Row );
 57
 116458        members.Add( $"  {SeedJsonValue.Text( name )}: [{NewLine}{string.Join( "," + NewLine, ordered )}{NewLine}  ]" );
 116459    }
 60
 254761    private static string Row( DesignRow row ) => $"    {{ {string.Join( ", ", row.Values.Select( v => $"{SeedJsonValue.
 62}