< Summary

Line coverage
91%
Covered lines: 32
Uncovered lines: 3
Coverable lines: 35
Total lines: 110
Line coverage: 91.4%
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
get_AutoActionEnabled()100%11100%
get_AutoAddToOzonActionsListEnabled()100%11100%
get_CurrencyCode()100%11100%
get_MinPrice()100%11100%
set_MinPrice(...)100%11100%
get_MinPriceForAutoActionsEnabled()100%11100%
get_NetPrice()100%11100%
set_NetPrice(...)100%210%
get_OfferId()100%11100%
get_OldPrice()100%11100%
set_OldPrice(...)100%11100%
get_Price()100%11100%
set_Price(...)100%11100%
get_PriceStrategyEnabled()100%11100%
get_ProductId()100%11100%
get_QuantSize()100%11100%
get_Vat()100%11100%
set_Vat(...)100%11100%
NormalizePriceString(...)83.33%66100%
NormalizeVat(...)57.14%151481.81%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/OzonApi/Filters/ProductPriceItem.cs

#LineLine coverage
 1
 2
 3using Newtonsoft.Json;
 4
 5public class ProductPriceItem
 6{
 7    [JsonProperty("auto_action_enabled")]
 47028    public string? AutoActionEnabled { get; set; } = "UNKNOWN";
 9
 10    [JsonProperty("auto_add_to_ozon_actions_list_enabled")]
 470211    public string? AutoAddToOzonActionsListEnabled { get; set; } = "UNKNOWN";
 12
 13    [JsonProperty("currency_code")]
 470214    public string? CurrencyCode { get; set; } = "RUB";
 15
 16    [JsonProperty("min_price", NullValueHandling = NullValueHandling.Ignore)]
 17    public string? MinPrice
 18    {
 235119        get => _minPrice;
 120        set => _minPrice = NormalizePriceString(value);
 21    }
 22    private string? _minPrice;
 23
 24    [JsonProperty("min_price_for_auto_actions_enabled")]
 235025    public bool MinPriceForAutoActionsEnabled { get; set; }
 26
 27    [JsonProperty("net_price", NullValueHandling = NullValueHandling.Ignore)]
 28    public string? NetPrice
 29    {
 235030        get => _netPrice;
 031        set => _netPrice = NormalizePriceString(value);
 32    }
 33    private string? _netPrice;
 34
 35    [JsonProperty("offer_id")]
 470036    public string? OfferId { get; set; }
 37
 38    [JsonProperty("old_price", NullValueHandling = NullValueHandling.Ignore)]
 39    public string? OldPrice
 40    {
 235141        get => _oldPrice;
 142        set => _oldPrice = NormalizePriceString(value);
 43    }
 44    private string? _oldPrice;
 45
 46    [JsonProperty("price")]
 47    public string? Price
 48    {
 235249        get => _price;
 235250        set => _price = NormalizePriceString(value);
 51    }
 52    private string? _price;
 53
 54    [JsonProperty("price_strategy_enabled")]
 470255    public string? PriceStrategyEnabled { get; set; } = "UNKNOWN";
 56
 57    [JsonProperty("product_id")]
 235058    public long ProductId { get; set; }
 59
 60    [JsonProperty("quant_size")]
 470261    public int QuantSize { get; set; } = 1;
 62
 63    [JsonProperty("vat", NullValueHandling = NullValueHandling.Ignore)]
 64    public string? Vat
 65    {
 235266        get => _vat;
 267        set => _vat = NormalizeVat(value);
 68    }
 69    private string? _vat;
 70
 71    /// <summary>
 72    /// Нормализует строковое значение цены: обрезает пробелы, пустые строки переводит в null,
 73    /// заменяет отрицательные цены на null во избежание regex validation error в Ozon API.
 74    /// </summary>
 75    public static string? NormalizePriceString(string? val)
 76    {
 235477        if (string.IsNullOrWhiteSpace(val)) return null;
 235478        val = val.Trim();
 79        // Если значение не парсится как неотрицательное число — отбрасываем
 235480        if (double.TryParse(val.Replace(',', '.'), System.Globalization.NumberStyles.Float, System.Globalization.Culture
 81        {
 235482            if (num < 0) return null;
 235283            return num.ToString(System.Globalization.CultureInfo.InvariantCulture);
 84        }
 185        return null;
 86    }
 87
 88    /// <summary>
 89    /// Нормализует ставку НДС для Ozon API: допускаются только числа (regex "^\d+([\.,]\d+)?$").
 90    /// При null, пустой строке, "null", "none" или процентах — приводит к корректному формату Ozon.
 91    /// </summary>
 92    public static string? NormalizeVat(string? vat)
 93    {
 294        if (string.IsNullOrWhiteSpace(vat)) return null;
 295        vat = vat.Trim().TrimEnd('%').Trim();
 296        if (vat.Equals("null", StringComparison.OrdinalIgnoreCase) ||
 297            vat.Equals("none", StringComparison.OrdinalIgnoreCase))
 098            return null;
 99
 2100        if (double.TryParse(vat.Replace(',', '.'), System.Globalization.NumberStyles.Float, System.Globalization.Culture
 101        {
 2102            if (num < 0) return null;
 103            // Ozon ставки: 0 -> "0", 10/20 -> "0.1"/"0.2" или исходный процент
 3104            if (num == 20) return "0.2";
 1105            if (num == 10) return "0.1";
 1106            return num.ToString(System.Globalization.CultureInfo.InvariantCulture);
 107        }
 0108        return null;
 109    }
 110}