< Summary

Information
Class: RoleRadar.Domain.Tracking.Contact
Assembly: RoleRadar.Domain
File(s): /home/runner/work/roleradar/roleradar/src/RoleRadar.Domain/Tracking/Contact.cs
Line coverage
93%
Covered lines: 86
Uncovered lines: 6
Coverable lines: 92
Total lines: 159
Line coverage: 93.4%
Branch coverage
64%
Covered branches: 18
Total branches: 28
Branch coverage: 64.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_OwnerId()100%11100%
get_Name()100%11100%
get_Role()100%11100%
get_CompanyAffiliation()100%11100%
get_CompanyId()100%11100%
get_Relationship()100%11100%
get_Notes()100%11100%
get_IsRedacted()100%11100%
get_VersionToken()100%11100%
get_CreatedAt()100%11100%
get_UpdatedAt()100%11100%
.ctor(...)100%11100%
Create(...)65.38%292682.75%
Redact(...)50%2291.66%
Rehydrate(...)100%11100%

File(s)

/home/runner/work/roleradar/roleradar/src/RoleRadar.Domain/Tracking/Contact.cs

#LineLine coverage
 1using RoleRadar.Domain.Common;
 2
 3namespace RoleRadar.Domain.Tracking;
 4
 5
 6public sealed class Contact
 7{
 8    public const int MaxNameLength = 150;
 9    public const int MaxRoleLength = 150;
 10    public const int MaxCompanyAffiliationLength = 150;
 11    public const int MaxNotesLength = 500;
 12    public const string RedactedPlaceholder = "[REDACTED]";
 13
 6614    public Guid Id { get; }
 2415    public string OwnerId { get; }
 5216    public string Name { get; private set; }
 6817    public string? Role { get; private set; }
 6618    public string? CompanyAffiliation { get; private set; }
 6019    public Guid? CompanyId { get; private set; }
 5220    public ContactRelationship Relationship { get; private set; }
 6421    public string? Notes { get; private set; }
 6222    public bool IsRedacted { get; private set; }
 6823    public Guid VersionToken { get; private set; }
 2424    public DateTime CreatedAt { get; }
 4825    public DateTime UpdatedAt { get; private set; }
 26
 1827    private Contact(
 1828        Guid id,
 1829        string ownerId,
 1830        string name,
 1831        string? role,
 1832        string? companyAffiliation,
 1833        Guid? companyId,
 1834        ContactRelationship relationship,
 1835        string? notes,
 1836        bool isRedacted,
 1837        Guid versionToken,
 1838        DateTime createdAt,
 1839        DateTime updatedAt)
 40    {
 1841        Id = id;
 1842        OwnerId = ownerId;
 1843        Name = name;
 1844        Role = role;
 1845        CompanyAffiliation = companyAffiliation;
 1846        CompanyId = companyId;
 1847        Relationship = relationship;
 1848        Notes = notes;
 1849        IsRedacted = isRedacted;
 1850        VersionToken = versionToken;
 1851        CreatedAt = createdAt;
 1852        UpdatedAt = updatedAt;
 1853    }
 54
 55    public static Contact Create(
 56        string ownerId,
 57        string name,
 58        string? role = null,
 59        string? companyAffiliation = null,
 60        Guid? companyId = null,
 61        ContactRelationship relationship = ContactRelationship.Peer,
 62        string? notes = null,
 63        Guid? id = null,
 64        DateTime? now = null)
 65    {
 1066        var validOwner = new OwnerId(ownerId).Value;
 1067        if (string.IsNullOrWhiteSpace(name))
 68        {
 069            throw new ArgumentException("Contact name is required.", nameof(name));
 70        }
 71
 1072        var trimmedName = name.Trim();
 1073        if (trimmedName.Length > MaxNameLength)
 74        {
 075            throw new ArgumentException($"Contact name cannot exceed {MaxNameLength} characters.", nameof(name));
 76        }
 77
 1078        var trimmedRole = role?.Trim();
 1079        if (trimmedRole is not null && trimmedRole.Length > MaxRoleLength)
 80        {
 081            throw new ArgumentException($"Contact role cannot exceed {MaxRoleLength} characters.", nameof(role));
 82        }
 83
 1084        var trimmedCompany = companyAffiliation?.Trim();
 1085        if (trimmedCompany is not null && trimmedCompany.Length > MaxCompanyAffiliationLength)
 86        {
 087            throw new ArgumentException($"Company affiliation cannot exceed {MaxCompanyAffiliationLength} characters.", 
 88        }
 89
 1090        if (notes is not null && notes.Length > MaxNotesLength)
 91        {
 092            throw new ArgumentException($"Contact notes cannot exceed {MaxNotesLength} characters.", nameof(notes));
 93        }
 94
 1095        var timestamp = now ?? DateTime.UtcNow;
 1096        var utcNow = timestamp.Kind == DateTimeKind.Utc ? timestamp : DateTime.SpecifyKind(timestamp, DateTimeKind.Utc);
 97
 1098        return new Contact(
 1099            id: id ?? Guid.CreateVersion7(),
 10100            ownerId: validOwner,
 10101            name: trimmedName,
 10102            role: trimmedRole,
 10103            companyAffiliation: trimmedCompany,
 10104            companyId: companyId,
 10105            relationship: relationship,
 10106            notes: notes,
 10107            isRedacted: false,
 10108            versionToken: Guid.CreateVersion7(),
 10109            createdAt: utcNow,
 10110            updatedAt: utcNow);
 111    }
 112
 113    public void Redact(DateTimeOffset now)
 114    {
 6115        if (IsRedacted)
 116        {
 0117            return;
 118        }
 119
 6120        Name = RedactedPlaceholder;
 6121        Role = null;
 6122        CompanyAffiliation = null;
 6123        CompanyId = null;
 6124        Relationship = ContactRelationship.Redacted;
 6125        Notes = null;
 6126        IsRedacted = true;
 6127        VersionToken = Guid.CreateVersion7();
 6128        UpdatedAt = now.UtcDateTime;
 6129    }
 130
 131    public static Contact Rehydrate(
 132        Guid id,
 133        string ownerId,
 134        string name,
 135        string? role,
 136        string? companyAffiliation,
 137        Guid? companyId,
 138        ContactRelationship relationship,
 139        string? notes,
 140        bool isRedacted,
 141        Guid versionToken,
 142        DateTime createdAt,
 143        DateTime updatedAt)
 144    {
 8145        return new Contact(
 8146            id,
 8147            ownerId,
 8148            name,
 8149            role,
 8150            companyAffiliation,
 8151            companyId,
 8152            relationship,
 8153            notes,
 8154            isRedacted,
 8155            versionToken,
 8156            createdAt,
 8157            updatedAt);
 158    }
 159}