< Summary

Information
Class: Despesas.Repository.UnitOfWork.Abstractions.BaseUnitOfWork<T>
Assembly: Despesas.Repository
File(s): /src/Despesas.Repository/UnitOfWork/Abstractions/BaseUnitOfWork.cs
Line coverage
100%
Covered lines: 25
Uncovered lines: 0
Coverable lines: 25
Total lines: 49
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

/src/Despesas.Repository/UnitOfWork/Abstractions/BaseUnitOfWork.cs

#LineLine coverage
 1using Domain.Core.Aggreggates;
 2using Microsoft.EntityFrameworkCore;
 3using Repository;
 4using System.Linq.Expressions;
 5
 6namespace Despesas.Repository.UnitOfWork.Abstractions;
 7
 8public sealed class BaseUnitOfWork<T> : IUnitOfWorkRepository<T> where T : BaseDomain
 9{
 10    protected readonly RegisterContext Context;
 11
 812    public BaseUnitOfWork(RegisterContext context)
 813    {
 814        Context = context;
 815    }
 16
 17    public async Task<T?> Get(Guid entityId)
 218    {
 219        return await Context.Set<T>().FindAsync(entityId);
 220    }
 21
 22    public async Task<IEnumerable<T>> GetAll()
 123    {
 124        return await Context.Set<T>().ToListAsync();
 125    }
 26
 27    public async Task Insert(T entity)
 228    {
 229        await Context.Set<T>().AddAsync(entity);
 230    }
 31
 32    public async Task Update(T entity)
 133    {
 134        var existingEntity = await Context.Set<T>().FirstOrDefaultAsync(c => c.Id.Equals(entity.Id));
 135        Context?.Entry(existingEntity).CurrentValues.SetValues(entity);
 136    }
 37
 38    public async Task Delete(Guid entityId)
 139    {
 140        var entity = await Get(entityId);
 141        if (entity != null)
 142            Context.Set<T>().Remove(entity);
 143    }
 44
 45    public async Task<IEnumerable<T>> Find(Expression<Func<T, bool>> expression)
 146    {
 147        return await Context.Set<T>().Where(expression).ToListAsync();
 148    }
 49}