< Summary

Information
Class: Services.DataServices.OzonClientServices
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/DataServices/OzonClientServices.cs
Line coverage
15%
Covered lines: 7
Uncovered lines: 37
Coverable lines: 44
Total lines: 96
Line coverage: 15.9%
Branch coverage
0%
Covered branches: 0
Total branches: 30
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%11100%
AddOzonClient()0%2040%
DeleteOzonClient()0%620%
GetOzonClients()0%7280%
GetOzonClientAsync()0%4260%
GetOzonClientAsync()0%4260%
Update()0%2040%
SaveChanges()100%210%

File(s)

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

#LineLine coverage
 1using OzonDomains.Models;
 2using OzonRepositories.Data;
 3
 4namespace Services.DataServices
 5{
 6    public class OzonClientServices : IDataServices
 7    {
 8        private readonly OzonClientRepository _repository;
 9        private readonly CryptographyServices _cryptography;
 10        private readonly OrdersDataServices _ordersDataServices;
 11
 2112        public OzonClientServices(OzonClientRepository repository,
 2113                                  CryptographyServices cryptography,
 2114                                  OrdersDataServices ordersDataServices)
 15        {
 2116            _repository = repository;
 2117            _cryptography = cryptography;
 2118            _ordersDataServices = ordersDataServices;
 2119        }
 20        public async Task<int> AddOzonClient(OzonClient value)
 21        {
 022            if (value.ClientId != null && value.ApiKey != null)
 23            {
 024                value.ClientId = _cryptography.Encrypt(value.ClientId);
 025                value.ApiKey = _cryptography.Encrypt(value.ApiKey);
 26            }
 027            return await _repository.Add(value);
 028        }
 29
 30        public async Task<int> DeleteOzonClient(OzonClient value)
 31        {
 032            var clientOrders = await _ordersDataServices.GetOrders();
 033            var ordersToUpdate = clientOrders.Where(order => order.OzonClient == value).ToList();
 34
 035            foreach (var order in ordersToUpdate)
 36            {
 037                order.OzonClient = null;
 038                await _ordersDataServices.UpdateOrder(order);
 39            }
 40
 041            return await _repository.Delete(value);
 042        }
 43
 44        public virtual async Task<List<OzonClient>> GetOzonClients()
 45        {
 046            List<OzonClient> ozonClients = await _repository.Get();
 047            foreach (var ozonClient in ozonClients)
 48            {
 049                if (ozonClient != null && ozonClient.ClientId != null && ozonClient.ApiKey != null)
 50                {
 051                    ozonClient.DecryptClientId = _cryptography.Decrypt(ozonClient.ClientId);
 052                    ozonClient.DecryptApiKey = _cryptography.Decrypt(ozonClient.ApiKey);
 53                }
 54            }
 55
 056            return ozonClients;
 057        }
 58
 59        public async Task<OzonClient?> GetOzonClientAsync(int id)
 60        {
 061            var ozonClient = await _repository.GetAsync(id);
 062            if (ozonClient != null && ozonClient.ClientId != null && ozonClient.ApiKey != null)
 63            {
 064                ozonClient.DecryptClientId = _cryptography.Decrypt(ozonClient.ClientId);
 065                ozonClient.DecryptApiKey = _cryptography.Decrypt(ozonClient.ApiKey);
 66            }
 067            return ozonClient;
 068        }
 69
 70        public async Task<OzonClient?> GetOzonClientAsync(OzonClient value)
 71        {
 072            var ozonClient = await _repository.GetAsync(value);
 073            if (ozonClient != null && ozonClient.ClientId != null && ozonClient.ApiKey != null)
 74            {
 075                ozonClient.DecryptClientId = _cryptography.Decrypt(ozonClient.ClientId);
 076                ozonClient.DecryptApiKey = _cryptography.Decrypt(ozonClient.ApiKey);
 77            }
 078            return ozonClient;
 079        }
 80
 81        public async Task<int> Update(OzonClient value)
 82        {
 083            if (value.ClientId != null && value.ApiKey != null)
 84            {
 085                value.ClientId = _cryptography.Encrypt(value.ClientId);
 086                value.ApiKey = _cryptography.Encrypt(value.ApiKey);
 87            }
 88
 089            return await _repository.Update(value);
 090        }
 91        public Task<int> SaveChanges()
 92        {
 093            return _repository.SaveChanges();
 94        }
 95    }
 96}