< Summary

Information
Class: OzonRepositories.Data.OrderHistoryRepository
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/OrderHistoryRepository.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 43
Coverable lines: 43
Total lines: 83
Line coverage: 0%
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
.ctor(...)100%210%
Add()100%210%
Delete()100%210%
Get()100%210%
GetAsync()100%210%
GetAsync()100%210%
Update()100%210%
GetByOrderIdAsync()100%210%
GetRecentChangesAsync()100%210%
GetChangesAfterDateAsync()100%210%

File(s)

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

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using OzonDomains.Models;
 3using OzonRepositories.Context;
 4
 5namespace OzonRepositories.Data;
 6
 7public class OrderHistoryRepository : MainRepository, IOrderHistoryRepository
 8    {
 09        public OrderHistoryRepository(ApplicationDbContext orderContext) : base(orderContext)
 10        {
 011        }
 12
 13        public async Task<int> Add(OrderHistory value)
 14        {
 015            _context.OrderHistories.Add(value);
 016            return await _context.SaveChangesAsync();
 017        }
 18
 19        public async Task<int> Delete(OrderHistory value)
 20        {
 021            _context.OrderHistories.Remove(value);
 022            return await _context.SaveChangesAsync();
 023        }
 24
 25        public Task<List<OrderHistory>> Get()
 26        {
 027            return _context.OrderHistories
 028                .Include(oh => oh.Order)
 029                .OrderByDescending(oh => oh.ChangedAt)
 030                .ToListAsync();
 31        }
 32
 33        public async Task<OrderHistory?> GetAsync(int id)
 34        {
 035            return await _context.OrderHistories
 036                .Include(oh => oh.Order)
 037                .FirstOrDefaultAsync(oh => oh.Id == id);
 038        }
 39
 40        public async Task<OrderHistory?> GetAsync(OrderHistory value)
 41        {
 042            return await _context.OrderHistories
 043                .FirstOrDefaultAsync(oh => oh.OrderId == value.OrderId &&
 044                                         oh.ColumnName == value.ColumnName &&
 045                                         oh.ChangedAt == value.ChangedAt);
 046        }
 47
 48        public async Task<int> Update(OrderHistory value)
 49        {
 050            _context.OrderHistories.Update(value);
 051            return await _context.SaveChangesAsync();
 052        }
 53
 54        public async Task<List<OrderHistory>> GetByOrderIdAsync(int orderId)
 55        {
 056            return await _context.OrderHistories
 057                .Where(oh => oh.OrderId == orderId)
 058                .Include(oh => oh.Order!)
 059                    .ThenInclude(c => c.OzonClient)
 060                .Include(oh => oh.Order!)
 061                    .ThenInclude(o => o.ProductInfo)
 062                .OrderByDescending(oh => oh.ChangedAt)
 063                .ToListAsync();
 064        }
 65
 66        public async Task<List<OrderHistory>> GetRecentChangesAsync(int count = 50)
 67        {
 068            return await _context.OrderHistories
 069                .OrderByDescending(oh => oh.ChangedAt)
 070                .Take(count)
 071                .ToListAsync();
 072        }
 73
 74        public async Task<List<OrderHistory>> GetChangesAfterDateAsync(DateTime afterDate)
 75        {
 076            return await _context.OrderHistories
 077                .Where(oh => oh.ChangedAt > afterDate)
 078                .OrderByDescending(oh => oh.ChangedAt)
 079                .ToListAsync();
 080        }
 81
 82
 83    }