< Summary - MechanicsSoftware — Coverage Report

Information
Class: MechanicsSoftware.Application.UseCases.Customers.Handlers.ListCustomersHandler
Assembly: MechanicsSoftware.Application
File(s): /home/runner/work/mechanics-software/mechanics-software/src/MechanicsSoftware.Application/UseCases/Customers/Handlers/ListCustomersHandler.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 32
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExecuteAsync()83.33%66100%

File(s)

/home/runner/work/mechanics-software/mechanics-software/src/MechanicsSoftware.Application/UseCases/Customers/Handlers/ListCustomersHandler.cs

#LineLine coverage
 1using MechanicsSoftware.Application.Abstractions;
 2using MechanicsSoftware.Application.UseCases.Customers.Queries;
 3using MechanicsSoftware.Domain.Enums;
 4using MechanicsSoftware.Domain.ValueObjects;
 5using Microsoft.EntityFrameworkCore;
 6
 7namespace MechanicsSoftware.Application.UseCases.Customers.Handlers;
 8
 89public sealed class ListCustomersHandler(IAppDbContext db)
 10{
 11    public async Task<IReadOnlyList<CustomerResponse>> ExecuteAsync(
 12        ListCustomersQuery query,
 13        CancellationToken cancellationToken = default)
 814    {
 815        var customers = db.Customers.AsQueryable();
 16
 817        if (!string.IsNullOrWhiteSpace(query.Name))
 218            customers = customers.Where(c => c.Name.Contains(query.Name.Trim()));
 19
 820        if (!string.IsNullOrWhiteSpace(query.Document))
 221        {
 222            var digits = string.Concat(query.Document.Where(char.IsDigit));
 223            var pt = digits.Length == 14 ? PersonType.COMPANY : PersonType.INDIVIDUAL;
 224            var documentVo = new TaxId(digits, pt);
 225            customers = customers.Where(c => c.Document == documentVo);
 226        }
 27
 828        return await customers
 829            .Select(c => CustomerResponse.From(c))
 830            .ToListAsync(cancellationToken);
 831    }
 32}