< Summary

Information
Class: Repository.Persistency.Implementations.AcessoRepositorioImpl
Assembly: Despesas.Repository
File(s): /src/Despesas.Repository/Persistency/Implementations/AcessoRepositorioImpl.cs
Line coverage
92%
Covered lines: 47
Uncovered lines: 4
Coverable lines: 51
Total lines: 76
Line coverage: 92.1%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Context()100%11100%
.ctor(...)100%11100%
Create()100%11100%
RecoveryPassword()100%11100%
ChangePassword()50%22100%
RevokeRefreshToken()100%22100%
FindByRefreshToken()100%11100%
RefreshTokenInfo()100%11100%
Find()100%11100%

File(s)

/src/Despesas.Repository/Persistency/Implementations/AcessoRepositorioImpl.cs

#LineLine coverage
 1using Domain.Entities;
 2using Microsoft.EntityFrameworkCore;
 3using Repository.Persistency.Abstractions;
 4using System.Linq.Expressions;
 5
 6namespace Repository.Persistency.Implementations;
 7public class AcessoRepositorioImpl : IAcessoRepositorioImpl
 8{
 339    public RegisterContext Context { get; }
 10
 1011    public AcessoRepositorioImpl(RegisterContext context)
 1012    {
 1013        Context = context;
 1014    }
 15
 16    public async Task Create(Acesso acesso)
 217    {
 218        acesso.Usuario.PerfilUsuario = Context.PerfilUsuario.First(p => p.Id == acesso.Usuario.PerfilUsuario.Id);
 219        acesso.Usuario.Categorias.ToList().ForEach(c =>
 020        {
 021            var tipoCategoria = Context.TipoCategoria.FirstOrDefault(tc => tc.Id == c.TipoCategoria.Id);
 022            if (tipoCategoria != null)
 023                c.TipoCategoria = tipoCategoria;
 224        });
 225        Context.Acesso.Add(acesso);
 226        await Context.SaveChangesAsync();
 127    }
 28
 29    public async Task RecoveryPassword(string email, string newPassword)
 130    {
 131        var entity = Context.Acesso.First(c => c.Login.Equals(email));
 132        entity.Senha = newPassword;
 133        Context.Update(entity);
 134        await Context.SaveChangesAsync();
 135    }
 36
 37    public async Task ChangePassword(Guid idUsuario, string password)
 238    {
 239        var usuario = Context.Acesso.Include(u => u.Usuario).SingleOrDefault(prop => prop.UsuarioId.Equals(idUsuario))
 240            ?? throw new();
 41
 242        var acesso = Context.Acesso.First(c => c.Login.Equals(usuario.Login));
 243        acesso.Senha = password;
 244        Context.Acesso.Update(acesso);
 245        await Context.SaveChangesAsync();
 246    }
 47
 48    public async Task RevokeRefreshToken(Guid idUsuario)
 349    {
 350        var acesso = Context.Acesso.FirstOrDefault(prop => prop.Id.Equals(idUsuario));
 451        if (acesso is null) throw new ArgumentException("Token inexistente!");
 252        acesso.RefreshToken = String.Empty;
 253        acesso.RefreshTokenExpiry = null;
 254        Context.Acesso.Update(acesso);
 255        await Context.SaveChangesAsync();
 256    }
 57
 58    public async Task<Acesso> FindByRefreshToken(string refreshToken)
 159    {
 160        return await Context.Acesso
 161            .Include(x => x.Usuario)
 162            .ThenInclude(u => u.PerfilUsuario)
 163            .FirstAsync(prop => prop.RefreshToken.Equals(refreshToken));
 164    }
 65
 66    public async Task RefreshTokenInfo(Acesso acesso)
 167    {
 168        Context.Acesso.Update(acesso);
 169        await Context.SaveChangesAsync();
 170    }
 71
 72    public async Task<Acesso?> Find(Expression<Func<Acesso, bool>> expression)
 673    {
 674        return await Context.Acesso.Include(c => c.Usuario).Include(c => c.Usuario.PerfilUsuario).SingleOrDefaultAsync(e
 675    }
 76}