< Summary - MechanicsSoftware — Coverage Report

Information
Class: MechanicsSoftware.Domain.ValueObjects.LicensePlate
Assembly: MechanicsSoftware.Domain
File(s): /home/runner/work/mechanics-software/mechanics-software/src/MechanicsSoftware.Domain/ValueObjects/LicensePlate.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 37
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%88100%
GetEqualityComponents()100%11100%
ToString()100%11100%

File(s)

/home/runner/work/mechanics-software/mechanics-software/src/MechanicsSoftware.Domain/ValueObjects/LicensePlate.cs

#LineLine coverage
 1using System.Text.RegularExpressions;
 2using MechanicsSoftware.Domain.Exceptions;
 3
 4namespace MechanicsSoftware.Domain.ValueObjects;
 5
 6public sealed partial class LicensePlate : ValueObject
 7{
 8    [GeneratedRegex(@"^[A-Z]{3}[0-9][A-Z][0-9]{2}$")]
 9    private static partial Regex MercosulFormat();
 10
 11    [GeneratedRegex(@"^[A-Z]{3}[0-9]{4}$")]
 12    private static partial Regex LegacyFormat();
 13
 14    public string Value { get; }
 15
 10016    public LicensePlate(string value)
 10017    {
 10018        if (string.IsNullOrWhiteSpace(value))
 419            throw new DomainException("License plate cannot be empty.");
 20
 9621        var normalized = value.ToUpperInvariant();
 9622        if (normalized.Contains('-'))
 423            normalized = normalized.Replace("-", "");
 24
 9625        if (!MercosulFormat().IsMatch(normalized) && !LegacyFormat().IsMatch(normalized))
 1026            throw new DomainException($"'{value}' is not a valid Brazilian license plate.");
 27
 8628        Value = normalized;
 8629    }
 30
 31    protected override IEnumerable<object?> GetEqualityComponents()
 3232    {
 3233        yield return Value;
 2434    }
 35
 236    public override string ToString() => Value;
 37}