< Summary

Information
Class: OzonRepositories.Data.ProductRepository
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/ProductRepository.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 28
Coverable lines: 28
Total lines: 62
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%
Add()100%210%
Delete()100%210%
Get()100%210%
GetAsync()100%210%
GetAsync()100%210%
Update()100%210%
GetImageUrlsByArticlesAsync()0%620%

File(s)

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

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using OzonDomains.Models;
 3using OzonRepositories.Context;
 4
 5namespace OzonRepositories.Data
 6{
 7    public class ProductRepository : MainRepository, IRepository<Product>
 8    {
 09        public ProductRepository(ApplicationDbContext orderContext) : base(orderContext)
 10        {
 011        }
 12
 13        public async Task<int> Add(Product value)
 14        {
 015            await _context.Products.AddAsync(value);
 016            return await _context.SaveChangesAsync();
 017        }
 18
 19        public async Task<int> Delete(Product value)
 20        {
 021            _context.Products.Remove(value);
 022            return await _context.SaveChangesAsync();
 023        }
 24
 25        public async Task<List<Product>> Get()
 26        {
 027            await Task.CompletedTask;
 028            return _context.Products.ToList();
 029        }
 30
 31        public async Task<Product?> GetAsync(int id)
 32        {
 033            return await _context.Products.FirstOrDefaultAsync(p => p.Id == id);
 034        }
 35
 36        public async Task<Product?> GetAsync(Product value)
 37        {
 038            return await _context.Products.FirstOrDefaultAsync(p => p.Article == value.Article);
 039        }
 40
 41        public async Task<int> Update(Product value)
 42        {
 043            _context.Products.Update(value);
 044            return await _context.SaveChangesAsync();
 045        }
 46
 47        /// <summary>Словарь article → ImageUrl для списка артикулов. Только записи с непустым ImageUrl.</summary>
 48        public async Task<Dictionary<string, string>> GetImageUrlsByArticlesAsync(IEnumerable<string> articles)
 49        {
 050            var articleList = articles.Where(a => !string.IsNullOrWhiteSpace(a)).Distinct().ToList();
 051            if (articleList.Count == 0)
 052                return new Dictionary<string, string>();
 53
 054            return await _context.Products
 055                .Where(p => p.Article != null && articleList.Contains(p.Article) && p.ImageUrl != null)
 056                .Select(p => new { p.Article, p.ImageUrl })
 057                .ToDictionaryAsync(
 058                    p => p.Article!,
 059                    p => p.ImageUrl!);
 060        }
 61    }
 62}