< Summary

Information
Class: MRA.Services.RemoteConfig.RemoteConfigService
Assembly: MRA.Services
File(s): D:\a\MiguelRomerART\MiguelRomerART\MRA.Services\RemoteConfig\RemoteConfigService.cs
Line coverage
56%
Covered lines: 13
Uncovered lines: 10
Coverable lines: 23
Total lines: 58
Line coverage: 56.5%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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%
RegisterRemoteConfig()100%11100%
GetPopularityDate()100%210%
GetPopularityMonths()100%210%
GetPopularityCritic()100%210%
GetPopularityPopular()100%210%
GetPopularityFavorite()100%210%
GetKey(...)0%620%

File(s)

D:\a\MiguelRomerART\MiguelRomerART\MRA.Services\RemoteConfig\RemoteConfigService.cs

#LineLine coverage
 1using Microsoft.Extensions.Caching.Memory;
 2using MRA.Infrastructure.Cache;
 3using MRA.Infrastructure.RemoteConfig;
 4using MRA.Infrastructure.Settings;
 5using MRA.Services.Cache;
 6
 7namespace MRA.Services.RemoteConfig;
 8
 9public class RemoteConfigService : CacheServiceBase, IRemoteConfigService
 10{
 11    private List<object> _keys;
 12
 13    private readonly IRemoteConfigDatabase _remoteConfig;
 14
 15    public RemoteConfigService(
 16            ICacheProvider cache,
 17            AppSettings appSettings,
 118            IRemoteConfigDatabase remoteConfigDatabase) : base(appSettings, cache)
 19    {
 120        _remoteConfig = remoteConfigDatabase;
 121        RegisterRemoteConfig();
 122    }
 23
 24    private void RegisterRemoteConfig()
 25    {
 126        _keys = new List<object>()
 127        {
 128            new RemoteConfigSetting<double>(RemoteConfigKey.Popularity_Date, _appSettings.RemoteConfig.DefaultValues.Pop
 129            new RemoteConfigSetting<int>(RemoteConfigKey.Popularity_Months, _appSettings.RemoteConfig.DefaultValues.Popu
 130            new RemoteConfigSetting<double>(RemoteConfigKey.Popularity_Critic, _appSettings.RemoteConfig.DefaultValues.P
 131            new RemoteConfigSetting<double>(RemoteConfigKey.Popularity_Popular, _appSettings.RemoteConfig.DefaultValues.
 132            new RemoteConfigSetting<double>(RemoteConfigKey.Popularity_Favorite, _appSettings.RemoteConfig.DefaultValues
 133        };
 134    }
 35
 36    public double GetPopularityDate() =>
 037        GetOrSetFromCache(RemoteConfigKey.Popularity_Date.ToString(), () => _remoteConfig.GetValue(GetKey<double>(Remote
 38    public int GetPopularityMonths() =>
 039        GetOrSetFromCache(RemoteConfigKey.Popularity_Date.ToString(), () => _remoteConfig.GetValue(GetKey<int>(RemoteCon
 40    public double GetPopularityCritic() =>
 041        GetOrSetFromCache(RemoteConfigKey.Popularity_Date.ToString(), () => _remoteConfig.GetValue(GetKey<double>(Remote
 42    public double GetPopularityPopular() =>
 043        GetOrSetFromCache(RemoteConfigKey.Popularity_Date.ToString(), () => _remoteConfig.GetValue(GetKey<double>(Remote
 44    public double GetPopularityFavorite() =>
 045        GetOrSetFromCache(RemoteConfigKey.Popularity_Date.ToString(), () => _remoteConfig.GetValue(GetKey<double>(Remote
 46
 47
 48    private RemoteConfigSetting<T> GetKey<T>(RemoteConfigKey key)
 49    {
 050        var config = _keys.OfType<RemoteConfigSetting<T>>()
 051                          .FirstOrDefault(k => k.Key == key);
 52
 053        if (config == null)
 054            throw new InvalidOperationException($"La clave '{key}' no está registrada.");
 55
 056        return config;
 57    }
 58}