< Summary - MechanicsSoftware — Coverage Report

Information
Class: MechanicsSoftware.Application.UseCases.Customers.Handlers.CreateCustomerHandler
Assembly: MechanicsSoftware.Application
File(s): /home/runner/work/mechanics-software/mechanics-software/src/MechanicsSoftware.Application/UseCases/Customers/Handlers/CreateCustomerHandler.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 35
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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%
ExecuteAsync()100%22100%

File(s)

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

#LineLine coverage
 1using MechanicsSoftware.Application.Abstractions;
 2using MechanicsSoftware.Application.UseCases.Customers.Commands;
 3using MechanicsSoftware.Domain.Entities;
 4using MechanicsSoftware.Domain.Exceptions;
 5using MechanicsSoftware.Domain.ValueObjects;
 6using Microsoft.EntityFrameworkCore;
 7
 8namespace MechanicsSoftware.Application.UseCases.Customers.Handlers;
 9
 410public sealed class CreateCustomerHandler(IAppDbContext db)
 11{
 12    public async Task<CustomerResponse> ExecuteAsync(CreateCustomerCommand command, CancellationToken cancellationToken 
 413    {
 414        var documentVo = new TaxId(command.DocumentValue, command.PersonType);
 15
 416        var customerExisting = await db.Customers
 417            .AnyAsync(c => c.Document == documentVo, cancellationToken);
 18
 419        if (customerExisting)
 220            throw new DomainException($"A customer with document '{command.DocumentValue}' already exists.");
 21
 222        var customer = Customer.Create(
 223            id: Guid.NewGuid(),
 224            personType: command.PersonType,
 225            taxId: command.DocumentValue,
 226            name: command.Name,
 227            email: command.Email,
 228            phone: command.Phone);
 29
 230        db.Customers.Add(customer);
 231        await db.SaveChangesAsync(cancellationToken);
 32
 233        return CustomerResponse.From(customer);
 234    }
 35}