< Summary

Information
Class: Services.FeedPriceServices.FidApiFeedPriceReader
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/FeedPriceServices/FidApiFeedPriceReader.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 52
Line coverage: 100%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetAsync()50%22100%
AsUtc(...)50%22100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/FeedPriceServices/FidApiFeedPriceReader.cs

#LineLine coverage
 1using Services.ApiServices.FidApi;
 2
 3namespace Services.FeedPriceServices;
 4
 5/// <summary>Читает цену и остатки через публичный API фид-сервиса, не обращаясь к его PostgreSQL.</summary>
 6public sealed class FidApiFeedPriceReader : IFeedPriceReader
 7{
 8    private readonly FidApiDataManager _fidApi;
 9
 210    public FidApiFeedPriceReader(FidApiDataManager fidApi) => _fidApi = fidApi;
 11
 12    public async Task<FeedPriceSnapshot> GetAsync(
 13        IReadOnlyCollection<string> articleKeys,
 14        int runsPerCabinet,
 15        CancellationToken ct = default)
 16    {
 117        var response = await _fidApi.GetPriceStockAsync(articleKeys, runsPerCabinet, ct)
 118            ?? throw new InvalidOperationException("Фид-сервис не вернул снимок цены и остатков.");
 19
 120        return new FeedPriceSnapshot(
 121            response.Current.Select(row => new FeedCurrentRow
 122            {
 123                Cabinet = row.CabinetKey,
 124                Article = row.Article,
 125                Warehouse = row.WarehouseName,
 126                Stock = row.Stock,
 127                StockSupplier = row.StockSupplier,
 128                Price = row.Price,
 129                OldPrice = row.OldPrice,
 130                MinPrice = row.MinPrice,
 131                PurchasePrice = row.PurchasePrice,
 132                PriceWarehouse = row.PriceWarehouse,
 133                PriceSupplier = row.PriceSupplier,
 134                RunId = row.RunId,
 135                UpdatedAt = AsUtc(row.UpdatedAt)
 136            }).ToArray(),
 237            response.History.Select(row => new FeedHistoryRow
 238            {
 239                RunId = row.RunId,
 240                AssembledAt = AsUtc(row.AssembledAt),
 241                AssembledBy = row.AssembledBy ?? string.Empty,
 242                Cabinet = row.CabinetKey,
 243                Article = row.Article,
 244                Price = row.Price,
 245                OldPrice = row.OldPrice,
 246                TotalStock = row.TotalStock
 247            }).ToArray());
 148    }
 49
 50    private static DateTimeOffset AsUtc(DateTime value) =>
 251        new(value.Kind == DateTimeKind.Unspecified ? DateTime.SpecifyKind(value, DateTimeKind.Utc) : value.ToUniversalTi
 52}