< Summary

Information
Class: Services.ApiServices.TelegramBotApi.NewOrdersTelegramNotifier
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/TelegramBotApi/NewOrdersTelegramNotifier.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 27
Line coverage: 0%
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%210%
NotifyAsync()0%7280%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/TelegramBotApi/NewOrdersTelegramNotifier.cs

#LineLine coverage
 1using Microsoft.Extensions.Logging;
 2
 3namespace Services.ApiServices.TelegramBotApi;
 4
 5/// <summary>Отправляет в Telegram пачку только что загруженных заказов. Ошибки не пробрасывает.</summary>
 06public sealed class NewOrdersTelegramNotifier(ITelegramNotifier telegram, TelegramBotConfig config,
 07    ILogger<NewOrdersTelegramNotifier>? logger = null)
 8{
 9    public async Task NotifyAsync(IReadOnlyList<TelegramNewOrderItem> orders, CancellationToken ct = default)
 10    {
 011        if (orders.Count == 0 || !telegram.IsConfigured) return;
 12
 13        try
 14        {
 015            foreach (var message in TelegramMessageFactory.NewOrders(orders, config.SiteBaseUrl))
 016                await telegram.SendAsync(message, ct);
 017        }
 018        catch (OperationCanceledException) when (ct.IsCancellationRequested)
 19        {
 020            throw;
 21        }
 022        catch (Exception ex)
 23        {
 024            logger?.LogWarning(ex, "Не удалось отправить уведомление о новых заказах в Telegram");
 025        }
 026    }
 27}