private static void ValidationParameterDB(ClienteRequestDto requestDto, IEnumerable <ClienteEntity> listEntity)
        {
            if (requestDto.TipoPersona == default)
            {
                throw new ClienteTipoPersonaNullException(requestDto.TipoPersona);
            }

            var usernameExist = listEntity.Where(x => x.Nombre == requestDto.Nombre && x.Id != requestDto.Id).Any();

            if (usernameExist)
            {
                throw new ClientenameAlreadyExistException(requestDto.Nombre);
            }

            var codeExist = listEntity.Where(x => x.CodigoTipoDocumento == requestDto.CodigoTipoDocumento &&
                                             x.TipoDocumentoId == requestDto.TipoDocumentoId &&
                                             x.Id != requestDto.Id);

            if (codeExist.Any())
            {
                throw new ClienteCodigoTipoDocumentoException(requestDto.CodigoTipoDocumento);
            }

            if (requestDto.FechaNacimiento == default)
            {
                throw new ClienteFechaNacimientoException(requestDto.FechaNacimiento);
            }
            if (requestDto.FechaRegistro == default)
            {
                throw new ClienteFechaRegistroException(requestDto.FechaRegistro);
            }
        }
 private static void ValidationDto(ClienteRequestDto requestDto)
 {
     if (requestDto == null)
     {
         throw new ClienteRequestDtoNullException();
     }
 }
        public Task <bool> Delete(ClienteRequestDto requestDto)
        {
            ValidationDto(requestDto);
            var entity = ValidationEntity(requestDto);

            return(_clienteRepositorio.Delete(entity));
        }
        public Task <ClienteDto> Get(ClienteRequestDto requestDto)
        {
            ValidationDto(requestDto);
            var entity = ValidationEntity(requestDto);

            return(Task.FromResult(_mapper.Map <ClienteDto>(entity)));
        }
Exemplo n.º 5
0
        public async void Cliente_GetAll_Test_IntegrationTest()
        {
            ServiceProvider provider = ServiceCollectionCliente();

            var clienteService     = provider.GetRequiredService <IClienteService>();
            var clienteRepositorio = provider.GetRequiredService <IClienteRepositorio>();
            var mapper             = provider.GetRequiredService <IMapper>();
            var documentoService   = provider.GetRequiredService <ITipoDocumentoService>();
            var documentoRepo      = provider.GetRequiredService <ITipoDocumentoRepositorio>();

            var dtoDocumento = new TipoDocumentoRequestDto
            {
                Id = Guid.NewGuid(),
                NombreTipoDocumento = "fakeDocumentofakeCliente03",
            };
            var documento = documentoRepo
                            .SearchMatching <TipoDocumentoEntity>(x => x.NombreTipoDocumento == dtoDocumento.NombreTipoDocumento || x.Id == dtoDocumento.Id)
                            .FirstOrDefault();

            if (documento != null || documento != default)
            {
                _ = await documentoRepo.Delete(documento).ConfigureAwait(false);
            }

            _ = await documentoService.Insert(dtoDocumento).ConfigureAwait(false);

            var dtoCliente = new ClienteRequestDto
            {
                Id                  = Guid.Parse("45c2a9b5-1eac-48d3-83a4-ff692326e4f7"),
                Nombre              = "NombreClienteGetAll",
                Apellido            = "NombreClienteGetAll",
                NumeroTelefono      = 123456789,
                CorreoElectronico   = "*****@*****.**",
                CodigoTipoDocumento = "000000008",
                TipoPersona         = (global::Evaluacion.Aplicacion.Dto.Especificas.Personas.TipoPersona)TipoPersona.Juridico,
                FechaNacimiento     = DateTimeOffset.Now,
                FechaRegistro       = DateTimeOffset.Now,
                TipoDocumentoId     = dtoDocumento.Id,
            };

            var cliente = clienteRepositorio
                          .SearchMatching <ClienteEntity>(x => x.Nombre == dtoCliente.Nombre || x.Id == dtoCliente.Id)
                          .FirstOrDefault();

            if (cliente != null || cliente != default)
            {
                _ = await clienteRepositorio.Delete(cliente).ConfigureAwait(false);
            }

            _ = await clienteService.Insert(dtoCliente).ConfigureAwait(false);

            var result = mapper.Map <IEnumerable <ClienteEntity> >(await clienteService.GetAll().ConfigureAwait(false));

            Assert.NotNull(result.ToString());
            Assert.True(result.Any());

            _ = await clienteService.Delete(dtoCliente).ConfigureAwait(false);

            _ = await documentoService.Delete(dtoDocumento).ConfigureAwait(false);
        }
        public Task <bool> Update(ClienteRequestDto requestDto)
        {
            ValidationDto(requestDto);
            var entity = ValidationEntity(requestDto);

            #region Validation If
            if (!string.IsNullOrEmpty(requestDto.Nombre))
            {
                entity.Nombre = requestDto.Nombre;
            }

            if (!string.IsNullOrEmpty(requestDto.Apellido))
            {
                entity.Apellido = requestDto.Apellido;
            }

            if (requestDto.FechaNacimiento != default)
            {
                entity.FechaNacimiento = requestDto.FechaNacimiento;
            }

            if (requestDto.FechaRegistro != default)
            {
                entity.FechaRegistro = requestDto.FechaRegistro;
            }

            if (requestDto.NumeroTelefono != default)
            {
                entity.NumeroTelefono = requestDto.NumeroTelefono;
            }

            if (!string.IsNullOrEmpty(requestDto.CorreoElectronico))
            {
                entity.CorreoElectronico = requestDto.CorreoElectronico;
            }

            if (requestDto.TipoDocumentoId != default)
            {
                entity.TipoDocumentoId = requestDto.TipoDocumentoId;
            }

            if (!string.IsNullOrEmpty(requestDto.CodigoTipoDocumento))
            {
                entity.CodigoTipoDocumento = requestDto.CodigoTipoDocumento;
            }

            if (requestDto.TipoPersona != default)
            {
                entity.TipoPersona = (Dominio.Core.Especificas.Personas.TipoPersona)requestDto.TipoPersona;
            }
            #endregion

            var listentity = _clienteRepositorio
                             .GetAll <ClienteEntity>();

            ValidationCliente(requestDto);
            ValidationParameterDB(_mapper.Map <ClienteRequestDto>(entity), listentity);

            return(_clienteRepositorio.Update(entity));
        }
Exemplo n.º 7
0
        public async void Cliente_Delete_Test_IntegrationTest()
        {
            ServiceProvider provider = ServiceCollectionCliente();

            var clienteService     = provider.GetRequiredService <IClienteService>();
            var clienteRepositorio = provider.GetRequiredService <IClienteRepositorio>();
            var documentoService   = provider.GetRequiredService <ITipoDocumentoService>();
            var documentoRepo      = provider.GetRequiredService <ITipoDocumentoRepositorio>();

            var dtoDocumento = new TipoDocumentoRequestDto
            {
                Id = Guid.NewGuid(),
                NombreTipoDocumento = "fakeDocumentofakeCliente01",
            };
            var documento = documentoRepo
                            .SearchMatching <TipoDocumentoEntity>(x => x.NombreTipoDocumento == dtoDocumento.NombreTipoDocumento || x.Id == dtoDocumento.Id)
                            .FirstOrDefault();

            if (documento != null || documento != default)
            {
                _ = await documentoRepo.Delete(documento).ConfigureAwait(false);
            }

            _ = await documentoService.Insert(dtoDocumento).ConfigureAwait(false);

            var dtoCliente = new ClienteRequestDto
            {
                Id                  = Guid.NewGuid(),
                Nombre              = "fakeProveedorDeleteTestI1",
                Apellido            = "fakeProveedorDeleteTestI1",
                NumeroTelefono      = 123456789,
                CorreoElectronico   = "*****@*****.**",
                CodigoTipoDocumento = "000000001",
                TipoPersona         = (global::Evaluacion.Aplicacion.Dto.Especificas.Personas.TipoPersona)TipoPersona.Juridico,
                FechaNacimiento     = DateTimeOffset.Now,
                FechaRegistro       = DateTimeOffset.Now,
                TipoDocumentoId     = dtoDocumento.Id,
            };

            var cliente = clienteRepositorio
                          .SearchMatching <ClienteEntity>(x => x.Nombre == dtoCliente.Nombre || x.Id == dtoCliente.Id)
                          .FirstOrDefault();

            if (cliente != null || cliente != default)
            {
                _ = await clienteRepositorio.Delete(cliente).ConfigureAwait(false);
            }

            _ = await clienteService.Insert(dtoCliente).ConfigureAwait(false);

            var dtoCliente2 = new ClienteRequestDto
            {
                Id = dtoCliente.Id
            };
            var result = await clienteService.Delete(dtoCliente2).ConfigureAwait(false);

            Assert.True(result);
            _ = await documentoService.Delete(dtoDocumento).ConfigureAwait(false);
        }
        public async Task <IActionResult> Post(ClienteRequestDto clienteRequestDto)
        {
            var cliente = _mapper.Map <ClienteRequestDto, Cliente>(clienteRequestDto);
            await _clienteService.AddCliente(cliente);

            var clienteresponseDto = _mapper.Map <Cliente, ClienteResponseDto>(cliente);
            var response           = new ApiResponse <ClienteResponseDto>(clienteresponseDto);

            return(Ok(response));
        }
        private void ValidationCliente(ClienteRequestDto requestDto)
        {
            var listdocumento = _tipoDocumentoRepositorio
                                .SearchMatching <TipoDocumentoEntity>(x => x.Id == requestDto.TipoDocumentoId).FirstOrDefault();

            if (listdocumento.NombreTipoDocumento.ToLower() == "nit".ToLower())
            {
                throw new ClienteTipoDocumentoException(requestDto.TipoDocumentoId.ToString());
            }
        }
        private ClienteEntity ValidationEntity(ClienteRequestDto requestDto)
        {
            var entity = _clienteRepositorio.SearchMatchingOneResult <ClienteEntity>(x => x.Id == requestDto.Id);

            if (entity == null || entity == default)
            {
                throw new ClienteNoExistException(requestDto.Nombre);
            }
            return(entity);
        }
Exemplo n.º 11
0
        public async Task <ClienteResponseDto> ClienteManagementUpdate(ClienteRequestDto requestDto)
        {
            var result = await _clienteService.Update(requestDto).ConfigureAwait(false) != default;

            return(new ClienteResponseDto
            {
                Aceptado = result,
                StatusCode = result ? HttpStatusCode.OK : HttpStatusCode.Unauthorized,
                StatusDescription = result ? "Update" : "No Update"
            });
        }
        public async Task Validar_TipoPersona_Cliente_Fail()
        {
            var clienteRepoMock = new Mock <IClienteRepositorio>();

            var Listentity = new List <ClienteEntity>
            {
                new ClienteEntity
                {
                    Id     = Guid.NewGuid(),
                    Nombre = "Nombre",
                    CodigoTipoDocumento = "123456789",
                    TipoDocumentoId     = Guid.Parse("581E3E67-82E2-4F1F-B379-9BD870DB669E"),
                    TipoPersona         = (global::Evaluacion.Dominio.Core.Especificas.Personas.TipoPersona)TipoPersona.Natural,
                }
            };
            var tipoDocumentoRepoMock = new Mock <ITipoDocumentoRepositorio>();

            _ = tipoDocumentoRepoMock
                .Setup(m => m.SearchMatching(It.IsAny <Expression <Func <TipoDocumentoEntity, bool> > >()))
                .Returns(new List <TipoDocumentoEntity> {
                new TipoDocumentoEntity
                {
                    Id = Guid.NewGuid(),
                    NombreTipoDocumento = "fakenonit"
                }
            });
            _ = clienteRepoMock
                .Setup(m => m.GetAll <ClienteEntity>())
                .Returns(Listentity);

            var service = new ServiceCollection();

            service.AddTransient(_ => clienteRepoMock.Object);
            service.AddTransient(_ => tipoDocumentoRepoMock.Object);

            service.ConfigurePersonasService(new DbSettings());

            var provider       = service.BuildServiceProvider();
            var clienteService = provider.GetRequiredService <IClienteService>();

            var dtoCliente = new ClienteRequestDto
            {
                Nombre          = "fake",
                FechaNacimiento = DateTimeOffset.Now,
                FechaRegistro   = DateTimeOffset.Now,
                TipoDocumentoId = Guid.Parse("581E3E67-82E2-4F1F-B379-9BD870DB669E")
            };

            _ = await Assert.ThrowsAsync <ClienteTipoPersonaNullException>(() => clienteService.Insert(dtoCliente)).ConfigureAwait(false);

            dtoCliente.TipoPersona = 0;
            _ = await Assert.ThrowsAsync <ClienteTipoPersonaNullException>(() => clienteService.Insert(dtoCliente)).ConfigureAwait(false);
        }
        public async Task <Guid> Insert(ClienteRequestDto requestDto)
        {
            ValidationDto(requestDto);
            ValidationCliente(requestDto);

            var listentity = _clienteRepositorio
                             .GetAll <ClienteEntity>();

            ValidationParameterDB(requestDto, listentity);

            var response = await _clienteRepositorio.Insert(_mapper.Map <ClienteEntity>(requestDto)).ConfigureAwait(false);

            return(response.Id);
        }
Exemplo n.º 14
0
 public async Task <ClienteDto> Post(ClienteRequestDto clienteDto) => await Post <ClienteRequestDto>("InsertCliente", clienteDto).ConfigureAwait(false);
Exemplo n.º 15
0
 public Task <ClienteDto> ClienteManagementGet(ClienteRequestDto requestDto)
 {
     return(_clienteService.Get(requestDto));
 }
 public async Task <ClienteResponseDto> DeleteCliente(ClienteRequestDto requestDto) =>
 await _fachadaPersonasService.ClienteManagementDelete(requestDto).ConfigureAwait(false);
 public async Task <ClienteDto> GetCliente(ClienteRequestDto requestDto) =>
 await _fachadaPersonasService.ClienteManagementGet(requestDto).ConfigureAwait(false);