< Summary - pva.SuperV

Information
Class: pva.SuperV.Api.Services.BaseService
Assembly: pva.SuperV.Api
File(s): /home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Api/Services/BaseService.cs
Tag: dotnet-ubuntu_18869653307
Line coverage
96%
Covered lines: 50
Uncovered lines: 2
Coverable lines: 52
Total lines: 87
Line coverage: 96.1%
Branch coverage
87%
Covered branches: 14
Total branches: 16
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetProjectEntity(...)100%22100%
GetClassEntity(...)100%11100%
GetClassEntity(...)100%22100%
GetFieldDefinitionEntity(...)100%11100%
GetFieldDefinitionEntity(...)50%2283.33%
GetFieldEntity(...)50%2285.71%
CreateResult(...)100%11100%
SortResult(...)100%88100%

File(s)

/home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Api/Services/BaseService.cs

#LineLine coverage
 1using pva.SuperV.Api.Exceptions;
 2using pva.SuperV.Engine;
 3using pva.SuperV.Engine.Exceptions;
 4using pva.SuperV.Model;
 5
 6namespace pva.SuperV.Api.Services
 7{
 8    public abstract class BaseService
 9    {
 10        protected static Project GetProjectEntity(string projectId)
 24511        {
 24512            if (Project.Projects.TryGetValue(projectId, out Project? project))
 24313            {
 24314                return project;
 15            }
 216            throw new UnknownEntityException("Project", projectId);
 24317        }
 18
 19        protected static Class GetClassEntity(string projectId, string className)
 1420        {
 1421            return GetClassEntity(GetProjectEntity(projectId), className);
 1322        }
 23
 24        protected static Class GetClassEntity(Project project, string className)
 3125        {
 3126            if (project.Classes.TryGetValue(className, out Class? clazz))
 3027            {
 3028                return clazz;
 29            }
 130            throw new UnknownEntityException("Class", className);
 3031        }
 32
 33        protected static IFieldDefinition GetFieldDefinitionEntity(Project project, string className, string fieldName)
 234        {
 235            return GetFieldDefinitionEntity(GetClassEntity(project, className), fieldName);
 236        }
 37
 38        protected static IFieldDefinition GetFieldDefinitionEntity(Class clazz, string fieldName)
 939        {
 940            if (clazz.FieldDefinitions.TryGetValue(fieldName, out IFieldDefinition? fieldDefinition))
 941            {
 942                return fieldDefinition;
 43            }
 044            throw new UnknownEntityException("Field", fieldName);
 945        }
 46
 47        protected static IField GetFieldEntity(string projectId, string instanceName, string fieldName)
 13548        {
 13549            if (GetProjectEntity(projectId) is RunnableProject runnableProject)
 13550            {
 13551                Instance instance = runnableProject.GetInstance(instanceName);
 13552                return instance.GetField(fieldName);
 53            }
 054            throw new NonRunnableProjectException(projectId);
 13555        }
 56
 57        protected static PagedSearchResult<T> CreateResult<T>(PagedSearchRequest search, List<T> allEntities, List<T> fi
 3558            => new(search.PageNumber, search.PageSize, allEntities.Count,
 3559                [.. filteredEntities
 3560                    .Skip((search.PageNumber - 1) * search.PageSize)
 3561                    .Take(search.PageSize)]);
 62
 63        protected static List<T> SortResult<T>(List<T> entities, string? sortOption, Dictionary<string, Comparison<T>> s
 4064        {
 4065            if (String.IsNullOrEmpty(sortOption))
 2566            {
 2567                return entities;
 68            }
 1569            string actualSortOption = sortOption.StartsWith('-') ? sortOption[1..] : sortOption;
 1570            if (sortOptions.TryGetValue(actualSortOption, out Comparison<T>? comparison))
 1071            {
 1072                entities.Sort(comparison);
 1073                if (sortOption.StartsWith('-'))
 574                {
 575                    entities.Reverse();
 576                }
 1077            }
 78            else
 579            {
 580                throw new InvalidSortOptionException(sortOption, [.. sortOptions!.Keys]);
 81            }
 1082            return entities;
 3583        }
 84
 85
 86    }
 87}