< Summary

Information
Class: KT.Modules.Alarm.Core.Application.AllConnectionsService
Assembly: KT.Modules.Alarm
File(s): G:\NetProjects\KeepTrack\src\Modules\KT.Modules.Alarm\Core\Application\AllConnectionsService.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 38
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetAsync()83.33%66100%

File(s)

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

#LineLine coverage
 1using KT.Modules.Alarm.Core.Domain.Ports;
 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{
 28    internal class AllConnectionsService(IConnectionRepository connectionRepository, ISearchUserService searchUserServic
 9    {
 10        public async Task<List<ConnectionDto>> GetAsync(string userId)
 211        {
 12            try
 213            {
 214                if (string.IsNullOrEmpty(userId))
 115                    throw new ArgumentNullException(nameof(userId));
 116                var connections = await connectionRepository.GetConnectionUsersAsync(userId);
 117                var connectionDto = new List<ConnectionDto>();
 518                foreach (var connection in connections)
 119                {
 120                    string user = connection.UserId1 == userId ? connection.UserId2 : connection.UserId1;
 121                    var userDto = await searchUserService.SearchByIdAsync(user);
 122                    connectionDto.Add(new ConnectionDto
 123                    {
 124                        IdConnection = connection.IdConnection,
 125                        UserId = userDto.Id,
 126                        ContactName = userDto.Username,
 127                        CreatedAt = connection.CreatedAt
 128                    });
 129                }
 130                return connectionDto;
 31            }
 132            catch (Exception ex)
 133            {
 134                throw new Exception("An error occurred while retrieving connections.", ex);
 35            }
 136        }
 37    }
 38}