< Summary

Information
Class: Services.ApiServices.MlAutoApi.MlAutoRuDataManager
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/MlAutoApi/MlAutoRuDataManager.cs
Line coverage
62%
Covered lines: 18
Uncovered lines: 11
Coverable lines: 29
Total lines: 65
Line coverage: 62%
Branch coverage
65%
Covered branches: 13
Total branches: 20
Branch coverage: 65%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
PingAsync(...)100%210%
ShowInfoAsync(...)100%210%
GetStoragesAsync(...)100%210%
GetDeliveryAddressesAsync(...)100%210%
PostAsync(...)100%11100%
CreateOrderTestDetailedAsync(...)100%11100%
CreateOrderAsync(...)100%11100%
GetOrderByNumberAsync(...)100%11100%
GetMyOrdersAsync(...)100%11100%
GetOrderSummariesAsync()100%11100%
GetOrderItemsAsync()100%11100%
SearchAsync(...)100%210%
Objects(...)50%9657.14%
Value(...)100%22100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/MlAutoApi/MlAutoRuDataManager.cs

#LineLine coverage
 1using Newtonsoft.Json.Linq;
 2
 3namespace Services.ApiServices.MlAutoApi;
 4
 5/// <summary>Разрешённые read-only методы российского контура ML-Auto.</summary>
 6public sealed class MlAutoRuDataManager
 7{
 8    private readonly MlAutoRuHttpClient _client;
 9
 14610    public MlAutoRuDataManager(MlAutoRuHttpClient client) => _client = client;
 11
 012    public Task<JToken> PingAsync(CancellationToken cancellationToken = default) => _client.PingAsync(cancellationToken)
 13
 14    public Task<JToken> ShowInfoAsync(CancellationToken cancellationToken = default) =>
 015        _client.PostAsync("/ShowInfo/", null, cancellationToken);
 16
 17    public Task<JToken> GetStoragesAsync(CancellationToken cancellationToken = default) =>
 018        _client.PostAsync("/ImportersSearch/", null, cancellationToken);
 19
 20    public Task<JToken> GetDeliveryAddressesAsync(CancellationToken cancellationToken = default) =>
 021        _client.PostAsync("/MyDeliveryAddress/", null, cancellationToken);
 22
 23    public Task<JToken> PostAsync(string path, IReadOnlyDictionary<string, string?>? parameters, CancellationToken cance
 2424        _client.PostAsync(path, parameters, cancellationToken);
 25
 26    public Task<MlAutoApiResponse> CreateOrderTestDetailedAsync(IReadOnlyDictionary<string, string?> parameters, Cancell
 1927        _client.PostDetailedAsync("/CreateOrderTest/", parameters, cancellationToken);
 28
 29    public Task<JToken> CreateOrderAsync(IReadOnlyDictionary<string, string?> parameters, CancellationToken cancellation
 1530        _client.PostAsync("/CreateOrder/", parameters, cancellationToken);
 31
 32    public Task<JToken> GetOrderByNumberAsync(string orderNumber, CancellationToken cancellationToken = default) =>
 1933        _client.PostAsync("/GetOrderByNumber/", new Dictionary<string, string?> { ["ORDER-NUMBER"] = orderNumber }, canc
 34
 135    public Task<JToken> GetMyOrdersAsync(CancellationToken cancellationToken = default) => _client.PostAsync("/GetMyOrde
 36
 37    public async Task<IReadOnlyList<MlAutoOrderSummary>> GetOrderSummariesAsync(CancellationToken cancellationToken = de
 38    {
 139        var response = await GetMyOrdersAsync(cancellationToken);
 440        return Objects(response, "ORDERS").Select(x => new MlAutoOrderSummary(Value(x, "ORDER-NUMBER", "ORDERNUMBER", "N
 941            .Where(x => !string.IsNullOrWhiteSpace(x.Number)).DistinctBy(x => x.Number).OrderByDescending(x => x.Created
 142    }
 43
 44    public async Task<IReadOnlyList<MlAutoOrderItemInfo>> GetOrderItemsAsync(string orderNumber, CancellationToken cance
 45    {
 346        var response = await GetOrderByNumberAsync(orderNumber, cancellationToken);
 647        return Objects(response, "ITEMS").Select(x => new MlAutoOrderItemInfo(Value(x, "PIN") ?? string.Empty, Value(x, 
 248    }
 49
 50    public Task<JToken> SearchAsync(string article, string brand, CancellationToken cancellationToken = default) =>
 051        _client.PostAsync("/Search/", new Dictionary<string, string?>
 052        {
 053            ["ARTICLE"] = article.Trim(), ["BRAND"] = brand.Trim(), ["SEARCH_TYPE"] = "0"
 054        }, cancellationToken);
 55
 356    private static IEnumerable<JObject> Objects(JToken token, string arrayName) => token switch
 357    {
 058        JArray array => array.OfType<JObject>(),
 659        JObject obj when obj.GetValue(arrayName, StringComparison.OrdinalIgnoreCase) is JArray nested => nested.OfType<J
 060        JObject obj => [obj],
 061        _ => []
 362    };
 63
 9664    private static string? Value(JObject source, params string[] names) => names.Select(name => source.GetValue(name, St
 65}