< Summary

Information
Class: FAU.Logica.Services.AuditoriaCatalogoResolver
Assembly: FAU.Logica
File(s): /home/runner/work/Sistema.Liquidacion.BE/Sistema.Liquidacion.BE/FAU.Logica/Services/AuditoriaCatalogoResolver.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 57
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetAccionIdAsync()0%4260%
GetContextoIdAsync()0%4260%

File(s)

/home/runner/work/Sistema.Liquidacion.BE/Sistema.Liquidacion.BE/FAU.Logica/Services/AuditoriaCatalogoResolver.cs

#LineLine coverage
 1using System.Collections.Concurrent;
 2using FAU.DataAccess;
 3using Microsoft.EntityFrameworkCore;
 4
 5namespace FAU.Logica.Services;
 6
 7public sealed class AuditoriaCatalogoResolver : IAuditoriaCatalogoResolver
 8{
 9    private readonly ApplicationDbContext _context;
 10
 11    // Cache por nombre (case-insensitive)
 012    private readonly ConcurrentDictionary<string, long> _acciones = new(StringComparer.OrdinalIgnoreCase);
 013    private readonly ConcurrentDictionary<string, long> _contextos = new(StringComparer.OrdinalIgnoreCase);
 14
 015    public AuditoriaCatalogoResolver(ApplicationDbContext context)
 16    {
 017        _context = context;
 018    }
 19
 20    public async Task<long> GetAccionIdAsync(string nombreAccion)
 21    {
 022        if (string.IsNullOrWhiteSpace(nombreAccion))
 023            throw new ArgumentException("El nombre de acción es requerido", nameof(nombreAccion));
 24
 025        if (_acciones.TryGetValue(nombreAccion, out var id))
 026            return id;
 27
 028        var accion = await _context.Set<FAU.Entidades.Accion>()
 029            .AsNoTracking()
 030            .FirstOrDefaultAsync(a => a.Nombre == nombreAccion);
 31
 032        if (accion == null)
 033            throw new InvalidOperationException($"No existe la acción '{nombreAccion}' en el catálogo de auditoría.");
 34
 035        _acciones[nombreAccion] = accion.Id;
 036        return accion.Id;
 037    }
 38
 39    public async Task<long> GetContextoIdAsync(string nombreContexto)
 40    {
 041        if (string.IsNullOrWhiteSpace(nombreContexto))
 042            throw new ArgumentException("El nombre de contexto es requerido", nameof(nombreContexto));
 43
 044        if (_contextos.TryGetValue(nombreContexto, out var id))
 045            return id;
 46
 047        var contexto = await _context.Set<FAU.Entidades.Contexto>()
 048            .AsNoTracking()
 049            .FirstOrDefaultAsync(c => c.Nombre == nombreContexto);
 50
 051        if (contexto == null)
 052            throw new InvalidOperationException($"No existe el contexto '{nombreContexto}' en el catálogo de auditoría."
 53
 054        _contextos[nombreContexto] = contexto.Id;
 055        return contexto.Id;
 056    }
 57}