< Summary

Information
Class: OzonOrdersWeb.WebServices.Transactions.Grid.Load.TransactionGridQuotationSourcesProvider
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/Transactions/Grid/Load/TransactionGridQuotationSourcesProvider.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 47
Coverable lines: 47
Total lines: 84
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
.ctor(...)100%210%
GetAsync()0%110100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/Transactions/Grid/Load/TransactionGridQuotationSourcesProvider.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Mvc;
 2using OzonDomains;
 3using OzonDomains.Models;
 4using OzonOrdersWeb.Areas.Studio2.ViewModels.TransactionsGrid;
 5using Services.ApiSupplierSettingsServices;
 6
 7namespace OzonOrdersWeb.WebServices.Transactions.Grid.Load;
 8
 9public interface ITransactionGridQuotationSourcesProvider
 10{
 11    /// <summary>Реестр провайдеров предложений для клиента (порт <c>apiSupplierQuotationSources</c> из _TransactionScri
 12    Task<IReadOnlyList<TransactionGridQuotationSource>> GetAsync(IUrlHelper url, CancellationToken cancellationToken);
 13}
 14
 15/// <summary>
 16/// Один список вместо 21 константы в Razor: ключ, имя, endpoint <c>Search</c> у <c>*PriceController</c>,
 17/// флаг из настроек API-поставщика. Контроллеры цен не меняются.
 18/// </summary>
 19public sealed class TransactionGridQuotationSourcesProvider : ITransactionGridQuotationSourcesProvider
 20{
 021    private static readonly (string Key, string Name, string Controller, bool Warmup, CurrencyCode Currency)[] Registry 
 022    {
 023        (ApiSupplierSettings.ArmtekProviderKey, "Армтек", "ArmtekPrice", true, CurrencyCode.RUB),
 024        (ApiSupplierSettings.ArmtekByProviderKey, "Армтек BY", "ArmtekByPrice", true, CurrencyCode.BYN),
 025        (ApiSupplierSettings.ShateMProviderKey, "Шате‑М", "ShateMPrice", false, CurrencyCode.BYN),
 026        (ApiSupplierSettings.AvdProviderKey, "АВД", "AvdPrice", false, CurrencyCode.RUB),
 027        (ApiSupplierSettings.BergProviderKey, "Берг", "BergPrice", false, CurrencyCode.RUB),
 028        (ApiSupplierSettings.JapartsProviderKey, "Japarts", "JapartsPrice", false, CurrencyCode.RUB),
 029        (ApiSupplierSettings.MotexProviderKey, "МоТехС", "MotexPrice", false, CurrencyCode.RUB),
 030        (ApiSupplierSettings.MlAutoProviderKey, "ML-Auto BY", "MlAutoPrice", false, CurrencyCode.BYN),
 031        (ApiSupplierSettings.MlAutoRuProviderKey, "ML-Auto RU", "MlAutoRuPrice", false, CurrencyCode.RUB),
 032        (ApiSupplierSettings.ForumAutoProviderKey, "Форум-Авто (Союз)", "ForumAutoPrice", false, CurrencyCode.RUB),
 033        (ApiSupplierSettings.ForumAutoInterpartsProviderKey, "Форум-Авто (Интерпартс)", "ForumAutoInterpartsPrice", fals
 034        (ApiSupplierSettings.ForumAutoPiterProviderKey, "Форум-Авто (Питер)", "ForumAutoPiterPrice", false, CurrencyCode
 035        (ApiSupplierSettings.ForumAutoRostovProviderKey, "Форум-Авто (Ростов)", "ForumAutoRostovPrice", false, CurrencyC
 036        (ApiSupplierSettings.ForumAutoIstraProviderKey, "Форум-Авто (Истра)", "ForumAutoIstraPrice", false, CurrencyCode
 037        (ApiSupplierSettings.FavoritPartsProviderKey, "Фаворит Союз", "FavoritPartsPrice", false, CurrencyCode.RUB),
 038        (ApiSupplierSettings.FavoritPartsIstraProviderKey, "Фаворит Истра", "FavoritPartsIstraPrice", false, CurrencyCod
 039        (ApiSupplierSettings.FavoritPartsRostovProviderKey, "Фаворит Ростов", "FavoritPartsRostovPrice", false, Currency
 040        (ApiSupplierSettings.MoskvorechieIstraProviderKey, "Москворечье (Истра)", "MoskvorechieIstraPrice", false, Curre
 041        (ApiSupplierSettings.ProfitLigaProviderKey, "Профит-Лига", "ProfitLigaPrice", false, CurrencyCode.RUB),
 042        (ApiSupplierSettings.NikeiProviderKey, "Nikei", "NikeiPrice", false, CurrencyCode.RUB),
 043        (ApiSupplierSettings.MikadoMskHod20ProviderKey, "Микадо МскХод20", "MikadoMskHod20Price", false, CurrencyCode.RU
 044        (ApiSupplierSettings.ZZapMoscowProviderKey, "ZZap Москва", "ZZapMoscowPrice", false, CurrencyCode.RUB)
 045    };
 46
 47    private readonly ApiSupplierSettingsService? _settings;
 48
 049    public TransactionGridQuotationSourcesProvider(ApiSupplierSettingsService? settings = null)
 50    {
 051        _settings = settings;
 052    }
 53
 54    public async Task<IReadOnlyList<TransactionGridQuotationSource>> GetAsync(IUrlHelper url, CancellationToken cancella
 55    {
 056        var result = new List<TransactionGridQuotationSource>(Registry.Length);
 057        foreach (var (key, name, controller, warmup, currency) in Registry)
 58        {
 059            var enabled = true;
 060            var displayName = name;
 061            if (_settings != null)
 62            {
 063                var settings = await _settings.GetAsync(key, currency, cancellationToken);
 064                enabled = settings.IsQuotationEnabled;
 065                if (!string.IsNullOrWhiteSpace(settings.DisplayName))
 066                    displayName = settings.DisplayName;
 67            }
 68
 069            var endpoint = url.Action("Search", controller, new { area = "Studio2" });
 070            if (string.IsNullOrEmpty(endpoint))
 71            {
 72                continue;
 73            }
 74
 075            result.Add(new TransactionGridQuotationSource(
 076                key, displayName, endpoint,
 077                warmup ? url.Action("Warmup", controller, new { area = "Studio2" }) : null,
 078                enabled,
 079                $"/Studio2/ApiSupplierSettings/{key}"));
 080        }
 81
 082        return result;
 083    }
 84}