< Summary

Information
Class: Services.FiltersServices.DataFilterManagers.TransactionDataFilterManager
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/FiltersServices/DataFilterManagers/TransactionDataFilterManager.cs
Line coverage
94%
Covered lines: 35
Uncovered lines: 2
Coverable lines: 37
Total lines: 97
Line coverage: 94.5%
Branch coverage
92%
Covered branches: 26
Total branches: 28
Branch coverage: 92.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
FilterByFilterData()83.33%6691.66%
FilterByRadioButton()100%11100%
AreAllPropertiesNull(...)100%1818100%
AreAllPropertiesNull(...)75%4483.33%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/FiltersServices/DataFilterManagers/TransactionDataFilterManager.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using OzonDomains;
 3using OzonDomains.Models;
 4using Services.DataServices;
 5using Services.FiltersServices.FilterModels;
 6using System.Reflection;
 7using OServices.FiltersServices.FilterModels;
 8
 9
 10namespace Services.FiltersServices.DataFilterManagers
 11{
 12    public class TransactionDataFilterManager
 13    {
 14        private QueryableDataFilter<Transaction> _filter;
 15        private TransactionDataServices _servcies;
 7416        public TransactionDataFilterManager(QueryableDataFilter<Transaction> filter,
 7417                                            TransactionDataServices transactionDataServices)
 18        {
 7419            _filter = filter;
 7420            _servcies = transactionDataServices;
 7421        }
 22        public async Task<List<Transaction>> FilterByFilterData(List<Transaction> standartTransactions, OrderFilterModel
 23        {
 2424            bool filterIsNull = AreAllPropertiesNull(filterModel);
 2425            bool orderFilterIsNotNull = AreAllPropertiesNull(orderFilterModel);
 2426            IQueryable<Transaction> transactions = _servcies.GetTransactions();
 27
 2428            if (filterIsNull && !orderFilterIsNotNull)
 29            {
 430                return await transactions.ToListAsync();
 31            }
 2032            else if (filterIsNull && orderFilterIsNotNull)
 33            {
 034                return standartTransactions;
 35            }
 36
 2037            transactions = _filter.FilterByString(transactions, tr => tr.CreateBy, filterModel.CreateBy);
 2038            transactions = _filter.FilterByDate(transactions, tr => tr.CreatedDateTime, filterModel.CreatedDateTime);
 2039            transactions = _filter.FilterByEnum(transactions, t => t.Type, filterModel.Type);
 40
 2041            return await transactions.ToListAsync();
 2442        }
 43
 44        public async Task<List<Transaction>> FilterByRadioButton(List<Transaction> filterModel, string buttonState)
 45        {
 246            await Task.CompletedTask;
 247            throw new NotImplementedException();
 48        }
 49
 50        public bool AreAllPropertiesNull(TransactionFilterModel model)
 51        {
 3352            PropertyInfo[] properties = typeof(TransactionFilterModel).GetProperties();
 53
 18254            foreach (PropertyInfo prop in properties)
 55            {
 7056                if (prop.Name == nameof(TransactionFilterModel.Type))
 57                {
 3358                    if (model.Type.HasValue && model.Type != TransactionType.All)
 59                    {
 1060                        return false;
 61                    }
 62                }
 3763                else if (prop.Name == nameof(TransactionFilterModel.CreateBy))
 64                {
 2365                    if (!string.IsNullOrEmpty(model.CreateBy) && model.CreateBy != "Все")
 66                    {
 967                        return false;
 68                    }
 69                }
 1470                else if (prop.Name == nameof(TransactionFilterModel.CreatedDateTime))
 71                {
 1472                    if (model.CreatedDateTime.HasValue)
 73                    {
 574                        return false;
 75                    }
 76                }
 77            }
 78
 979            return true;
 80        }
 81        public bool AreAllPropertiesNull(OrderFilterModel model)
 82        {
 3583            PropertyInfo[] properties = typeof(OrderFilterModel).GetProperties();
 84
 86785            foreach (PropertyInfo prop in properties)
 86            {
 41687                object? value = prop.GetValue(model);
 41688                if (value != null)
 89                {
 3590                    return false;
 91                }
 92            }
 93
 094            return true;
 95        }
 96    }
 97}