< Summary - MechanicsSoftware — Coverage Report

Information
Class: MechanicsSoftware.Domain.ValueObjects.Money
Assembly: MechanicsSoftware.Domain
File(s): /home/runner/work/mechanics-software/mechanics-software/src/MechanicsSoftware.Domain/ValueObjects/Money.cs
Line coverage
95%
Covered lines: 20
Uncovered lines: 1
Coverable lines: 21
Total lines: 39
Line coverage: 95.2%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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%22100%
Add(...)100%11100%
Multiply(...)100%22100%
ToFormatted()100%11100%
GetEqualityComponents()100%11100%
ToString()100%210%

File(s)

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

#LineLine coverage
 1using MechanicsSoftware.Domain.Exceptions;
 2
 3namespace MechanicsSoftware.Domain.ValueObjects;
 4
 5public sealed class Money : ValueObject
 6{
 7    public int Cents { get; }
 8    public const string Currency = "BRL";
 9
 90210    public Money(int cents)
 90211    {
 90212        if (cents < 0)
 413            throw new DomainException("Money amount cannot be negative.");
 89814        Cents = cents;
 89815    }
 16
 19817    public Money Add(Money other) => new(Cents + other.Cents);
 18
 19    public Money Multiply(int factor)
 14420    {
 14421        if (factor < 0)
 222            throw new DomainException("Multiply factor cannot be negative.");
 14223        return new(Cents * factor);
 14224    }
 25
 26    public string ToFormatted()
 7627    {
 7628        var reais = Cents / 100;
 7629        var centavos = Cents % 100;
 7630        return $"R$ {reais},{centavos:D2}";
 7631    }
 32
 33    protected override IEnumerable<object?> GetEqualityComponents()
 2834    {
 2835        yield return Cents;
 2036    }
 37
 038    public override string ToString() => ToFormatted();
 39}