| @@ -8,10 +8,10 @@ | |||
| public DateTime? Date { get; set; } | |||
| public string? Link { get; set; } | |||
| public int? SchedulerId { get; set; } | |||
| public User Scheduler { get; set; } | |||
| public User? Scheduler { get; set; } | |||
| public int SelectionLevelId { get; set; } | |||
| public SelectionLevel SelectionLevel { get; set; } | |||
| public SelectionLevel? SelectionLevel { get; set; } | |||
| public int ApplicantId { get; set; } | |||
| public Applicant Applicant { get; set; } | |||
| public Applicant? Applicant { get; set; } | |||
| } | |||
| } | |||
| @@ -11,11 +11,12 @@ | |||
| { | |||
| _selectionLevelService = selectionLevelService; | |||
| } | |||
| [Authorize] | |||
| [HttpGet] | |||
| public async Task<IActionResult> GetAll() => | |||
| Ok(await _selectionLevelService.GetAllAsync()); | |||
| [Authorize] | |||
| [HttpGet("{id}")] | |||
| public async Task<IActionResult> GetById([FromRoute] int id) => | |||
| Ok(await _selectionLevelService.GetByIdAsync(id)); | |||
| @@ -14,11 +14,12 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| { | |||
| _selectionProcessesService = selectionProcessesService; | |||
| } | |||
| //[Authorize] | |||
| //[HttpGet] | |||
| //public async Task<IActionResult> GetAll() => | |||
| // Ok(await _selectionProcessesService.GetAllAsync()); | |||
| [HttpGet] | |||
| public async Task<IActionResult> GetAll() => | |||
| Ok(await _selectionProcessesService.GetAllAsync()); | |||
| [Authorize] | |||
| [HttpPost] | |||
| public async Task<IActionResult> FinishSelectionProcess([FromBody] SelectionProcessCreateDto model) => | |||
| Ok(await _selectionProcessesService.FinishSelectionProcess(model)); | |||
| @@ -30,18 +31,12 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| // return StatusCode((int)HttpStatusCode.Created); | |||
| //} | |||
| [HttpPut("{id}")] | |||
| public async Task<IActionResult> Update([FromBody] SelectionProcessCreateDto request, [FromRoute] int id) | |||
| { | |||
| await _selectionProcessesService.UpdateAsync(id, request); | |||
| return Ok(); | |||
| } | |||
| [HttpDelete("{id}")] | |||
| public async Task<IActionResult> DeleteInsurer([FromRoute] int id) | |||
| { | |||
| await _selectionProcessesService.DeleteAsync(id); | |||
| return NoContent(); | |||
| } | |||
| //[Authorize] | |||
| //[HttpPut("{id}")] | |||
| //public async Task<IActionResult> Update([FromBody] SelectionProcessCreateDto request, [FromRoute] int id) | |||
| //{ | |||
| // await _selectionProcessesService.UpdateAsync(id, request); | |||
| // return Ok(); | |||
| //} | |||
| } | |||
| } | |||
| @@ -1,4 +1,5 @@ | |||
| using Diligent.WebAPI.Contracts.DTOs.Applicant; | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | |||
| using Diligent.WebAPI.Contracts.Exceptions; | |||
| using NSubstitute; | |||
| @@ -24,7 +25,13 @@ namespace Diligent.WebAPI.Tests.Controllers | |||
| GithubLink = null, | |||
| LinkedlnLink = null, | |||
| PhoneNumber = "432424", | |||
| Position = ".NET Developer" | |||
| Position = ".NET Developer", | |||
| SelectionProcesses = new List<SelectionProcessResposneWithoutApplicantDto> | |||
| { | |||
| new SelectionProcessResposneWithoutApplicantDto{ Status = ""}, | |||
| new SelectionProcessResposneWithoutApplicantDto{ Status = ""}, | |||
| new SelectionProcessResposneWithoutApplicantDto{ Status = ""} | |||
| } | |||
| }; | |||
| } | |||
| @@ -39,6 +46,17 @@ namespace Diligent.WebAPI.Tests.Controllers | |||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||
| } | |||
| [Fact] | |||
| public async Task GetProcesses_ShouldReturn_200OK_WhenApplicantExists() | |||
| { | |||
| _applicantService.GetApplicantWithSelectionProcessesById(Arg.Any<int>()).Returns(_applicant); | |||
| ApplicantsController applicantsController = new(_applicantService); | |||
| var result = await applicantsController.GetProcesses(1); | |||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||
| } | |||
| [Fact] | |||
| public async Task GetById_ShouldThrowEntityNotFooundException_WhenApplicantDontExist() | |||
| { | |||
| @@ -48,6 +66,15 @@ namespace Diligent.WebAPI.Tests.Controllers | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.GetById(1000)); | |||
| } | |||
| [Fact] | |||
| public async Task GetProcesses_ShouldThrowEntityNotFooundException_WhenApplicantDoesnotExist() | |||
| { | |||
| _applicantService.When(x => x.GetApplicantWithSelectionProcessesById(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); }); | |||
| ApplicantsController applicantsController = new(_applicantService); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.GetProcesses(1000)); | |||
| } | |||
| [Fact] | |||
| public async Task GetAll_ShouldReturn_200OK_Always() | |||
| { | |||
| @@ -0,0 +1,60 @@ | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionLevel; | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | |||
| using Diligent.WebAPI.Contracts.Exceptions; | |||
| namespace Diligent.WebAPI.Tests.Controllers | |||
| { | |||
| public class SelectionLevelsControllerTests | |||
| { | |||
| private ISelectionLevelService _service = Substitute.For<ISelectionLevelService>(); | |||
| private readonly SelectionLevelResposneDto _selectionLevel; | |||
| public SelectionLevelsControllerTests() | |||
| { | |||
| _selectionLevel = new SelectionLevelResposneDto | |||
| { | |||
| Id = 1, | |||
| Name = "HR intervju" | |||
| }; | |||
| } | |||
| [Fact] | |||
| public async Task GetById_ShouldReturn_200OK_WhenLevelExist() | |||
| { | |||
| _service.GetByIdAsync(Arg.Any<int>()).Returns(_selectionLevel); | |||
| SelectionLevelsController controller = new(_service); | |||
| var result = await controller.GetById(1); | |||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||
| } | |||
| [Fact] | |||
| public async Task GetById_ShouldThrowEntityNotFooundException_WhenLevelDoesnotExist() | |||
| { | |||
| _service.When(x => x.GetByIdAsync(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); }); | |||
| SelectionLevelsController controller = new(_service); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.GetById(1000)); | |||
| } | |||
| [Fact] | |||
| public async Task GetAll_ShouldReturn_200OK_Always() | |||
| { | |||
| var levels = new List<SelectionLevelResponseWithDataDto> | |||
| { | |||
| new SelectionLevelResponseWithDataDto | |||
| { | |||
| Id = 1, | |||
| Name = "HR intervju", | |||
| SelectionProcesses = new List<SelectionProcessResposneDto>() | |||
| } | |||
| }; | |||
| _service.GetAllAsync().Returns(levels); | |||
| SelectionLevelsController controller = new(_service); | |||
| var result = await controller.GetAll(); | |||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,48 @@ | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | |||
| using Diligent.WebAPI.Contracts.Exceptions; | |||
| namespace Diligent.WebAPI.Tests.Controllers | |||
| { | |||
| public class SelectionProcessesControllerTests | |||
| { | |||
| private ISelectionProcessService _service = Substitute.For<ISelectionProcessService>(); | |||
| private readonly SelectionProcessResposneDto _selectionProcess; | |||
| public SelectionProcessesControllerTests() | |||
| { | |||
| _selectionProcess = new SelectionProcessResposneDto | |||
| { | |||
| Id = 1, | |||
| Name = "HR intervju" | |||
| }; | |||
| } | |||
| [Fact] | |||
| public async Task FinishSelectionProcess_ShouldReturn_True_WhenProcessExists() | |||
| { | |||
| _service.FinishSelectionProcess(Arg.Any<SelectionProcessCreateDto>()).Returns(true); | |||
| SelectionProcessesController controller = new(_service); | |||
| var result = await controller.FinishSelectionProcess(new SelectionProcessCreateDto()); | |||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||
| } | |||
| [Fact] | |||
| public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist() | |||
| { | |||
| _service.When(x => x.FinishSelectionProcess(Arg.Any<SelectionProcessCreateDto>())).Do(x => { throw new EntityNotFoundException(); }); | |||
| SelectionProcessesController controller = new(_service); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.FinishSelectionProcess(new SelectionProcessCreateDto())); | |||
| } | |||
| [Fact] | |||
| public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessWasInLastLevel() | |||
| { | |||
| _service.When(x => x.FinishSelectionProcess(Arg.Any<SelectionProcessCreateDto>())).Do(x => { throw new EntityNotFoundException(); }); | |||
| SelectionProcessesController controller = new(_service); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.FinishSelectionProcess(new SelectionProcessCreateDto())); | |||
| } | |||
| } | |||
| } | |||
| @@ -13,7 +13,7 @@ namespace Diligent.WebAPI.Tests | |||
| .Options; | |||
| var databaseContext = new DatabaseContext(options); | |||
| databaseContext.Database.EnsureCreated(); | |||
| if (!await databaseContext.Applicants.AnyAsync()) | |||
| if (!await databaseContext.Set<T>().AnyAsync()) | |||
| { | |||
| await databaseContext.Set<T>().AddRangeAsync(applicants); | |||
| await databaseContext.SaveChangesAsync(); | |||
| @@ -2,6 +2,7 @@ | |||
| using Diligent.WebAPI.Business.MappingProfiles; | |||
| using Diligent.WebAPI.Business.Services; | |||
| using Diligent.WebAPI.Contracts.DTOs.Applicant; | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | |||
| using Diligent.WebAPI.Contracts.Exceptions; | |||
| using Diligent.WebAPI.Data.Entities; | |||
| @@ -28,7 +29,13 @@ namespace Diligent.WebAPI.Tests.Services | |||
| GithubLink = null, | |||
| LinkedlnLink = null, | |||
| PhoneNumber = "432424", | |||
| Position = ".NET Developer" | |||
| Position = ".NET Developer", | |||
| SelectionProcesses = new List<SelectionProcess> | |||
| { | |||
| new SelectionProcess{ Id = 1, Status = "", Name = ""}, | |||
| new SelectionProcess{ Id = 2, Status = "", Name = ""}, | |||
| new SelectionProcess{ Id = 3, Status = "", Name = ""} | |||
| } | |||
| }; | |||
| _applicants = new List<Applicant> | |||
| { | |||
| @@ -39,7 +46,8 @@ namespace Diligent.WebAPI.Tests.Services | |||
| var configuration = new MapperConfiguration(cfg => cfg.AddProfiles( | |||
| new List<Profile> | |||
| { | |||
| new ApplicantMappingProfile() | |||
| new ApplicantMappingProfile(), | |||
| new SelectionProcessMappingProfile(), | |||
| })); | |||
| _mapper = new Mapper(configuration); | |||
| } | |||
| @@ -66,6 +74,19 @@ namespace Diligent.WebAPI.Tests.Services | |||
| result.Should().BeEquivalentTo(_mapper.Map<ApplicantViewDto>(_applicant)); | |||
| } | |||
| [Fact] | |||
| public async Task GetApplicantWithSelectionProcessesById_ShouldReturnApplicant_WhenApplicantExists() | |||
| { | |||
| var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); | |||
| ApplicantService applicantService = new(databaseContext, _mapper); | |||
| var result = await applicantService.GetApplicantWithSelectionProcessesById(1); | |||
| var processes = result.SelectionProcesses; | |||
| processes.Should().HaveCount(3); | |||
| result.Should().BeEquivalentTo(_mapper.Map<ApplicantViewDto>(_applicant)); | |||
| } | |||
| [Fact] | |||
| public async Task GetById_ShouldThrowEntityNotFooundException_WhenApplicantDontExist() | |||
| { | |||
| @@ -0,0 +1,65 @@ | |||
| using AutoMapper; | |||
| using Diligent.WebAPI.Business.MappingProfiles; | |||
| using Diligent.WebAPI.Business.Services; | |||
| using Diligent.WebAPI.Contracts.DTOs.Applicant; | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionLevel; | |||
| using Diligent.WebAPI.Contracts.Exceptions; | |||
| using Diligent.WebAPI.Data.Entities; | |||
| namespace Diligent.WebAPI.Tests.Services | |||
| { | |||
| public class SelectionLevelsServiceTests | |||
| { | |||
| private readonly IMapper _mapper; | |||
| private readonly List<SelectionLevel> _levels; | |||
| private readonly SelectionLevel _selectionLevel; | |||
| public SelectionLevelsServiceTests() | |||
| { | |||
| _selectionLevel = new SelectionLevel | |||
| { | |||
| Id = 1, | |||
| Name = "HR intervju", | |||
| SelectionProcesses = new List<SelectionProcess>() | |||
| }; | |||
| // configure mapper | |||
| var configuration = new MapperConfiguration(cfg => cfg.AddProfiles( | |||
| new List<Profile> | |||
| { | |||
| new SelectionLevelMappingProfile(), | |||
| })); | |||
| _mapper = new Mapper(configuration); | |||
| } | |||
| [Fact] | |||
| public async Task GetAll_ShouldReturnListOfLevels_Always() | |||
| { | |||
| var databaseContext = await Helpers<SelectionLevel>.GetDatabaseContext(_levels); | |||
| SelectionLevelService service = new(databaseContext, _mapper); | |||
| var result = await service.GetAllAsync(); | |||
| result.Should().HaveCount(4); | |||
| } | |||
| [Fact] | |||
| public async Task GetById_ShouldReturnLevel_WhenLevelExist() | |||
| { | |||
| var databaseContext = await Helpers<SelectionLevel>.GetDatabaseContext(_levels); | |||
| SelectionLevelService service = new(databaseContext, _mapper); | |||
| var result = await service.GetByIdAsync(1); | |||
| result.Should().BeEquivalentTo(_mapper.Map<SelectionLevelResposneDto>(_selectionLevel)); | |||
| } | |||
| [Fact] | |||
| public async Task GetById_ShouldThrowEntityNotFooundException_WhenLevelDoesnotExist() | |||
| { | |||
| var databaseContext = await Helpers<SelectionLevel>.GetDatabaseContext(_levels); | |||
| SelectionLevelService service = new(databaseContext, _mapper); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.GetByIdAsync(1000)); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,134 @@ | |||
| using AutoMapper; | |||
| using Diligent.WebAPI.Business.MappingProfiles; | |||
| using Diligent.WebAPI.Business.Services; | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionLevel; | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | |||
| using Diligent.WebAPI.Contracts.Exceptions; | |||
| using Diligent.WebAPI.Data.Entities; | |||
| namespace Diligent.WebAPI.Tests.Services | |||
| { | |||
| public class SelectionProcessServiceTests | |||
| { | |||
| private readonly IMapper _mapper; | |||
| private readonly List<SelectionProcess> _processes; | |||
| private readonly SelectionProcess _selectionProcess; | |||
| private readonly SelectionProcessCreateDto _selectionProcessCreateDto; | |||
| public SelectionProcessServiceTests() | |||
| { | |||
| _selectionProcessCreateDto = new SelectionProcessCreateDto | |||
| { | |||
| Id = 1, | |||
| ApplicantId = 1, | |||
| Date = DateTime.Now, | |||
| Link = "link", | |||
| Name = "custom name", | |||
| SchedulerId = 1, | |||
| SelectionLevelId = 4, | |||
| Status = "Obrađen" | |||
| }; | |||
| _selectionProcess = new SelectionProcess | |||
| { | |||
| Id = 1, | |||
| ApplicantId = 1, | |||
| Date = DateTime.Now, | |||
| Link = "link", | |||
| Name = "custom name", | |||
| SchedulerId = 1, | |||
| SelectionLevelId = 4, | |||
| Status = "Obrađen" | |||
| }; | |||
| _processes = new List<SelectionProcess> | |||
| { | |||
| _selectionProcess | |||
| }; | |||
| // configure mapper | |||
| var configuration = new MapperConfiguration(cfg => cfg.AddProfiles( | |||
| new List<Profile> | |||
| { | |||
| new SelectionProcessMappingProfile(), | |||
| })); | |||
| _mapper = new Mapper(configuration); | |||
| } | |||
| [Fact] | |||
| public async Task GetAll_ShouldReturnListOfProcesses_Always() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(databaseContext, _mapper); | |||
| var result = await service.GetAllAsync(); | |||
| result.Should().HaveCount(1); | |||
| } | |||
| [Fact] | |||
| public async Task GetById_ShouldReturnProcess_WhenProcessExist() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(databaseContext, _mapper); | |||
| var result = await service.GetByIdAsync(1); | |||
| result.Should().BeEquivalentTo(_mapper.Map<SelectionProcessResposneDto>(_selectionProcess)); | |||
| } | |||
| [Fact] | |||
| public async Task GetById_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(databaseContext, _mapper); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.GetByIdAsync(1000)); | |||
| } | |||
| [Fact] | |||
| public async Task FinishSelectionProcess_ShouldReturnTrueAndAddNewSelectionProcess_WhenProcessExists() | |||
| { | |||
| var process = new SelectionProcess | |||
| { | |||
| Id = 1, | |||
| ApplicantId = 1, | |||
| Date = DateTime.Now, | |||
| Link = "link", | |||
| Name = "custom name", | |||
| SchedulerId = 1, | |||
| SelectionLevelId = 1, | |||
| Status = "Zakazan" | |||
| }; | |||
| var processes = new List<SelectionProcess> | |||
| { | |||
| process | |||
| }; | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(processes); | |||
| SelectionProcessService service = new(databaseContext, _mapper); | |||
| var result = await service.FinishSelectionProcess(_selectionProcessCreateDto); | |||
| var newProcesses = await service.GetAllAsync(); | |||
| result.Should().BeTrue(); | |||
| newProcesses.Should().HaveCount(processes.Count() + 1); | |||
| } | |||
| [Fact] | |||
| public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(databaseContext, _mapper); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.FinishSelectionProcess(new SelectionProcessCreateDto { Id = 1000 })); | |||
| } | |||
| [Fact] | |||
| public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessIsInLastLevel() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(databaseContext, _mapper); | |||
| await Assert.ThrowsAsync<InvalidOperationException>(async () => await service.FinishSelectionProcess(new SelectionProcessCreateDto { Id = 1, SelectionLevelId = 4 })); | |||
| } | |||
| } | |||
| } | |||