< Summary

Information
Class: CoWorkingApp.Core.Application.Services.SeatService
Assembly: CoWorkingApp.Core
File(s): H:\Vicentico\Proyectos\CoWorkingApp Project\CoWorkingApp\CoWorkingApp.Core\Application\Services\SeatService.cs
Line coverage
100%
Covered lines: 42
Uncovered lines: 0
Coverable lines: 42
Total lines: 120
Line coverage: 100%
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 Cyclomatic complexity Line coverage
.ctor(...)100%1100%
GetAvailablesAsync()100%1100%
GetByNameAsync()100%4100%
UpdateProperties(...)100%4100%
IsValid(...)100%1100%

File(s)

H:\Vicentico\Proyectos\CoWorkingApp Project\CoWorkingApp\CoWorkingApp.Core\Application\Services\SeatService.cs

#LineLine coverage
 1using CoWorkingApp.Core.Application.Abstracts;
 2using CoWorkingApp.Core.Application.Contracts.Adapters;
 3using CoWorkingApp.Core.Application.Contracts.Repositories;
 4using CoWorkingApp.Core.Application.Contracts.Services;
 5using CoWorkingApp.Core.Domain.DTOs;
 6using CoWorkingApp.Core.Domain.Entities;
 7
 8namespace CoWorkingApp.Core.Application.Services
 9{
 10    /// <summary>
 11    /// Implementación concreta del servicio para la entidad Seat.
 12    /// </summary>
 13    public class SeatService : ServiceGeneric<ISeatRepository, Seat, SeatRequest, SeatResponse>, ISeatService
 14    {
 15        /// <summary>
 16        /// Constructor de la clase SeatService.
 17        /// </summary>
 18        /// <param name="seatRepository">El repositorio de asientos asociado al servicio.</param>
 15219        public SeatService(ISeatRepository seatRepository, IMapperAdapter mapper) : base(seatRepository, mapper) { }
 20
 21        // Implementación de métodos específicos de ISeatService
 22
 23        /// <summary>
 24        /// Obtiene todos los asientos disponibles.
 25        /// </summary>
 26        /// <returns>Una colección de respuestas de asientos disponibles.</returns>
 27        public async Task<IEnumerable<SeatResponse>> GetAvailablesAsync()
 328        {
 29            try
 330            {
 31                // Obtener los asientos disponibles desde el repositorio
 332                var seatsAvailable = await _repository.GetAvailablesAsync();
 33
 34                // Mapear los asientos disponibles a respuestas de asientos
 235                var responses = _mapper.Map<IEnumerable<Seat>, IEnumerable<SeatResponse>>(seatsAvailable).ToList();
 536                responses.ForEach(responses => responses.Success = true);
 237                return responses;
 38            }
 139            catch (Exception ex)
 140            {
 41                // Manejar excepciones y lanzar un error genérico
 142                return new List<SeatResponse> { HandleException(ex) };
 43            }
 344        }
 45
 46        /// <summary>
 47        /// Obtiene un asiento por su nombre.
 48        /// </summary>
 49        /// <param name="name">El nombre del asiento.</param>
 50        /// <returns>Una respuesta de asiento correspondiente al nombre proporcionado.</returns>
 51        public async Task<SeatResponse> GetByNameAsync(string name)
 952        {
 53            try
 954            {
 55                // Verificar si el nombre es nulo o vacío
 956                if (string.IsNullOrEmpty(name))
 257                {
 58                    // Si es nulo o vacío, lanzar una excepción
 259                    throw new ArgumentNullException("The name cannot be null or empty");
 60                }
 61
 62                // Obtener el asiento por su nombre desde el repositorio. Si no, lanzar una excepción
 763                var seat = await _repository.GetByNameAsync(name) ?? throw new ArgumentException($"Seat {name} not found
 64
 65                // Mapear el asiento a una respuesta de asiento y establecer el éxito en verdadero
 466                var response = _mapper.Map<Seat, SeatResponse>(seat);
 167                response.Success = true;
 168                return response;
 69            }
 270            catch (ArgumentNullException ex)
 271            {
 72                // Manejar la excepción de argumento nulo y generar una respuesta de error
 273                return HandleException(ex);
 74            }
 375            catch (ArgumentException ex)
 376            {
 77                // Manejar la excepción de argumento inválido y generar una respuesta de error
 378                return HandleException(ex);
 79            }
 380            catch (Exception)
 381            {
 82                // Manejar excepciones inesperadas y generar una respuesta de error
 383                var exception = new Exception();
 384                return HandleException(exception);
 85            }
 986        }
 87
 88        // Implementación de métodos abstractos de ServiceGeneric
 89
 90        /// <summary>
 91        /// ACTualiza las propiedades de un asiento existente con los valores de una solicitud de asiento.
 92        /// </summary>
 93        /// <param name="existingEntity">La entidad de asiento existente que se actualizará.</param>
 94        /// <param name="request">La solicitud de asiento que contiene los nuevos valores.</param>
 95        /// <returns>El asiento actualizado.</returns>
 96        protected override Seat UpdateProperties(Seat existingEntity, SeatRequest request)
 1397        {
 98            // ACTualizar las propiedades del asiento existente con los valores de la solicitud
 1399            return new Seat
 13100            {
 13101                Name = string.IsNullOrEmpty(request.Name) ? existingEntity.Name : request.Name,
 13102                IsBlocked = request.IsBlocked,
 13103                Description = string.IsNullOrEmpty(request.Description) ? existingEntity.Description : request.Descripti
 13104            };
 13105        }
 106
 107        /// <summary>
 108        /// Verifica si un asiento es válido.
 109        /// </summary>
 110        /// <param name="entity">El asiento que se va a validar.</param>
 111        /// <returns>True si el asiento es válido, False en caso contrario.</returns>
 112        protected override bool IsValid(Seat entity)
 21113        {
 114            // Verificar si la entidad es válida (en este caso, el nombre no puede ser nulo o vacío)
 21115            return !string.IsNullOrEmpty(entity.Name);
 21116        }
 117
 118        // Otros métodos específicos para SeatService
 119    }
 120}