< Summary

Information
Class: Repository.Persistency.Generic.GenericRepositorio<T>
Assembly: Despesas.Repository
File(s): /src/Despesas.Repository/Persistency/Abstractions/Generic/GenericRepositorio.cs
Line coverage
79%
Covered lines: 23
Uncovered lines: 6
Coverable lines: 29
Total lines: 52
Line coverage: 79.3%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Insert(...)100%11100%
GetAll()100%11100%
Get(...)100%11100%
Update(...)100%11100%
Delete(...)100%11100%
Exists(...)100%210%
Find(...)100%210%

File(s)

/src/Despesas.Repository/Persistency/Abstractions/Generic/GenericRepositorio.cs

#LineLine coverage
 1using Domain.Core.Aggreggates;
 2using System.Linq.Expressions;
 3
 4namespace Repository.Persistency.Generic;
 5public class GenericRepositorio<T> : IRepositorio<T> where T : BaseDomain, new()
 6{
 7    protected readonly RegisterContext _context;
 8
 99    public GenericRepositorio(RegisterContext context)
 910    {
 911        this._context = context;
 912    }
 13
 14    public virtual void Insert(T item)
 215    {
 216        this._context.Add(item);
 217        this._context.SaveChanges();
 218    }
 19
 20    public virtual List<T> GetAll()
 121    {
 122        return this._context.Set<T>().ToList();
 123    }
 24
 25    public virtual T Get(Guid id)
 126    {
 127        return this._context.Set<T>().SingleOrDefault(prop => prop.Id.Equals(id));
 128    }
 29
 30    public virtual void Update(T entity)
 231    {
 232        var existingEntity = _context.Set<T>().Find(entity.Id);
 233        this._context.Set<T>().Entry(existingEntity).CurrentValues.SetValues(entity);
 134        this._context.SaveChanges();
 135    }
 36
 37    public virtual void Delete(T entity)
 238    {
 239        this._context.Set<T>().Remove(entity);
 140        this._context.SaveChanges();
 141    }
 42
 43    public virtual bool Exists(Guid id)
 044    {
 045        return this._context.Set<T>().Any(prop => prop.Id.Equals(id));
 046    }
 47
 48    public IEnumerable<T>? Find(Expression<Func<T, bool>> expression)
 049    {
 050        return this._context.Set<T>().Where(expression);
 051    }
 52}