< Summary

Information
Class: FAU.DataAccess.Repositories.AuditoriaRepository
Assembly: FAU.DataAccess
File(s): /home/runner/work/Sistema.Liquidacion.BE/Sistema.Liquidacion.BE/FAU.DataAccess/Repositories/AuditoriaRepository.cs
Line coverage
74%
Covered lines: 23
Uncovered lines: 8
Coverable lines: 31
Total lines: 63
Line coverage: 74.1%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetPagedAsync()60%101083.33%
CreateAsync()100%210%

File(s)

/home/runner/work/Sistema.Liquidacion.BE/Sistema.Liquidacion.BE/FAU.DataAccess/Repositories/AuditoriaRepository.cs

#LineLine coverage
 1using FAU.Entidades;
 2using Microsoft.EntityFrameworkCore;
 3
 4namespace FAU.DataAccess.Repositories;
 5
 6public class AuditoriaRepository : IAuditoriaRepository
 7{
 8    private readonly ApplicationDbContext _context;
 9
 310    public AuditoriaRepository(ApplicationDbContext context)
 11    {
 312        _context = context;
 313    }
 14
 15    public async Task<(IEnumerable<BitacoraAuditoria> Items, int TotalCount)> GetPagedAsync(
 16        int page,
 17        int pageSize,
 18        string? contexto = null,
 19        string? accion = null,
 20        string? usuario = null,
 21        DateTime? desde = null,
 22        DateTime? hasta = null)
 23    {
 324        var query = _context.BitacorasAuditoria
 325            .Where(b => b.Aplicacion == "liquidacion")
 326            .Include(b => b.Usuario)
 327            .Include(b => b.Accion)
 328            .Include(b => b.Contexto)
 329            .AsQueryable();
 30
 331        if (!string.IsNullOrWhiteSpace(contexto))
 132            query = query.Where(b => b.Contexto.Nombre == contexto);
 33
 334        if (!string.IsNullOrWhiteSpace(accion))
 035            query = query.Where(b => b.Accion.Nombre == accion);
 36
 337        if (!string.IsNullOrWhiteSpace(usuario))
 038            query = query.Where(b => b.Usuario.Username.Contains(usuario));
 39
 340        if (desde.HasValue)
 041            query = query.Where(b => b.Fecha >= desde.Value);
 42
 343        if (hasta.HasValue)
 044            query = query.Where(b => b.Fecha <= hasta.Value);
 45
 346        var total = await query.CountAsync();
 47
 348        var items = await query
 349            .OrderByDescending(b => b.Fecha)
 350            .Skip((page - 1) * pageSize)
 351            .Take(pageSize)
 352            .ToListAsync();
 53
 354        return (items, total);
 355    }
 56
 57    public async Task<BitacoraAuditoria> CreateAsync(BitacoraAuditoria bitacora)
 58    {
 059        _context.BitacorasAuditoria.Add(bitacora);
 060        await _context.SaveChangesAsync();
 061        return bitacora;
 062    }
 63}