< 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
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 57
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
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%
GetAccionIdAsync()100%66100%
GetContextoIdAsync()100%66100%

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)
 812    private readonly ConcurrentDictionary<string, long> _acciones = new(StringComparer.OrdinalIgnoreCase);
 813    private readonly ConcurrentDictionary<string, long> _contextos = new(StringComparer.OrdinalIgnoreCase);
 14
 815    public AuditoriaCatalogoResolver(ApplicationDbContext context)
 16    {
 817        _context = context;
 818    }
 19
 20    public async Task<long> GetAccionIdAsync(string nombreAccion)
 21    {
 522        if (string.IsNullOrWhiteSpace(nombreAccion))
 123            throw new ArgumentException("El nombre de acción es requerido", nameof(nombreAccion));
 24
 425        if (_acciones.TryGetValue(nombreAccion, out var id))
 126            return id;
 27
 328        var accion = await _context.Set<FAU.Entidades.Accion>()
 329            .AsNoTracking()
 330            .FirstOrDefaultAsync(a => a.Nombre == nombreAccion);
 31
 332        if (accion == null)
 133            throw new InvalidOperationException($"No existe la acción '{nombreAccion}' en el catálogo de auditoría.");
 34
 235        _acciones[nombreAccion] = accion.Id;
 236        return accion.Id;
 337    }
 38
 39    public async Task<long> GetContextoIdAsync(string nombreContexto)
 40    {
 541        if (string.IsNullOrWhiteSpace(nombreContexto))
 142            throw new ArgumentException("El nombre de contexto es requerido", nameof(nombreContexto));
 43
 444        if (_contextos.TryGetValue(nombreContexto, out var id))
 145            return id;
 46
 347        var contexto = await _context.Set<FAU.Entidades.Contexto>()
 348            .AsNoTracking()
 349            .FirstOrDefaultAsync(c => c.Nombre == nombreContexto);
 50
 351        if (contexto == null)
 152            throw new InvalidOperationException($"No existe el contexto '{nombreContexto}' en el catálogo de auditoría."
 53
 254        _contextos[nombreContexto] = contexto.Id;
 255        return contexto.Id;
 356    }
 57}