< 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_22190969454
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)
 33711        {
 33712            if (Project.Projects.TryGetValue(projectId, out Project? project))
 33513            {
 33514                return project;
 15            }
 216            throw new UnknownEntityException("Project", projectId);
 33517        }
 18
 19        protected static Class GetClassEntity(string projectId, string className)
 1620        {
 1621            return GetClassEntity(GetProjectEntity(projectId), className);
 1522        }
 23
 24        protected static Class GetClassEntity(Project project, string className)
 4825        {
 4826            if (project.Classes.TryGetValue(className, out Class? clazz))
 4727            {
 4728                return clazz;
 29            }
 130            throw new UnknownEntityException("Class", className);
 4731        }
 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)
 2439        {
 2440            if (clazz.FieldDefinitions.TryGetValue(fieldName, out IFieldDefinition? fieldDefinition))
 2441            {
 2442                return fieldDefinition;
 43            }
 044            throw new UnknownEntityException("Field", fieldName);
 2445        }
 46
 47        protected static IField GetFieldEntity(string projectId, string instanceName, string fieldName)
 15848        {
 15849            if (GetProjectEntity(projectId) is RunnableProject runnableProject)
 15850            {
 15851                Instance instance = runnableProject.GetInstance(instanceName);
 15852                return instance.GetField(fieldName);
 53            }
 054            throw new NonRunnableProjectException(projectId);
 15855        }
 56
 57        protected static PagedSearchResult<T> CreateResult<T>(PagedSearchRequest search, List<T> allEntities, List<T> fi
 3858            => new(search.PageNumber, search.PageSize, allEntities.Count,
 3859                [.. filteredEntities
 3860                    .Skip((search.PageNumber - 1) * search.PageSize)
 3861                    .Take(search.PageSize)]);
 62
 63        protected static List<T> SortResult<T>(List<T> entities, string? sortOption, Dictionary<string, Comparison<T>> s
 4364        {
 4365            if (String.IsNullOrEmpty(sortOption))
 2866            {
 2867                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;
 3883        }
 84
 85
 86    }
 87}