< Summary

Information
Class: OzonRepositories.Data.SupplierRepository
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Data/SupplierRepository.cs
Line coverage
100%
Covered lines: 25
Uncovered lines: 0
Coverable lines: 25
Total lines: 67
Line coverage: 100%
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%11100%
Add()100%11100%
Delete()100%11100%
Get()100%11100%
GetAsync()100%11100%
GetAsyncNoTracking()100%11100%
GetAsync()100%11100%
GetByNameAsync()100%11100%
GetBySiteAsync()100%11100%
GetWithUrls()100%11100%
Update()100%11100%

File(s)

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

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using OzonDomains.Models;
 3using OzonRepositories.Context;
 4
 5namespace OzonRepositories.Data
 6{
 7    public class SupplierRepository : MainRepository, IRepository<Supplier>
 8    {
 309        public SupplierRepository(ApplicationDbContext orderContext) : base(orderContext)
 10        {
 3011        }
 12
 13        public async Task<int> Add(Supplier value)
 14        {
 415            await _context.Suppliers.AddAsync(value);
 416            return await _context.SaveChangesAsync();
 217        }
 18
 19        public async Task<int> Delete(Supplier value)
 20        {
 121            _context.Remove(value);
 122            return await _context.SaveChangesAsync();
 123        }
 24
 25        public async Task<List<Supplier>> Get()
 26        {
 227            return await _context.Suppliers.ToListAsync();
 228        }
 29
 30        public async Task<Supplier?> GetAsync(int id)
 31        {
 232            return await _context.Suppliers.FindAsync(id);
 233        }
 34
 35        // Без трекинга: для чтения "на подсмотреть" перед Update() того же Id в одном запросе —
 36        // FindAsync() иначе оставляет в контексте второй экземпляр с тем же ключом, и Update() падает
 37        // с конфликтом identity map.
 38        public async Task<Supplier?> GetAsyncNoTracking(int id)
 39        {
 440            return await _context.Suppliers.AsNoTracking().FirstOrDefaultAsync(x => x.Id == id);
 441        }
 42
 43        public async Task<Supplier?> GetAsync(Supplier value)
 44        {
 245            return await _context.Suppliers.SingleOrDefaultAsync(a => a.Name == value.Name);
 246        }
 47        public async Task<Supplier?> GetByNameAsync(string name)
 48        {
 649            return await _context.Suppliers.SingleOrDefaultAsync(a => a.Name == name);
 650        }
 51        public async Task<Supplier?> GetBySiteAsync(Supplier value)
 52        {
 853            return await _context.Suppliers.SingleOrDefaultAsync(a => a.Site == value.Site);
 854        }
 55
 56        public async Task<List<Supplier>> GetWithUrls()
 57        {
 258            return await _context.Suppliers.Where(s => s.Site != null).ToListAsync();
 259        }
 60
 61        public async Task<int> Update(Supplier value)
 62        {
 363            _context.Suppliers.Update(value);
 364            return await _context.SaveChangesAsync();
 365        }
 66    }
 67}