< Summary

Information
Class: LifeChart.Infrastructure.Repositories.DailyEntryRepository
Assembly: LifeChart.Infrastructure
File(s): /home/runner/work/lifechart/lifechart/src/LifeChart.Infrastructure/Repositories/DailyEntryRepository.cs
Tag: 113_29159449707
Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 37
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetByDateAsync()100%210%
GetRangeAsync()100%210%
ExistsForTodayAsync()100%210%
SaveAsync()0%620%

File(s)

/home/runner/work/lifechart/lifechart/src/LifeChart.Infrastructure/Repositories/DailyEntryRepository.cs

#LineLine coverage
 1using LifeChart.Domain.Entries;
 2using LifeChart.Infrastructure.Persistence;
 3using Microsoft.EntityFrameworkCore;
 4
 5namespace LifeChart.Infrastructure.Repositories;
 6
 7public class DailyEntryRepository : IDailyEntryRepository
 8{
 9    private readonly LifeChartDbContext _context;
 10
 011    public DailyEntryRepository(LifeChartDbContext context)
 012        => _context = context;
 13
 14    public async Task<DailyEntry?> GetByDateAsync(DateOnly date)
 015        => await _context.DailyEntries.FirstOrDefaultAsync(e => e.Date == date);
 16
 17    public async Task<IEnumerable<DailyEntry>> GetRangeAsync(DateOnly from, DateOnly to)
 018        => await _context.DailyEntries
 019            .Where(e => e.Date >= from && e.Date <= to)
 020            .OrderBy(e => e.Date)
 021            .ToListAsync();
 22
 23    public async Task<bool> ExistsForTodayAsync()
 024        => await _context.DailyEntries
 025            .AnyAsync(e => e.Date == DateOnly.FromDateTime(DateTime.Today));
 26
 27    public async Task SaveAsync(DailyEntry entry)
 28    {
 029        var existing = await GetByDateAsync(entry.Date);
 030        if (existing is null)
 031            _context.DailyEntries.Add(entry);
 32        else
 033            _context.Entry(existing).CurrentValues.SetValues(entry);
 34
 035        await _context.SaveChangesAsync();
 036    }
 37}