< Summary - pva.SuperV

Information
Class: pva.SuperV.Api.Services.FieldFormatters.FieldFormatterService
Assembly: pva.SuperV.Api
File(s): /home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Api/Services/FieldFormatters/FieldFormatterService.cs
Tag: dotnet-ubuntu_18869653307
Line coverage
93%
Covered lines: 61
Uncovered lines: 4
Coverable lines: 65
Total lines: 103
Line coverage: 93.8%
Branch coverage
81%
Covered branches: 13
Total branches: 16
Branch coverage: 81.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
GetFieldFormatterTypesAsync()100%11100%
GetFieldFormattersAsync()100%11100%
SearchFieldFormattersAsync()100%11100%
FilterFieldFormatters(...)100%22100%
GetFieldFormatterAsync()50%2283.33%
CreateFieldFormatterAsync()50%2287.5%
UpdateFieldFormatterAsync()50%2287.5%
DeleteFieldFormatterAsync()100%4490.9%

File(s)

/home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Api/Services/FieldFormatters/FieldFormatterService.cs

#LineLine coverage
 1using pva.SuperV.Api.Exceptions;
 2using pva.SuperV.Engine;
 3using pva.SuperV.Engine.Exceptions;
 4using pva.SuperV.Engine.FieldFormatters;
 5using pva.SuperV.Model;
 6using pva.SuperV.Model.FieldFormatters;
 7using pva.SuperV.Model.Services;
 8
 9namespace pva.SuperV.Api.Services.FieldFormatters
 10{
 11    public class FieldFormatterService : BaseService, IFieldFormatterService
 12    {
 1513        private readonly Dictionary<string, Comparison<FieldFormatterModel>> sortOptions = new()
 1514            {
 3615                { "name", new Comparison<FieldFormatterModel>((a, b) => a.Name.CompareTo(b.Name)) }
 1516            };
 17
 18        [System.Diagnostics.CodeAnalysis.SuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreference
 19            Justification = "<Pending>")]
 20        public async Task<List<string>> GetFieldFormatterTypesAsync()
 121        {
 122            Type fieldFormatterType = typeof(FieldFormatter);
 123            return await Task.FromResult(AppDomain.CurrentDomain.GetAssemblies()
 16524                .SelectMany(domainAssembly => domainAssembly.GetExportedTypes())
 813425                .Where(type => type.IsSubclassOf(fieldFormatterType) &&
 813426                        type != fieldFormatterType && !type.IsAbstract)
 127                .Select(type => type.ToString())
 128                .ToList());
 129        }
 30
 31        public async Task<List<FieldFormatterModel>> GetFieldFormattersAsync(string projectId)
 932        {
 933            return await Task.FromResult(GetProjectEntity(projectId).FieldFormatters.Values
 7934                .Select(fieldFormatter => FieldFormatterMapper.ToDto(fieldFormatter))
 935                .ToList());
 936        }
 37
 38        public async Task<PagedSearchResult<FieldFormatterModel>> SearchFieldFormattersAsync(string projectId, FieldForm
 839        {
 840            List<FieldFormatterModel> allFieldFormatters = await GetFieldFormattersAsync(projectId);
 841            List<FieldFormatterModel> fieldFormatters = FilterFieldFormatters(allFieldFormatters, search);
 842            fieldFormatters = SortResult(fieldFormatters, search.SortOption, sortOptions);
 743            return CreateResult(search, allFieldFormatters, fieldFormatters);
 44
 745        }
 46
 47        private static List<FieldFormatterModel> FilterFieldFormatters(List<FieldFormatterModel> allFieldFormatters, Fie
 848        {
 849            List<FieldFormatterModel> filteredFieldDefinitions = allFieldFormatters;
 850            if (!String.IsNullOrEmpty(search.NameFilter))
 151            {
 1252                filteredFieldDefinitions = [.. filteredFieldDefinitions.Where(clazz => clazz.Name.Contains(search.NameFi
 153            }
 854            return filteredFieldDefinitions;
 855        }
 56
 57        public async Task<FieldFormatterModel> GetFieldFormatterAsync(string projectId, string fieldFormatterName)
 158        {
 159            if (GetProjectEntity(projectId).FieldFormatters.TryGetValue(fieldFormatterName, out FieldFormatter? fieldFor
 160            {
 161                return await Task.FromResult(FieldFormatterMapper.ToDto(fieldFormatter));
 62            }
 063            return await Task.FromException<FieldFormatterModel>(new UnknownEntityException("Field formatter", fieldForm
 164        }
 65
 66        public async Task<FieldFormatterModel> CreateFieldFormatterAsync(string projectId, CreateFieldFormatterRequest c
 367        {
 368            if (GetProjectEntity(projectId) is WipProject wipProject)
 369            {
 370                FieldFormatter fieldFormatter = FieldFormatterMapper.FromDto(createRequest.FieldFormatter);
 371                wipProject.AddFieldFormatter(fieldFormatter);
 372                return await Task.FromResult(FieldFormatterMapper.ToDto(fieldFormatter));
 73            }
 074            return await Task.FromException<FieldFormatterModel>(new NonWipProjectException(projectId));
 375        }
 76
 77        public async Task<FieldFormatterModel> UpdateFieldFormatterAsync(string projectId, string fieldFormatterName, Fi
 178        {
 179            if (GetProjectEntity(projectId) is WipProject wipProject)
 180            {
 181                FieldFormatter fieldFormatter = FieldFormatterMapper.FromDto(fieldFormatterModel);
 182                wipProject.UpdateFieldFormatter(fieldFormatterName, fieldFormatter);
 183                return await Task.FromResult(FieldFormatterMapper.ToDto(fieldFormatter));
 84            }
 085            return await Task.FromException<FieldFormatterModel>(new NonWipProjectException(projectId));
 186        }
 87
 88        public async ValueTask DeleteFieldFormatterAsync(string projectId, string fieldFormatterName)
 489        {
 490            if (GetProjectEntity(projectId) is WipProject wipProject)
 391            {
 392                if (wipProject.RemoveFieldFormatter(fieldFormatterName))
 193                {
 194                    await ValueTask.CompletedTask;
 195                    return;
 96                }
 197                await ValueTask.FromException(new UnknownEntityException("Field formatter", fieldFormatterName));
 098            }
 199            await ValueTask.FromException(new NonWipProjectException(projectId));
 1100        }
 101
 102    }
 103}