< Summary - MechanicsSoftware — Coverage Report

Information
Class: MechanicsSoftware.Domain.Entities.Vehicle
Assembly: MechanicsSoftware.Domain
File(s): /home/runner/work/mechanics-software/mechanics-software/src/MechanicsSoftware.Domain/Entities/Vehicle.cs
Line coverage
100%
Covered lines: 38
Uncovered lines: 0
Coverable lines: 38
Total lines: 73
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
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%11100%
Create(...)100%44100%
Update(...)100%11100%
ValidateFields(...)100%88100%
UpdateLicensePlate(...)100%22100%

File(s)

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

#LineLine coverage
 1using MechanicsSoftware.Domain.Exceptions;
 2using MechanicsSoftware.Domain.ValueObjects;
 3
 4namespace MechanicsSoftware.Domain.Entities;
 5
 6public sealed class Vehicle : Entity<Guid>
 7{
 8    public LicensePlate LicensePlate { get; private set; } = null!;
 9    public string Make { get; private set; } = null!;
 10    public string Model { get; private set; } = null!;
 11    public int Year { get; private set; }
 12    public Guid CustomerId { get; private set; }
 13
 21614    private Vehicle() { }
 15
 16    public static Vehicle Create(
 17        Guid id,
 18        LicensePlate licensePlate,
 19        string make,
 20        string model,
 21        int year,
 22        Guid customerId)
 8823    {
 8824        if (licensePlate is null)
 225            throw new DomainException("License plate is required.");
 26
 8627        if (customerId == Guid.Empty)
 228            throw new DomainException("CustomerId is required.");
 29
 8430        var (trimmedMake, trimmedModel) = ValidateFields(make, model, year);
 31
 7232        return new Vehicle
 7233        {
 7234            Id = id,
 7235            LicensePlate = licensePlate,
 7236            Make = trimmedMake,
 7237            Model = trimmedModel,
 7238            Year = year,
 7239            CustomerId = customerId
 7240        };
 7241    }
 42
 43    public void Update(string make, string model, int year)
 1644    {
 1645        var (trimmedMake, trimmedModel) = ValidateFields(make, model, year);
 646        Make = trimmedMake;
 647        Model = trimmedModel;
 648        Year = year;
 649    }
 50
 51    private static (string Make, string Model) ValidateFields(string make, string model, int year)
 10052    {
 10053        if (string.IsNullOrWhiteSpace(make))
 854            throw new DomainException("Make is required.");
 55
 9256        if (string.IsNullOrWhiteSpace(model))
 857            throw new DomainException("Model is required.");
 58
 8459        var currentYear = DateTime.UtcNow.Year;
 8460        if (year < 1886 || year > currentYear + 1)
 661            throw new DomainException($"Year must be between 1886 and {currentYear + 1}.");
 62
 7863        return (make.Trim(), model.Trim());
 7864    }
 65
 66    public void UpdateLicensePlate(LicensePlate newLicensePlate)
 467    {
 468        if (newLicensePlate is null)
 269            throw new DomainException("License plate is required.");
 70
 271        LicensePlate = newLicensePlate;
 272    }
 73}