< Summary - Core.Tests

Information
Class: Common.Core.Classes.ModelData
Assembly: Common.Core
File(s): D:\a\NuGetPackages\NuGetPackages\src\Common\Core\Classes\ModelData.cs
Tag: 3_8508158812
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 44
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SetSQLColumn(...)100%1414100%

File(s)

D:\a\NuGetPackages\NuGetPackages\src\Common\Core\Classes\ModelData.cs

#LineLine coverage
 1using System.ComponentModel.DataAnnotations;
 2
 3[assembly: System.Runtime.CompilerServices.InternalsVisibleTo( "Core.Tests" )]
 4namespace Common.Core.Classes;
 5
 6/// <summary>Base class for models with an integer as the primary key.</summary>
 7public abstract class ModelData : ModelBase
 8{
 9  /// <summary>Gets or sets the primary key.</summary>
 10  [Key]
 11  [Range( 0, 2147483647 )]
 12  public abstract int Id { get; set; }
 13
 14  #region Internal Methods
 15
 16  internal static void SetSQLColumn( string colName, object? newValue, IList<string> sql )
 8417  {
 18    const char cCharQuote = '\'';
 19    const string cStrQuote = "'";
 20    const string cDblQuote = "''";
 21
 8422    string quote = string.Empty;
 8423    bool hasNewValue = newValue is not null;
 24
 8425    if( hasNewValue )
 7926    {
 7927      if( newValue is string str )
 7528      {
 7529        quote = cStrQuote;
 9330        if( str.Contains( cCharQuote ) ) { newValue = str.Replace( cStrQuote, cDblQuote ); }
 7531      }
 432      else if( newValue is char chr )
 333      {
 334        quote = cStrQuote;
 635        if( chr == cCharQuote ) { newValue = cDblQuote; }
 336      }
 7937    }
 38
 8439    newValue = hasNewValue ? $"{quote}{newValue}{quote}" : "NULL";
 8440    sql.Add( $"[{colName}]={newValue}" );
 8441  }
 42
 43  #endregion
 44}