< Summary

Information
Class: Services.DataServices.AccessProfileDataServices
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/DataServices/AccessProfileDataServices.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 21
Coverable lines: 21
Total lines: 50
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%
GetAllAsync()100%210%
GetAccessProfileAsync()100%210%
<GetAccessProfileAsync()100%210%
InvalidateCache(...)100%210%
AddAsync()100%210%
UpdateAsync()100%210%
DeleteAsync()100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/DataServices/AccessProfileDataServices.cs

#LineLine coverage
 1using Microsoft.Extensions.Caching.Memory;
 2using OzonDomains.Models.AccessControl;
 3using OzonRepositories.Data;
 4
 5namespace Services.DataServices;
 6
 7public class AccessProfileDataServices
 8{
 9    private readonly AccessProfileRepository _repository;
 10    private readonly IMemoryCache _cache;
 11
 012    public AccessProfileDataServices(AccessProfileRepository repository, IMemoryCache cache)
 13    {
 014        _repository = repository;
 015        _cache = cache;
 016    }
 17
 18    public async Task<List<AccessProfile>> GetAllAsync() =>
 019        await _repository.GetAllAsync();
 20
 21    public async Task<AccessProfile?> GetAccessProfileAsync(int id)
 22    {
 023        string cacheKey = $"access_profile_{id}";
 024        return await _cache.GetOrCreateAsync(cacheKey, async entry =>
 025        {
 026            entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10);
 027            return await _repository.GetByIdAsync(id);
 028        });
 029    }
 30
 31    public void InvalidateCache(int id)
 32    {
 033        _cache.Remove($"access_profile_{id}");
 034    }
 35
 36    public async Task<int> AddAsync(AccessProfile profile) =>
 037        await _repository.AddAsync(profile);
 38
 39    public async Task<int> UpdateAsync(AccessProfile profile)
 40    {
 041        InvalidateCache(profile.Id);
 042        return await _repository.UpdateAsync(profile);
 043    }
 44
 45    public async Task<int> DeleteAsync(AccessProfile profile)
 46    {
 047        InvalidateCache(profile.Id);
 048        return await _repository.DeleteAsync(profile);
 049    }
 50}