< Summary - MechanicsSoftware — Coverage Report

Information
Class: MechanicsSoftware.Domain.Entities.Customer
Assembly: MechanicsSoftware.Domain
File(s): /home/runner/work/mechanics-software/mechanics-software/src/MechanicsSoftware.Domain/Entities/Customer.cs
Line coverage
97%
Covered lines: 39
Uncovered lines: 1
Coverable lines: 40
Total lines: 68
Line coverage: 97.5%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
.ctor(...)100%11100%
Create(...)100%11100%
Update(...)100%11100%
ValidateName(...)100%44100%
ValidatePhone(...)83.33%66100%

File(s)

/home/runner/work/mechanics-software/mechanics-software/src/MechanicsSoftware.Domain/Entities/Customer.cs

#LineLine coverage
 1using MechanicsSoftware.Domain.Enums;
 2using MechanicsSoftware.Domain.Exceptions;
 3using MechanicsSoftware.Domain.ValueObjects;
 4
 5namespace MechanicsSoftware.Domain.Entities;
 6
 7public sealed class Customer : Entity<Guid>
 8{
 9    public string Name { get; private set; } = null!;
 10    public TaxId Document { get; private set; } = null!;
 11    public Email Email { get; private set; } = null!;
 12    public string Phone { get; private set; } = null!;
 13
 014    private Customer() { }
 15
 7616    private Customer(Guid id, string name, TaxId taxId, Email email, string phone)
 7617    {
 7618        Id = id;
 7619        Name = name;
 7620        Document = taxId;
 7621        Email = email;
 7622        Phone = phone;
 7623    }
 24
 25    public static Customer Create(Guid id, string name, string taxId, PersonType personType, string email, string phone)
 9426    {
 9427        ValidateName(name);
 8628        ValidatePhone(phone);
 29
 8030        return new Customer(
 8031            id,
 8032            name.Trim(),
 8033            new TaxId(taxId, personType),
 8034            new Email(email),
 8035            phone.Trim()
 8036        );
 7637    }
 38
 39    public void Update(string name, string email, string phone)
 1040    {
 1041        ValidateName(name);
 842        ValidatePhone(phone);
 43
 844        Name = name.Trim();
 845        Email = new Email(email);
 646        Phone = phone.Trim();
 647    }
 48
 49    private static void ValidateName(string name)
 10450    {
 10451        if (string.IsNullOrWhiteSpace(name))
 452            throw new DomainException("Customer name is required.");
 53
 10054        if (name.Trim().Length > 100)
 655            throw new DomainException("Customer name must not exceed 100 characters.");
 9456    }
 57
 58    private static void ValidatePhone(string phone)
 9459    {
 9460        if (string.IsNullOrWhiteSpace(phone))
 461            throw new DomainException("Phone is required.");
 62
 9063        var digits = new string(phone.Where(char.IsDigit).ToArray());
 64
 9065        if (digits.Length < 8 || digits.Length > 15)
 266            throw new DomainException("Phone must have between 8 and 15 digits (with area code).");
 8867    }
 68}