< Summary

Information
Class: Repository.Abastractions.BaseRepository<T>
Assembly: Despesas.Repository
File(s): /src/Despesas.Repository/Abstractions/BaseRepository.cs
Line coverage
100%
Covered lines: 32
Uncovered lines: 0
Coverable lines: 32
Total lines: 58
Line coverage: 100%
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
get_Context()100%11100%
.ctor(...)100%11100%
Insert(...)100%11100%
Update(...)100%11100%
Delete(...)100%11100%
GetAll()100%11100%
Get(...)100%11100%
Find(...)100%11100%
Exists(...)100%11100%
Exists(...)100%11100%

File(s)

/src/Despesas.Repository/Abstractions/BaseRepository.cs

#LineLine coverage
 1using Domain.Core.Aggreggates;
 2using Microsoft.EntityFrameworkCore;
 3using System.Linq.Expressions;
 4
 5namespace Repository.Abastractions;
 6
 7public abstract class BaseRepository<T> where T : BaseDomain, new()
 8{
 519    private DbContext Context { get; set; }
 10
 4011    protected BaseRepository(DbContext context)
 4012    {
 4013        Context = context;
 4014    }
 15
 16    public virtual void Insert(T entity)
 117    {
 118        Context.Add(entity);
 119        Context.SaveChanges();
 120    }
 21
 22    public virtual void Update(T entity)
 123    {
 124        Context.Update(entity);
 125        Context.SaveChanges();
 126    }
 27
 28    public virtual void Delete(T entity)
 129    {
 130        Context.Remove(entity);
 131        Context.SaveChanges();
 132    }
 33
 34    public virtual IEnumerable<T> GetAll()
 135    {
 136        return Context.Set<T>().ToList();
 137    }
 38
 39    public virtual T Get(Guid id)
 240    {
 241        return Context.Set<T>().Find(id);
 242    }
 43
 44    public virtual IEnumerable<T> Find(Expression<Func<T, bool>> expression)
 245    {
 246        return Context.Set<T>().Where(expression);
 247    }
 48
 49    public virtual bool Exists(Guid id)
 150    {
 151        return this.Get(id) != null;
 152    }
 53
 54    public virtual bool Exists(Expression<Func<T, bool>> expression)
 155    {
 156        return Find(expression).Any();
 157    }
 58}