public void DeleteEmployed_Successfult_Test() { var employedRepoMock = new Mock <IEmployedRepository>(); employedRepoMock .Setup(e => e.SearchMatching(It.IsAny <Expression <Func <EmployedEntity, bool> > >())) .Returns(new List <EmployedEntity> { new EmployedEntity { EmployedId = Guid.NewGuid() } }); employedRepoMock .Setup(e => e.Delete(It.IsAny <EmployedEntity>())) .Returns(() => { return(true); }); var service = new ServiceCollection(); service.AddTransient(_ => employedRepoMock.Object); service.ConfigurePeopleManagementService(new DbSettings()); var provider = service.BuildServiceProvider(); var employedSvc = provider.GetRequiredService <IEmployedService>(); var newEmployed = new EmployedRequestDto { EmployedId = Guid.Parse("31826538-6b06-4021-95c2-27fb184ac4fe") }; var responseDelete = employedSvc.DeleteEmployed(newEmployed); Assert.NotEqual(default, responseDelete);
public bool DeleteEmployed(EmployedRequestDto request) { if (request.EmployedId == default) { throw new IdCannotNullOrEmptyException(); } ValidateEmployedIdExist(request); return(_repoEmployed.Delete(_mapper.Map <EmployedEntity>(request))); }
private void ValidateEmployedIdExist(EmployedRequestDto request) { var employedIdExist = _repoEmployed .SearchMatching <EmployedEntity>(dt => dt.EmployedId == request.EmployedId).Any(); if (!employedIdExist) { throw new DontExistIdException(); } }
public void Throw_DontExistIdException_when_id_it_isnt() { var employedRepoMock = new Mock <IEmployedRepository>(); employedRepoMock .Setup(x => x.SearchMatching(It.IsAny <Expression <Func <EmployedEntity, bool> > >())) .Returns(new List <EmployedEntity>()); var service = new ServiceCollection(); service.AddTransient(_ => employedRepoMock.Object); service.ConfigurePeopleManagementService(new DbSettings()); var provider = service.BuildServiceProvider(); var employedSvc = provider.GetRequiredService <IEmployedService>(); var newEmployed = new EmployedRequestDto { EmployedId = Guid.NewGuid(), }; Assert.Throws <DontExistIdException>(() => employedSvc.DeleteEmployed(newEmployed)); }
public EmployedResponseDto DeleteEmployed(EmployedRequestDto request) => _employedFacade.DeleteEmployed(request);