< Summary - Core.Tests

Information
Class: Common.Core.Models.Address
Assembly: Common.Core
File(s): D:\a\NuGetPackages\NuGetPackages\src\Common\Core\Models\Address.cs
Tag: 3_8508158812
Line coverage
100%
Covered lines: 82
Uncovered lines: 0
Coverable lines: 82
Total lines: 185
Line coverage: 100%
Branch coverage
100%
Covered branches: 42
Total branches: 42
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
get_Street()100%11100%
set_Street(...)100%22100%
get_City()100%11100%
set_City(...)100%22100%
get_Province()100%11100%
set_Province(...)100%22100%
get_Postcode()100%11100%
set_Postcode(...)100%22100%
get_Country()100%11100%
set_Country(...)100%22100%
get_FullAddress()100%66100%
Equals(...)100%1414100%
UpdateAddress(...)100%1212100%
BuildAddress(...)100%11100%

File(s)

D:\a\NuGetPackages\NuGetPackages\src\Common\Core\Models\Address.cs

#LineLine coverage
 1using System.ComponentModel.DataAnnotations;
 2using System.ComponentModel.DataAnnotations.Schema;
 3using System.Data;
 4using System.Text.Json.Serialization;
 5using Common.Core.Classes;
 6
 7namespace Common.Core.Models;
 8
 9/// <summary>This class contains details of an Address.</summary>
 10public class Address : ModelBase, IEquatable<object>
 11{
 12  #region Private Variables
 13
 14  private string? _street;
 15  private string? _city;
 16  private string? _province;
 17  private string? _postcode;
 18  private string? _country;
 19
 20  #endregion
 21
 22  #region Properties
 23
 24  /// <summary>Gets or sets the Street.</summary>
 25  [MaxLength(50)]
 26  [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
 27  public string? Street
 28  {
 11629    get => _street;
 30    set
 7531    {
 7532      if( value != _street )
 7533      {
 7534        _street = SetNullString( value );
 7535        OnPropertyChanged( nameof( Street ) );
 7536        OnPropertyChanged( nameof( FullAddress ) );
 7537      }
 7538    }
 39  }
 40
 41  /// <summary>Gets or sets the City.</summary>
 42  [MaxLength( 50 )]
 43  [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
 44  public string? City
 45  {
 11246    get => _city;
 47    set
 7348    {
 7349      if( value != _city )
 7350      {
 7351        _city = SetNullString( value );
 7352        OnPropertyChanged( nameof( City ) );
 7353        OnPropertyChanged( nameof( FullAddress ) );
 7354      }
 7355    }
 56  }
 57
 58  /// <summary>Gets or sets the Province.</summary>
 59  [MaxLength( 50 )]
 60  [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
 61  public string? Province
 62  {
 11063    get => _province;
 64    set
 7365    {
 7366      if( value != _province )
 7367      {
 7368        _province = SetNullString( value );
 7369        OnPropertyChanged( nameof( Province ) );
 7370        OnPropertyChanged( nameof( FullAddress ) );
 7371      }
 7372    }
 73  }
 74
 75  /// <summary>Gets or sets the Postal Code.</summary>
 76  [MaxLength( 20 )]
 77  [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
 78  public string? Postcode
 79  {
 10680    get => _postcode;
 81    set
 7382    {
 7383      if( value != _postcode )
 7384      {
 7385        _postcode = SetNullString( value );
 7386        OnPropertyChanged( nameof( Postcode ) );
 7387      }
 7388    }
 89  }
 90
 91  /// <summary>Gets or sets the Country.</summary>
 92  [MaxLength( 50 )]
 93  [JsonIgnore( Condition = JsonIgnoreCondition.WhenWritingNull )]
 94  public string? Country
 95  {
 10396    get => _country;
 97    set
 7298    {
 7299      if( value != _country )
 72100      {
 72101        _country = SetNullString( value );
 72102        OnPropertyChanged( nameof( Country ) );
 72103      }
 72104    }
 105  }
 106
 107  /// <summary>Gets the Full Address.</summary>
 108  [NotMapped]
 109  [JsonIgnore]
 110  public string FullAddress
 111  {
 112    get
 2113    {
 2114      var values = new[] { Street?.Trim(), City?.Trim(), Province?.Trim() };
 8115      return string.Join( ", ", values.Where( s => !string.IsNullOrEmpty( s ) ) );
 2116    }
 117  }
 118
 119  #endregion
 120
 121  #region Public Methods
 122
 123  /// <inheritdoc/>
 124  /// <param name="obj">An Address object to compare with this object.</param>
 125  public new bool Equals( object? obj )
 15126  {
 19127    if( obj is null || obj is not Address other ) { return false; }
 128
 17129    if( other.Street != Street ) { return false; }
 13130    if( other.City != City ) { return false; }
 12131    if( other.Province != Province ) { return false; }
 11132    if( other.Postcode != Postcode ) { return false; }
 10133    if( other.Country != Country ) { return false; }
 134
 7135    return true;
 15136  }
 137
 138  /// <summary>Builds the SQL script for any value changes.</summary>
 139  /// <param name="obj">Address object containing the original values.</param>
 140  /// <param name="mod">Address object containing the modified values.</param>
 141  /// <param name="cur">Address object containing the current values.</param>
 142  /// <param name="list">List of SQL script changes.</param>
 143  /// <param name="prefix">Table column name prefix for Address fields (if required).</param>
 144  /// <returns><see langword="true"/> if the current object is equal to the object containing the
 145  /// original values; otherwise, <see langword="false"/>.</returns>
 146  /// <remarks>This method assumes that the table column names are the same as the property names.</remarks>
 147  public static bool UpdateAddress( Address obj, Address mod, Address cur, IList<string> list,
 148    string prefix = "" )
 7149  {
 7150    if( !cur.Equals( obj ) )
 1151    {
 1152      mod.Street = cur.Street;
 1153      mod.City = cur.City;
 1154      mod.Province = cur.Province;
 1155      mod.Postcode = cur.Postcode;
 1156      mod.Country = cur.Country;
 1157      return false;
 158    }
 159
 24160    if( obj.Street != mod.Street ) { ModelData.SetSQLColumn( prefix + nameof( Street ), mod.Street, list ); }
 24161    if( obj.City != mod.City ) { ModelData.SetSQLColumn( prefix + nameof( City ), mod.City, list ); }
 24162    if( obj.Province != mod.Province ) { ModelData.SetSQLColumn( prefix + nameof( Province ), mod.Province, list ); }
 24163    if( obj.Postcode != mod.Postcode ) { ModelData.SetSQLColumn( prefix + nameof( Postcode ), mod.Postcode, list ); }
 24164    if( obj.Country != mod.Country ) { ModelData.SetSQLColumn( prefix + nameof( Country ), mod.Country, list ); }
 6165    return true;
 7166  }
 167
 168  #endregion
 169
 170  #region Internal Methods
 171
 172  internal static Address BuildAddress( DataRow row, string prefix = "" )
 17173  {
 17174    return new Address()
 17175    {
 17176      Street = row.Field<string?>( prefix + nameof( Street ) ),
 17177      City = row.Field<string?>( prefix + nameof( City ) ),
 17178      Province = row.Field<string?>( prefix + nameof( Province ) ),
 17179      Postcode = row.Field<string?>( prefix + nameof( Postcode ) ),
 17180      Country = row.Field<string?>( prefix + nameof( Country ) )
 17181    };
 17182  }
 183
 184  #endregion
 185}