< Summary

Information
Class: RoleRadar.Domain.Tracking.Company
Assembly: RoleRadar.Domain
File(s): /home/runner/work/roleradar/roleradar/src/RoleRadar.Domain/Tracking/Company.cs
Line coverage
100%
Covered lines: 107
Uncovered lines: 0
Coverable lines: 107
Total lines: 234
Line coverage: 100%
Branch coverage
100%
Covered branches: 64
Total branches: 64
Branch coverage: 100%
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_NormalizedName()100%11100%
get_Description()100%11100%
get_ParentCompany()100%11100%
get_OwnershipType()100%11100%
get_Headquarters()100%11100%
get_CategoryTags()100%11100%
get_Status()100%11100%
get_LastCheckedAt()100%11100%
get_LastCheckResult()100%11100%
get_VersionToken()100%11100%
get_CreatedAt()100%11100%
get_UpdatedAt()100%11100%
Create(...)100%1818100%
Rehydrate(...)100%11100%
Update(...)100%3232100%
ValidateCategoryTags(...)100%1414100%

File(s)

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

#LineLine coverage
 1namespace RoleRadar.Domain.Tracking;
 2
 3public sealed class Company
 4{
 5    public const int MaxNameLength = 150;
 6    public const int MaxDescriptionLength = 300;
 7    public const int MaxParentCompanyLength = 150;
 8    public const int MaxHeadquartersLength = 150;
 9    public const int MaxCategoryTagsCount = 20;
 10    public const int MaxCategoryTagLength = 50;
 11    public const int MaxLastCheckResultLength = 300;
 12
 1717413    public Guid Id { get; init; }
 742214    public string OwnerId { get; init; } = string.Empty;
 750415    public string Name { get; private set; } = string.Empty;
 625816    public string NormalizedName { get; private set; } = string.Empty;
 404817    public string? Description { get; private set; }
 341418    public string? ParentCompany { get; private set; }
 651019    public OwnershipType OwnershipType { get; private set; } = OwnershipType.Unknown;
 363220    public string? Headquarters { get; private set; }
 602421    public IReadOnlyList<string> CategoryTags { get; private set; } = [];
 666622    public CompanyStatus Status { get; private set; } = CompanyStatus.Neutral;
 141023    public DateTimeOffset? LastCheckedAt { get; private set; }
 140424    public string? LastCheckResult { get; private set; }
 408625    public Guid VersionToken { get; private set; }
 340226    public DateTimeOffset CreatedAt { get; init; }
 344627    public DateTimeOffset UpdatedAt { get; private set; }
 28
 29    public static Company Create(
 30        string ownerId,
 31        string name,
 32        string? description = null,
 33        string? parentCompany = null,
 34        OwnershipType ownershipType = OwnershipType.Unknown,
 35        string? headquarters = null,
 36        IReadOnlyList<string>? categoryTags = null,
 37        CompanyStatus status = CompanyStatus.Neutral,
 38        Guid? id = null,
 39        DateTimeOffset? now = null)
 40    {
 203441        ArgumentException.ThrowIfNullOrWhiteSpace(ownerId);
 203442        ArgumentException.ThrowIfNullOrWhiteSpace(name);
 43
 203244        var trimmedName = name.Trim();
 203245        if (trimmedName.Length > MaxNameLength)
 46        {
 647            throw new ArgumentException($"Company name cannot exceed {MaxNameLength} characters.", nameof(name));
 48        }
 49
 202650        if (description is not null && description.Length > MaxDescriptionLength)
 51        {
 652            throw new ArgumentException($"Company description cannot exceed {MaxDescriptionLength} characters.", nameof(
 53        }
 54
 202055        if (parentCompany is not null && parentCompany.Length > MaxParentCompanyLength)
 56        {
 657            throw new ArgumentException($"Parent company cannot exceed {MaxParentCompanyLength} characters.", nameof(par
 58        }
 59
 201460        if (headquarters is not null && headquarters.Length > MaxHeadquartersLength)
 61        {
 662            throw new ArgumentException($"Headquarters cannot exceed {MaxHeadquartersLength} characters.", nameof(headqu
 63        }
 64
 200865        var validatedTags = ValidateCategoryTags(categoryTags);
 200466        var timestamp = now ?? DateTimeOffset.UtcNow;
 67
 200468        return new Company
 200469        {
 200470            Id = id ?? Guid.CreateVersion7(),
 200471            OwnerId = ownerId.Trim(),
 200472            Name = trimmedName,
 200473            NormalizedName = trimmedName.ToLowerInvariant(),
 200474            Description = description,
 200475            ParentCompany = parentCompany,
 200476            OwnershipType = ownershipType,
 200477            Headquarters = headquarters,
 200478            CategoryTags = validatedTags,
 200479            Status = status,
 200480            VersionToken = Guid.CreateVersion7(),
 200481            CreatedAt = timestamp,
 200482            UpdatedAt = timestamp
 200483        };
 84    }
 85
 86    public static Company Rehydrate(
 87        Guid id,
 88        string ownerId,
 89        string name,
 90        string normalizedName,
 91        string? description,
 92        string? parentCompany,
 93        OwnershipType ownershipType,
 94        string? headquarters,
 95        IReadOnlyList<string> categoryTags,
 96        CompanyStatus status,
 97        DateTimeOffset? lastCheckedAt,
 98        string? lastCheckResult,
 99        Guid versionToken,
 100        DateTimeOffset createdAt,
 101        DateTimeOffset updatedAt)
 102    {
 568103        return new Company
 568104        {
 568105            Id = id,
 568106            OwnerId = ownerId,
 568107            Name = name,
 568108            NormalizedName = normalizedName,
 568109            Description = description,
 568110            ParentCompany = parentCompany,
 568111            OwnershipType = ownershipType,
 568112            Headquarters = headquarters,
 568113            CategoryTags = categoryTags,
 568114            Status = status,
 568115            LastCheckedAt = lastCheckedAt,
 568116            LastCheckResult = lastCheckResult,
 568117            VersionToken = versionToken,
 568118            CreatedAt = createdAt,
 568119            UpdatedAt = updatedAt
 568120        };
 121    }
 122
 123    public void Update(
 124        string? name = null,
 125        string? description = null,
 126        string? parentCompany = null,
 127        OwnershipType? ownershipType = null,
 128        string? headquarters = null,
 129        IReadOnlyList<string>? categoryTags = null,
 130        CompanyStatus? status = null,
 131        DateTimeOffset? lastCheckedAt = null,
 132        string? lastCheckResult = null,
 133        DateTimeOffset? now = null)
 134    {
 64135        if (name is not null)
 136        {
 20137            var trimmedName = name.Trim();
 20138            if (trimmedName.Length == 0 || trimmedName.Length > MaxNameLength)
 139            {
 6140                throw new ArgumentException($"Company name must be 1..{MaxNameLength} characters.", nameof(name));
 141            }
 14142            Name = trimmedName;
 14143            NormalizedName = trimmedName.ToLowerInvariant();
 144        }
 145
 58146        if (description is not null)
 147        {
 28148            if (description.Length > MaxDescriptionLength)
 149            {
 4150                throw new ArgumentException($"Company description cannot exceed {MaxDescriptionLength} characters.", nam
 151            }
 24152            Description = description;
 153        }
 154
 54155        if (parentCompany is not null)
 156        {
 6157            if (parentCompany.Length > MaxParentCompanyLength)
 158            {
 4159                throw new ArgumentException($"Parent company cannot exceed {MaxParentCompanyLength} characters.", nameof
 160            }
 2161            ParentCompany = parentCompany;
 162        }
 163
 50164        if (ownershipType.HasValue)
 165        {
 8166            OwnershipType = ownershipType.Value;
 167        }
 168
 50169        if (headquarters is not null)
 170        {
 6171            if (headquarters.Length > MaxHeadquartersLength)
 172            {
 4173                throw new ArgumentException($"Headquarters cannot exceed {MaxHeadquartersLength} characters.", nameof(he
 174            }
 2175            Headquarters = headquarters;
 176        }
 177
 46178        if (categoryTags is not null)
 179        {
 6180            CategoryTags = ValidateCategoryTags(categoryTags);
 181        }
 182
 46183        if (status.HasValue)
 184        {
 22185            Status = status.Value;
 186        }
 187
 46188        if (lastCheckedAt.HasValue)
 189        {
 2190            LastCheckedAt = lastCheckedAt.Value;
 191        }
 192
 46193        if (lastCheckResult is not null)
 194        {
 6195            if (lastCheckResult.Length > MaxLastCheckResultLength)
 196            {
 2197                throw new ArgumentException($"Last check result cannot exceed {MaxLastCheckResultLength} characters.", n
 198            }
 4199            LastCheckResult = lastCheckResult;
 200        }
 201
 44202        VersionToken = Guid.CreateVersion7();
 44203        UpdatedAt = now ?? DateTimeOffset.UtcNow;
 44204    }
 205
 206    private static List<string> ValidateCategoryTags(IReadOnlyList<string>? tags)
 207    {
 2014208        if (tags is null || tags.Count == 0)
 209        {
 1964210            return [];
 211        }
 212
 50213        if (tags.Count > MaxCategoryTagsCount)
 214        {
 2215            throw new ArgumentException($"Category tags count cannot exceed {MaxCategoryTagsCount}.", nameof(tags));
 216        }
 217
 48218        var list = new List<string>(tags.Count);
 334219        foreach (var tag in tags)
 220        {
 120221            var trimmed = tag.Trim();
 120222            if (trimmed.Length > MaxCategoryTagLength)
 223            {
 2224                throw new ArgumentException($"Category tag '{trimmed}' exceeds max length of {MaxCategoryTagLength}.", n
 225            }
 118226            if (trimmed.Length > 0 && !list.Contains(trimmed, StringComparer.OrdinalIgnoreCase))
 227            {
 116228                list.Add(trimmed);
 229            }
 230        }
 231
 46232        return list;
 233    }
 234}