< Summary

Information
Class: Services.ApiServices.InterpartsPriceApi.InterpartsPriceApiClient
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/InterpartsPriceApi/InterpartsPriceApiClient.cs
Line coverage
13%
Covered lines: 2
Uncovered lines: 13
Coverable lines: 15
Total lines: 44
Line coverage: 13.3%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetXmlAsync()0%7280%
GetTestRequest(...)100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/InterpartsPriceApi/InterpartsPriceApiClient.cs

#LineLine coverage
 1using Microsoft.Extensions.Http;
 2using SlqStudio.Application.Services.EmailService;
 3using Services.ApiServices;
 4
 5namespace Services.ApiServices.InterpartsPriceApi;
 6
 7public class InterpartsPriceApiClient : BaseApiClient
 8{
 9    public InterpartsPriceApiClient(IHttpClientFactory httpClientFactory, IEmailService? emailService)
 510        : base(httpClientFactory, emailService, "InterpartsPriceApi", TimeSpan.FromSeconds(15))
 11    {
 512    }
 13
 14    public async Task<InterpartsPriceHttpResult> GetXmlAsync(string requestUrl, CancellationToken cancellationToken = de
 15    {
 16        try
 17        {
 018            var client = _httpClientFactory?.CreateClient(_clientName) ?? new HttpClient();
 019            client.Timeout = _timeout;
 020            SetHttpClientHeaders(client);
 021            using var response = await client.GetAsync(requestUrl, cancellationToken);
 022            var body = await response.Content.ReadAsStringAsync(cancellationToken);
 023            return new InterpartsPriceHttpResult((int)response.StatusCode, body,
 024                response.IsSuccessStatusCode ? null : $"Interparts Price вернул HTTP {(int)response.StatusCode} ({respon
 25        }
 026        catch (TaskCanceledException ex)
 27        {
 028            return new InterpartsPriceHttpResult(null, null, $"Таймаут Interparts Price: {ex.Message}");
 29        }
 030        catch (HttpRequestException ex)
 31        {
 032            return new InterpartsPriceHttpResult(ex.StatusCode is null ? null : (int)ex.StatusCode, null, $"Ошибка сети 
 33        }
 034    }
 35
 36    public override Task<bool> GetTestRequest(string businessId, string apiKey)
 37    {
 38        // Здесь нет полноценного тестового эндпоинта, считаем что клиент "работает",
 39        // пока запросы не падают в менеджере.
 040        return Task.FromResult(true);
 41    }
 42}
 43
 44public sealed record InterpartsPriceHttpResult(int? StatusCode, string? Body, string? ErrorMessage);