< Summary

Information
Class: OzonRepositories.Data.BitrixStockAutoScheduleRepository
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/BitrixStockAutoScheduleRepository.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 36
Coverable lines: 36
Total lines: 78
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%
GetAllAsync()0%620%
GetByIdAsync(...)100%210%
AddAsync()100%210%
UpdateAsync()100%210%
DeleteAsync()0%620%
AddRunAsync()100%210%
UpdateRunAsync()100%210%
GetRunsAsync()100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/BitrixStockAutoScheduleRepository.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using OzonDomains.Models;
 3using OzonRepositories.Context;
 4
 5namespace OzonRepositories.Data;
 6
 7public class BitrixStockAutoScheduleRepository : IBitrixStockAutoScheduleRepository
 8{
 9    private readonly ApplicationDbContext _context;
 10
 011    public BitrixStockAutoScheduleRepository(ApplicationDbContext context)
 12    {
 013        _context = context;
 014    }
 15
 16    public async Task<List<BitrixStockAutoSchedule>> GetAllAsync(bool includeClient = false,
 17        CancellationToken cancellationToken = default)
 18    {
 019        var q = _context.BitrixStockAutoSchedules.AsQueryable();
 020        if (includeClient)
 21        {
 022            q = q.Include(s => s.OzonClient);
 23        }
 24
 025        return await q.OrderByDescending(s => s.CreatedAt).ToListAsync(cancellationToken);
 026    }
 27
 28    public Task<BitrixStockAutoSchedule?> GetByIdAsync(int id, CancellationToken cancellationToken = default) =>
 029        _context.BitrixStockAutoSchedules.Include(s => s.OzonClient).FirstOrDefaultAsync(s => s.Id == id, cancellationTo
 30
 31    public async Task<int> AddAsync(BitrixStockAutoSchedule schedule, CancellationToken cancellationToken = default)
 32    {
 033        schedule.CreatedAt = DateTime.UtcNow;
 034        schedule.UpdatedAt = DateTime.UtcNow;
 035        _context.BitrixStockAutoSchedules.Add(schedule);
 036        await _context.SaveChangesAsync(cancellationToken);
 037        return schedule.Id;
 038    }
 39
 40    public async Task UpdateAsync(BitrixStockAutoSchedule schedule, CancellationToken cancellationToken = default)
 41    {
 042        schedule.UpdatedAt = DateTime.UtcNow;
 043        _context.BitrixStockAutoSchedules.Update(schedule);
 044        await _context.SaveChangesAsync(cancellationToken);
 045    }
 46
 47    public async Task DeleteAsync(int id, CancellationToken cancellationToken = default)
 48    {
 049        var entity = await _context.BitrixStockAutoSchedules.FindAsync(new object[] { id }, cancellationToken);
 050        if (entity != null)
 51        {
 052            _context.BitrixStockAutoSchedules.Remove(entity);
 053            await _context.SaveChangesAsync(cancellationToken);
 54        }
 055    }
 56
 57    public async Task<BitrixStockAutoScheduleRun> AddRunAsync(BitrixStockAutoScheduleRun run,
 58        CancellationToken cancellationToken = default)
 59    {
 060        _context.BitrixStockAutoScheduleRuns.Add(run);
 061        await _context.SaveChangesAsync(cancellationToken);
 062        return run;
 063    }
 64
 65    public async Task UpdateRunAsync(BitrixStockAutoScheduleRun run, CancellationToken cancellationToken = default)
 66    {
 067        _context.BitrixStockAutoScheduleRuns.Update(run);
 068        await _context.SaveChangesAsync(cancellationToken);
 069    }
 70
 71    public async Task<List<BitrixStockAutoScheduleRun>> GetRunsAsync(int scheduleId, int take = 20,
 72        CancellationToken cancellationToken = default) =>
 073        await _context.BitrixStockAutoScheduleRuns.AsNoTracking()
 074            .Where(r => r.ScheduleId == scheduleId)
 075            .OrderByDescending(r => r.StartedAt)
 076            .Take(take)
 077            .ToListAsync(cancellationToken);
 78}