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

Information
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 43
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Compute(...)100%22100%
Normalize(...)100%11100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/DataBasePackages/ZhEaIsNsAaBn.DbSeeder/Migrations/SeedChecksum.cs

#LineLine coverage
 1#region Usings
 2using System.Security.Cryptography;
 3using System.Text;
 4#endregion
 5
 6namespace ZhEaIsNsAaBn.DbSeeder;
 7
 8/// <summary>
 9/// The checksum stored in the history table: SHA-256 over a migration's manifest and table files, with line endings nor
 10/// and any UTF-8 BOM removed, so a CRLF checkout hashes the same as an LF one.
 11/// </summary>
 12public static class SeedChecksum
 13{
 14    /// <summary>The manifest file name inside a migration folder.</summary>
 15    public const string ManifestFile = "manifest.json";
 16
 17
 18    /// <summary>Computes the checksum. Files are hashed by name (<c>manifest.json</c> first, then ordinal order), name 
 19    /// <param name="files">File name (no folder) and text of the manifest and each table file.</param>
 20    /// <returns>64 lower-case hex characters.</returns>
 21    /// <exception cref="ArgumentNullException"><paramref name="files"/> is <see langword="null"/>.</exception>
 22    public static string Compute( IEnumerable<KeyValuePair<string, string>> files )
 23    {
 83224        ArgumentNullException.ThrowIfNull( files );
 25
 83226        using var hash = IncrementalHash.CreateHash( HashAlgorithmName.SHA256 );
 27
 28
 758429        foreach ( var (name, text) in files.OrderBy( f => f.Key == ManifestFile ? 0 : 1 ).ThenBy( f => f.Key, StringComp
 30        {
 296031            hash.AppendData( Encoding.UTF8.GetBytes( name + "\n" ) );
 296032            hash.AppendData( Encoding.UTF8.GetBytes( Normalize( text ) + "\n" ) );
 33        }
 34
 35
 83236        return Convert.ToHexString( hash.GetHashAndReset() ).ToLowerInvariant();
 83237    }
 38
 39    /// <summary>Removes a leading BOM and turns CRLF / CR into LF.</summary>
 40    /// <param name="text">The file text.</param>
 41    /// <returns>The normalised text.</returns>
 608942    internal static string Normalize( string text ) => text.TrimStart( '' ).Replace( "\r\n", "\n", StringComparison.Ord
 43}