< Summary

Information
Class: OzonRepositories.Data.OrderHistoryOneCPostingRepository
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/OrderHistoryOneCPostingRepository.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: 8
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%
GetByOrderIdAsync()100%210%
GetHistoryIdsInWindowAsync()0%620%
GetMaxChangedAtInWindowAsync()0%620%
GetLatestHistoryInWindowAsync()0%620%
AddPostingsAsync()0%620%

File(s)

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

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using OzonDomains.Models;
 3using OzonRepositories.Context;
 4
 5namespace OzonRepositories.Data;
 6
 7public class OrderHistoryOneCPostingRepository : MainRepository, IOrderHistoryOneCPostingRepository
 8{
 09    public OrderHistoryOneCPostingRepository(ApplicationDbContext context) : base(context)
 10    {
 011    }
 12
 13    public async Task<List<OrderHistoryOneCPosting>> GetByOrderIdAsync(int orderId)
 14    {
 015        return await _context.OrderHistoryOneCPostings
 016            .AsNoTracking()
 017            .Include(p => p.HistoryLinks)
 018            .Where(p => p.OrderId == orderId)
 019            .OrderByDescending(p => p.PostedAt)
 020            .ToListAsync();
 021    }
 22
 23    public async Task<List<int>> GetHistoryIdsInWindowAsync(
 24        int orderId,
 25        DateTime windowStart,
 26        DateTime windowEnd,
 27        string? changedBy)
 28    {
 029        var query = _context.OrderHistories
 030            .AsNoTracking()
 031            .Where(h => h.OrderId == orderId && h.ChangedAt >= windowStart && h.ChangedAt <= windowEnd);
 32
 033        if (!string.IsNullOrWhiteSpace(changedBy))
 034            query = query.Where(h => h.ChangedBy == changedBy);
 35
 036        return await query.Select(h => h.Id).ToListAsync();
 037    }
 38
 39    public async Task<DateTime?> GetMaxChangedAtInWindowAsync(
 40        int orderId,
 41        DateTime windowStart,
 42        DateTime windowEnd,
 43        string? changedBy)
 44    {
 045        var query = _context.OrderHistories
 046            .AsNoTracking()
 047            .Where(h => h.OrderId == orderId && h.ChangedAt >= windowStart && h.ChangedAt <= windowEnd);
 48
 049        if (!string.IsNullOrWhiteSpace(changedBy))
 050            query = query.Where(h => h.ChangedBy == changedBy);
 51
 052        return await query.MaxAsync(h => (DateTime?)h.ChangedAt);
 053    }
 54
 55    public async Task<(DateTime? ChangedAt, string? ChangedBy)?> GetLatestHistoryInWindowAsync(
 56        int orderId,
 57        DateTime windowStart,
 58        DateTime windowEnd)
 59    {
 060        var row = await _context.OrderHistories
 061            .AsNoTracking()
 062            .Where(h => h.OrderId == orderId && h.ChangedAt >= windowStart && h.ChangedAt <= windowEnd)
 063            .OrderByDescending(h => h.ChangedAt)
 064            .Select(h => new { h.ChangedAt, h.ChangedBy })
 065            .FirstOrDefaultAsync();
 66
 067        return row == null ? null : (row.ChangedAt, row.ChangedBy);
 068    }
 69
 70    public async Task AddPostingsAsync(IReadOnlyList<OrderHistoryOneCPosting> postings)
 71    {
 072        if (postings.Count == 0)
 073            return;
 74
 075        await _context.OrderHistoryOneCPostings.AddRangeAsync(postings);
 076        await _context.SaveChangesAsync();
 077    }
 78}