< Summary

Information
Class: KT.Modules.Alarm.Core.Application.NotificationService
Assembly: KT.Modules.Alarm
File(s): G:\NetProjects\KeepTrack\src\Modules\KT.Modules.Alarm\Core\Application\NotificationService.cs
Line coverage
96%
Covered lines: 28
Uncovered lines: 1
Coverable lines: 29
Total lines: 42
Line coverage: 96.5%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
SendNotificationAsync()100%8893.33%
CreateNotification(...)100%11100%

File(s)

G:\NetProjects\KeepTrack\src\Modules\KT.Modules.Alarm\Core\Application\NotificationService.cs

#LineLine coverage
 1using FirebaseAdmin.Messaging;
 2using KT.Modules.Alarm.Presentation.Contracts;
 3using KT.Modules.Alarm.Presentation.Dto;
 4using KT.Modules.Security.Presentation.Contracts;
 5
 6namespace KT.Modules.Alarm.Core.Application
 7{
 38    internal class NotificationService(IDeviceTokenService deviceTokenService, IAllConnectionsService allConnectionsServ
 9    {
 10        public async Task SendNotificationAsync(NotificationDto notificationDto)
 311        {
 312            var devicesId = new List<string>();
 313            var userAsociated = await allConnectionsService.GetAsync(notificationDto.UserId);
 314            if (userAsociated.Count <= 0)
 115                throw new InvalidOperationException("There are no contacts to alert");
 1216            foreach (ConnectionDto user in userAsociated)
 317            {
 318                string deviceId = await deviceTokenService.GetAsync(user.UserId);
 319                if (!string.IsNullOrEmpty(deviceId))
 220                    devicesId.Add(deviceId);
 321            }
 222            if (devicesId.Count <= 0)
 123                throw new InvalidOperationException("Users do not have a device token.");
 124            await FirebaseMessaging.DefaultInstance.SendEachForMulticastAsync(CreateNotification(notificationDto, device
 025        }
 26
 27        private MulticastMessage CreateNotification(NotificationDto notificationDto, List<string> devicesId)
 128        {
 129            var message = new MulticastMessage()
 130            {
 131                Tokens = devicesId,
 132                Data = new Dictionary<string, string>()
 133                {
 134                    { "title", notificationDto.Title },
 135                    { "body", notificationDto.Message },
 136                    { "payload", notificationDto.Payload }
 137                }
 138            };
 139            return message;
 140        }
 41    }
 42}