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

Information
Class: ZhEaIsNsAaBn.DbSeeder.Design.SeedSnapshot
Assembly: ZhEaIsNsAaBn.DbSeeder.Design
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder.Design/Files/SeedSnapshot.cs
Line coverage
95%
Covered lines: 19
Uncovered lines: 1
Coverable lines: 20
Total lines: 58
Line coverage: 95%
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
PathOf(...)100%11100%
ToFile(...)50%22100%
Write(...)100%11100%
Read(...)75%4490.9%

File(s)

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

#LineLine coverage
 1namespace ZhEaIsNsAaBn.DbSeeder.Design;
 2
 3/// <summary>
 4/// <c>{output}/.snapshot/{Entity}.json</c>: the seed rows as of the last <c>add</c> / <c>baseline</c> / <c>snapshot reb
 5/// form (<c>Upsert</c> = every row, <c>SoftDelete</c> = keys of rows soft-deleted then). Design-time only, never embedd
 6/// </summary>
 7internal static class SeedSnapshot
 8{
 9    public const string Folder = ".snapshot";
 10
 11
 69312    public static string PathOf( string outputFolder, ExportedTable table ) => Path.Combine( outputFolder, Folder, table
 13
 14    public static DesignTable ToFile( ExportedTable table )
 15    {
 87616        var file = new DesignTable { Entity = table.Shape.EntityType.Name, MatchBy = table.Shape.IsBusinessKey ? table.M
 17
 87618        file.Upsert.AddRange( table.Rows );
 87619        file.SoftDelete.AddRange( table.Rows.Where( r => table.SoftDeleted.Contains( r.Key ) ).Select( r => r.Only( tabl
 20
 87621        return file;
 22    }
 23
 24    public static void Write( string outputFolder, ExportedTable table )
 25    {
 48026        var path = PathOf( outputFolder, table );
 27
 48028        Directory.CreateDirectory( Path.GetDirectoryName( path )! );
 48029        File.WriteAllText( path, SeedFileWriter.Table( ToFile( table ) ), new UTF8Encoding( false ) );
 48030    }
 31
 32    /// The snapshot of <paramref name="current"/>'s table, read back into the same row form; <see langword="null"/> whe
 33    /// <exception cref="InvalidOperationException">The file can't be parsed.</exception>
 34    public static ExportedTable? Read( string outputFolder, ExportedTable current )
 35    {
 21336        var path = PathOf( outputFolder, current );
 37
 21638        if ( !File.Exists( path ) ) { return null; }
 39
 40
 41        SeedTableFile file;
 42
 42043        try { file = JsonSerializer.Deserialize<SeedTableFile>( File.ReadAllText( path ), SeedMigrationSource.JsonOption
 044        catch ( JsonException ex ) { throw new InvalidOperationException( $"{path} can't be read: {ex.Message}", ex ); }
 45
 46
 21047        var match = current.MatchNames;
 48
 49        string KeyOf( IReadOnlyDictionary<string, JsonElement> row ) => SeedKeyComparer.Key( match.Select( m => row.TryG
 50
 21051        return new ExportedTable
 21052                   {
 21053                       Shape       = current.Shape,
 21054                       Rows        = file.Upsert.Select( r => new DesignRow( KeyOf( r ), r.Select( p => (p.Key, p.Value.
 21055                       SoftDeleted = file.SoftDelete.Select( KeyOf ).ToHashSet( StringComparer.Ordinal )
 21056                   };
 57    }
 58}