< Summary

Class:SVETA.Api.Helpers.Telegram
Assembly:SVETA.Api
File(s):/opt/dev/sveta_api_build/SVETA.Api/Helpers/Telegram.cs
Covered lines:5
Uncovered lines:20
Coverable lines:25
Total lines:49
Line coverage:20% (5 of 25)
Covered branches:3
Total branches:10
Branch coverage:30% (3 of 10)

Metrics

MethodLine coverage Branch coverage
get_Token()0%100%
get_ChatId()0%100%
SendNotification()21.73%30%

File(s)

/opt/dev/sveta_api_build/SVETA.Api/Helpers/Telegram.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Threading.Tasks;
 5using System.Net.Http;
 6using SVETA.Api.Data.Domain;
 7using SVETA.API.IntegrationTest.Common;
 8using Microsoft.Extensions.Logging;
 9
 10namespace SVETA.Api.Helpers
 11{
 12    public static class Telegram
 13    {
 14        /// <summary>
 15        /// Токен
 16        /// </summary>
 017        public static string Token { get; set; }
 18        /// <summary>
 19        /// id чата
 20        /// </summary>
 021        public static string ChatId { get; set; }
 22
 23        public static async Task SendNotification(string text)
 56024        {
 25            try
 56026            {
 56027                if (string.IsNullOrWhiteSpace(Token) || string.IsNullOrWhiteSpace(ChatId))
 56028                    return;
 029                using (HttpClient client = new HttpClient())
 030                {
 031                    var url = $"https://api.telegram.org/bot{Token}/sendMessage";
 032                    TelegramMessage message = new TelegramMessage
 033                    {
 034                        Text = text,
 035                        Chat_id = ChatId
 036                    };
 037                    var mes = StringContentCreator.CreateContent(message);
 038                    var resp = await client.PostAsync(url, mes);
 039                    var content = await resp.Content.ReadAsStringAsync();
 040                }
 041            }
 042            catch (Exception e)
 043            {
 044                Console.WriteLine("Ошибка отправки сообщения в телеграм");
 045                Console.WriteLine(e.Message, e);
 046            }
 56047        }
 48    }
 49}