< Summary

Information
Class: FAU.DataAccess.Repositories.BancoRepository
Assembly: FAU.DataAccess
File(s): /home/runner/work/Sistema.Liquidacion.BE/Sistema.Liquidacion.BE/FAU.DataAccess/Repositories/BancoRepository.cs
Line coverage
100%
Covered lines: 45
Uncovered lines: 0
Coverable lines: 45
Total lines: 101
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%
GetByIdAsync()100%11100%
GetByCodigoAsync()100%11100%
GetPagedAsync()100%44100%
GetAllAsync()100%11100%
CreateAsync()100%11100%
UpdateAsync()100%11100%
DeleteAsync()100%22100%
ExistsAsync()100%11100%
ExistsByIdAsync()100%11100%

File(s)

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

#LineLine coverage
 1using FAU.Entidades;
 2using Microsoft.EntityFrameworkCore;
 3
 4namespace FAU.DataAccess.Repositories;
 5
 6public class BancoRepository : IBancoRepository
 7{
 8    private readonly ApplicationDbContext _context;
 9
 1310    public BancoRepository(ApplicationDbContext context)
 11    {
 1312        _context = context;
 1313    }
 14
 15    public async Task<Banco?> GetByIdAsync(long id)
 16    {
 417        return await _context.Bancos
 418            .FirstOrDefaultAsync(b => b.Id == id);
 419    }
 20
 21    public async Task<Banco?> GetByCodigoAsync(string codigo)
 22    {
 123        return await _context.Bancos
 124            .FirstOrDefaultAsync(b => b.Codigo == codigo);
 125    }
 26
 27    public async Task<(IEnumerable<Banco> Items, int TotalCount)> GetPagedAsync(
 28        int page,
 29        int pageSize,
 30        string? searchQuery = null,
 31        bool? vigente = null)
 32    {
 333        var query = _context.Bancos.AsQueryable();
 34
 35        // Filtrar por búsqueda (nombre o código)
 336        if (!string.IsNullOrWhiteSpace(searchQuery))
 37        {
 138            query = query.Where(b =>
 139                b.Nombre.ToLower().Contains(searchQuery.ToLower()) ||
 140                b.Codigo.ToLower().Contains(searchQuery.ToLower()));
 41        }
 42
 43        // Filtrar por estado vigente
 344        if (vigente.HasValue)
 45        {
 146            query = query.Where(b => b.Vigente == vigente.Value);
 47        }
 48
 349        var totalCount = await query.CountAsync();
 50
 351        var items = await query
 352            .OrderBy(b => b.Nombre)
 353            .Skip((page - 1) * pageSize)
 354            .Take(pageSize)
 355            .ToListAsync();
 56
 357        return (items, totalCount);
 358    }
 59
 60    public async Task<IEnumerable<Banco>> GetAllAsync()
 61    {
 162        return await _context.Bancos
 163            .OrderBy(b => b.Nombre)
 164            .ToListAsync();
 165    }
 66
 67    public async Task<Banco> CreateAsync(Banco banco)
 68    {
 3169        _context.Bancos.Add(banco);
 3170        await _context.SaveChangesAsync();
 3171        return banco;
 3172    }
 73
 74    public async Task<Banco> UpdateAsync(Banco banco)
 75    {
 176        _context.Bancos.Update(banco);
 177        await _context.SaveChangesAsync();
 178        return banco;
 179    }
 80
 81    public async Task DeleteAsync(long id)
 82    {
 183        var banco = await _context.Bancos.FindAsync(id);
 184        if (banco != null)
 85        {
 186            _context.Bancos.Remove(banco);
 187            await _context.SaveChangesAsync();
 88        }
 189    }
 90
 91    public async Task<bool> ExistsAsync(string codigo)
 92    {
 293        return await _context.Bancos.AnyAsync(b => b.Codigo == codigo);
 294    }
 95
 96    public async Task<bool> ExistsByIdAsync(long id)
 97    {
 198        return await _context.Bancos.AnyAsync(b => b.Id == id);
 199    }
 100}
 101