< Summary

Information
Class: Services.ApiServices.ArmtekApi.Models.Response.ArmtekOrderStatusesConverter
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/ArmtekApi/Models/Response/ArmtekOrderStatuses.cs
Line coverage
75%
Covered lines: 12
Uncovered lines: 4
Coverable lines: 16
Total lines: 108
Line coverage: 75%
Branch coverage
70%
Covered branches: 7
Total branches: 10
Branch coverage: 70%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ReadJson(...)70%111080%
WriteJson(...)100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/ArmtekApi/Models/Response/ArmtekOrderStatuses.cs

#LineLine coverage
 1using Newtonsoft.Json;
 2using Newtonsoft.Json.Linq;
 3using Services.ApiServices.ArmtekApi.Converters;
 4
 5namespace Services.ApiServices.ArmtekApi.Models.Response;
 6
 7/// <summary>
 8/// getOrder2?STATUS=1 — RESP.STATUSES. Armtek возвращает это поле как объект с группами статусов
 9/// либо как массив (в частности, <c>[]</c> для заказа без детализации). Конвертер поддерживает
 10/// обе формы и не даёт штатному пустому массиву сорвать синхронизацию всего заказа.
 11/// </summary>
 12public class ArmtekOrderStatuses
 13{
 14    [JsonProperty("Processing")]
 15    [JsonConverter(typeof(ArmtekResultsAsListConverter<ArmtekProcessingSubStatus>))]
 16    public List<ArmtekProcessingSubStatus> Processing { get; set; } = new();
 17
 18    [JsonProperty("Ready")]
 19    [JsonConverter(typeof(ArmtekResultsAsListConverter<ArmtekReadyStatus>))]
 20    public List<ArmtekReadyStatus> Ready { get; set; } = new();
 21
 22    [JsonProperty("Delivered")]
 23    [JsonConverter(typeof(ArmtekResultsAsListConverter<ArmtekDeliveredStatus>))]
 24    public List<ArmtekDeliveredStatus> Delivered { get; set; } = new();
 25}
 26
 27/// <summary>Принимает объект STATUSES и массив объектов STATUSES, объединяя группы статусов.</summary>
 28public sealed class ArmtekOrderStatusesConverter : JsonConverter<ArmtekOrderStatuses?>
 29{
 30    public override ArmtekOrderStatuses? ReadJson(JsonReader reader, Type objectType, ArmtekOrderStatuses? existingValue
 31        bool hasExistingValue, JsonSerializer serializer)
 32    {
 333        if (reader.TokenType == JsonToken.Null)
 034            return null;
 35
 336        var token = JToken.Load(reader);
 337        if (token.Type == JTokenType.Object)
 038            return token.ToObject<ArmtekOrderStatuses>(serializer);
 39
 340        if (token.Type != JTokenType.Array)
 041            return new ArmtekOrderStatuses();
 42
 343        var combined = new ArmtekOrderStatuses();
 1644        foreach (var entry in token.Children<JObject>())
 45        {
 546            var statuses = entry.ToObject<ArmtekOrderStatuses>(serializer);
 547            if (statuses is null)
 48                continue;
 49
 550            combined.Processing.AddRange(statuses.Processing);
 551            combined.Ready.AddRange(statuses.Ready);
 552            combined.Delivered.AddRange(statuses.Delivered);
 53        }
 54
 355        return combined;
 56    }
 57
 58    public override void WriteJson(JsonWriter writer, ArmtekOrderStatuses? value, JsonSerializer serializer) =>
 059        serializer.Serialize(writer, value);
 60}
 61
 62/// <summary>Planned / Waiting / Confirmed / Shipped / WayQuan.</summary>
 63public class ArmtekProcessingSubStatus
 64{
 65    [JsonProperty("SubStatus")] public string SubStatus { get; set; } = string.Empty;
 66
 67    [JsonProperty("KWMENG")]
 68    [JsonConverter(typeof(ArmtekFlexibleStringConverter))]
 69    public string? Kwmeng { get; set; }
 70
 71    [JsonProperty("Werks")] public string Werks { get; set; } = string.Empty;
 72    [JsonProperty("WerksName")] public string WerksName { get; set; } = string.Empty;
 73    [JsonProperty("LsegETP")] public string LsegEtp { get; set; } = string.Empty;
 74    [JsonProperty("Date")] public string Date { get; set; } = string.Empty;
 75    [JsonProperty("ExpectedDate")] public string ExpectedDate { get; set; } = string.Empty;
 76}
 77
 78/// <summary>Готово к отгрузке на складе, ожидает комплектации.</summary>
 79public class ArmtekReadyStatus
 80{
 81    [JsonProperty("DELIVERY")] public string DeliveryNumber { get; set; } = string.Empty;
 82    [JsonProperty("DELIVERY_DATE")] public string DeliveryDate { get; set; } = string.Empty;
 83
 84    [JsonProperty("KWMENG")]
 85    [JsonConverter(typeof(ArmtekFlexibleStringConverter))]
 86    public string? Kwmeng { get; set; }
 87
 88    [JsonProperty("Werks")] public string Werks { get; set; } = string.Empty;
 89    [JsonProperty("ExpectedDate")] public string ExpectedDate { get; set; } = string.Empty;
 90}
 91
 92/// <summary>Отгружено — привязка к фактуре.</summary>
 93public class ArmtekDeliveredStatus
 94{
 95    [JsonProperty("INVOICE")] public string Invoice { get; set; } = string.Empty;
 96    [JsonProperty("INVOICE_DATE")] public string InvoiceDate { get; set; } = string.Empty;
 97
 98    [JsonProperty("KWMENG")]
 99    [JsonConverter(typeof(ArmtekFlexibleStringConverter))]
 100    public string? Kwmeng { get; set; }
 101
 102    [JsonProperty("SUMMA")]
 103    [JsonConverter(typeof(ArmtekFlexibleStringConverter))]
 104    public string? Summa { get; set; }
 105
 106    [JsonProperty("CURRENCY")] public string Currency { get; set; } = string.Empty;
 107    [JsonProperty("DELIVERY")] public string DeliveryNumber { get; set; } = string.Empty;
 108}