< Summary

Information
Class: FAU.DataAccess.Repositories.RolRepository
Assembly: FAU.DataAccess
File(s): /home/runner/work/Sistema.Liquidacion.BE/Sistema.Liquidacion.BE/FAU.DataAccess/Repositories/RolRepository.cs
Line coverage
78%
Covered lines: 26
Uncovered lines: 7
Coverable lines: 33
Total lines: 71
Line coverage: 78.7%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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%
GetByNombreAsync()100%210%
GetByNombreWithPermisosAsync()100%210%
GetAllAsync()100%11100%
CreateAsync()100%11100%
UpdateAsync()100%11100%
DeleteAsync()100%22100%
ExistsAsync()100%11100%

File(s)

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

#LineLine coverage
 1using FAU.Entidades;
 2using Microsoft.EntityFrameworkCore;
 3
 4namespace FAU.DataAccess.Repositories;
 5
 6public class RolRepository : IRolRepository
 7{
 8    private readonly ApplicationDbContext _context;
 9
 910    public RolRepository(ApplicationDbContext context)
 11    {
 912        _context = context;
 913    }
 14
 15    public async Task<Rol?> GetByIdAsync(long id)
 16    {
 217        return await _context.Roles
 218            .Include(r => r.Permisos)
 219            .FirstOrDefaultAsync(r => r.Id == id);
 220    }
 21
 22    public async Task<Rol?> GetByNombreAsync(string nombre)
 23    {
 024        return await _context.Roles
 025            .FirstOrDefaultAsync(r => r.Nombre == nombre);
 026    }
 27
 28    public async Task<Rol?> GetByNombreWithPermisosAsync(string nombre)
 29    {
 030        return await _context.Roles
 031            .Include(r => r.Permisos)
 032            .FirstOrDefaultAsync(r => r.Nombre == nombre);
 033    }
 34
 35    public async Task<IEnumerable<Rol>> GetAllAsync()
 36    {
 237        return await _context.Roles
 238            .Include(r => r.Permisos)
 239            .ToListAsync();
 240    }
 41
 42    public async Task<Rol> CreateAsync(Rol rol)
 43    {
 144        _context.Roles.Add(rol);
 145        await _context.SaveChangesAsync();
 146        return rol;
 147    }
 48
 49    public async Task<Rol> UpdateAsync(Rol rol)
 50    {
 151        _context.Roles.Update(rol);
 152        await _context.SaveChangesAsync();
 153        return rol;
 154    }
 55
 56    public async Task DeleteAsync(long id)
 57    {
 158        var rol = await _context.Roles.FindAsync(id);
 159        if (rol != null)
 60        {
 161            _context.Roles.Remove(rol);
 162            await _context.SaveChangesAsync();
 63        }
 164    }
 65
 66    public async Task<bool> ExistsAsync(string nombre)
 67    {
 268        return await _context.Roles.AnyAsync(r => r.Nombre == nombre);
 269    }
 70}
 71