< 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
73%
Covered lines: 22
Uncovered lines: 8
Coverable lines: 30
Total lines: 62
Line coverage: 73.3%
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%111082.6%
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            .Include(b => b.Usuario)
 326            .Include(b => b.Accion)
 327            .Include(b => b.Contexto)
 328            .AsQueryable();
 29
 330        if (!string.IsNullOrWhiteSpace(contexto))
 131            query = query.Where(b => b.Contexto.Nombre == contexto);
 32
 333        if (!string.IsNullOrWhiteSpace(accion))
 034            query = query.Where(b => b.Accion.Nombre == accion);
 35
 336        if (!string.IsNullOrWhiteSpace(usuario))
 037            query = query.Where(b => b.Usuario.Username.Contains(usuario));
 38
 339        if (desde.HasValue)
 040            query = query.Where(b => b.Fecha >= desde.Value);
 41
 342        if (hasta.HasValue)
 043            query = query.Where(b => b.Fecha <= hasta.Value);
 44
 345        var total = await query.CountAsync();
 46
 347        var items = await query
 348            .OrderByDescending(b => b.Fecha)
 349            .Skip((page - 1) * pageSize)
 350            .Take(pageSize)
 351            .ToListAsync();
 52
 353        return (items, total);
 354    }
 55
 56    public async Task<BitacoraAuditoria> CreateAsync(BitacoraAuditoria bitacora)
 57    {
 058        _context.BitacorasAuditoria.Add(bitacora);
 059        await _context.SaveChangesAsync();
 060        return bitacora;
 061    }
 62}