< Summary

Information
Class: Services.TransactionUtilsServices.WarehouseMappingSupplierResolver
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/TransactionUtilsServices/WarehouseMappingSupplierResolver.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 56
Line coverage: 100%
Branch coverage
80%
Covered branches: 21
Total branches: 26
Branch coverage: 80.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ApplyToOrders(...)80%2020100%
HasManuallySelectedSupplier(...)83.33%66100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/TransactionUtilsServices/WarehouseMappingSupplierResolver.cs

#LineLine coverage
 1using OzonDomains.Models;
 2
 3namespace Services.TransactionUtilsServices;
 4
 5/// <summary>
 6/// Подставляет поставщика для заказа из связи клиента Ozon и склада отгрузки.
 7/// </summary>
 8public static class WarehouseMappingSupplierResolver
 9{
 10    public static int ApplyToOrders(
 11        IEnumerable<Order> orders,
 12        IEnumerable<WarehouseMapping> mappings,
 13        int? unspecifiedSupplierId)
 14    {
 215        var supplierMappings = mappings
 216            .Where(mapping =>
 417                mapping.SupplierId.HasValue &&
 418                mapping.OzonClientId.HasValue &&
 419                !string.IsNullOrWhiteSpace(mapping.OzonWarehouseName))
 220            .ToList();
 221        var appliedCount = 0;
 22
 823        foreach (var order in orders)
 24        {
 225            if (HasManuallySelectedSupplier(order, unspecifiedSupplierId))
 26                continue;
 27
 128            var warehouseName = order.ShipmentWarehouse?.Name?.Trim();
 129            if (!order.OzonClientId.HasValue || string.IsNullOrWhiteSpace(warehouseName))
 30                continue;
 31
 132            var mapping = supplierMappings
 133                .Where(candidate =>
 334                    candidate.OzonClientId == order.OzonClientId &&
 335                    string.Equals(candidate.OzonWarehouseName.Trim(), warehouseName,
 336                        StringComparison.OrdinalIgnoreCase))
 237                .OrderBy(candidate => candidate.Priority)
 238                .ThenBy(candidate => candidate.Id)
 139                .FirstOrDefault();
 40
 141            if (mapping == null)
 42                continue;
 43
 144            order.SupplierId = mapping.SupplierId;
 145            order.Supplier = mapping.Supplier;
 146            appliedCount++;
 47        }
 48
 249        return appliedCount;
 50    }
 51
 52    private static bool HasManuallySelectedSupplier(Order order, int? unspecifiedSupplierId) =>
 253        order.SupplierId.HasValue &&
 254        order.SupplierId != unspecifiedSupplierId &&
 255        !string.Equals(order.Supplier?.Name, "Не указан", StringComparison.OrdinalIgnoreCase);
 56}