| @@ -17,4 +17,5 @@ | |||
| /Diligent.WebAPI.Contracts/obj | |||
| /Diligent.WebAPI.Tests/bin/Debug/net6.0 | |||
| /Diligent.WebAPI.Tests/obj/Debug/net6.0 | |||
| /Diligent.WebAPI.Tests/obj | |||
| /Diligent.WebAPI.Tests/obj | |||
| /Diligent.WebAPI.Tests/coverageresults | |||
| @@ -1,6 +1,7 @@ | |||
| | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionLevel; | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | |||
| using Diligent.WebAPI.Contracts.DTOs.Stats; | |||
| namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| { | |||
| @@ -10,5 +11,6 @@ namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| Task<SelectionLevelResposneDto> GetByIdAsync(int id); | |||
| Task<SelectionLevel> GetByIdEntity(int id); | |||
| List<SelectionLevelResponseWithDataDto> GetFilteredLevelsAsync(SelectionProcessFilterDto filters); | |||
| Task<List<SelectionLevelInfoDto>> GetCountByLevels(List<string> statuses); | |||
| } | |||
| } | |||
| @@ -8,7 +8,6 @@ namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| { | |||
| Task<List<SelectionProcessResposneDto>> GetAllAsync(); | |||
| Task<bool> FinishSelectionProcess(SelectionProcessCreateDto model); | |||
| Task<List<SelectionLevelInfoDto>> GetCountByLevels(List<string> statuses); | |||
| Task UpdateSelectionProcessStatusAsync(int id, SelectionProcessUpdateStatusDto selectionProcessUpdateStatusDto); | |||
| Task StatusUpdate(StatusChangeDTO model); | |||
| Task InterviewerUpdate(InterviewerUpdateDTO model); | |||
| @@ -1,4 +1,6 @@ | |||
| namespace Diligent.WebAPI.Business.Services | |||
| using Diligent.WebAPI.Contracts.DTOs.Stats; | |||
| namespace Diligent.WebAPI.Business.Services | |||
| { | |||
| public class SelectionLevelService : ISelectionLevelService | |||
| { | |||
| @@ -80,5 +82,22 @@ | |||
| return result; | |||
| } | |||
| public async Task<List<SelectionLevelInfoDto>> GetCountByLevels(List<string> statuses) | |||
| { | |||
| _logger.LogInformation("Start getting all Selection levels"); | |||
| var res = await _context.SelectionLevels.Include(n => n.SelectionProcesses).ToListAsync(); | |||
| _logger.LogInformation($"Received {res.Count} selection levels"); | |||
| _logger.LogInformation("Mapping levels with process counts to SelectionLevelInfo"); | |||
| var resMapped = res.Select(n => new SelectionLevelInfoDto | |||
| { | |||
| Level = n.Name, | |||
| CountAll = n.SelectionProcesses.Count, | |||
| CountDone = n.SelectionProcesses.Where(n => statuses.Contains(n.Status)).Count() | |||
| }).ToList(); | |||
| return resMapped; | |||
| } | |||
| } | |||
| } | |||
| @@ -17,13 +17,6 @@ namespace Diligent.WebAPI.Business.Services | |||
| _userManager = userManager; | |||
| } | |||
| public SelectionProcessService(DatabaseContext context, IMapper mapper, ILogger<SelectionProcessService> logger) | |||
| { | |||
| _context = context; | |||
| _mapper = mapper; | |||
| _logger = logger; | |||
| } | |||
| public async Task<List<SelectionProcessResposneDto>> GetAllAsync() | |||
| { | |||
| _logger.LogInformation("Start getting all Selection Processes"); | |||
| @@ -50,26 +43,22 @@ namespace Diligent.WebAPI.Business.Services | |||
| sp.Status = "Odrađen"; | |||
| _logger.LogInformation($"Skipping throught levels to come to next level"); | |||
| var nextLevel = _context.SelectionLevels.AsEnumerable() | |||
| .SkipWhile(obj => obj.Id != sp.SelectionLevelId) | |||
| .Skip(1).First(); | |||
| if (nextLevel is null) | |||
| if (sp.SelectionLevelId == _context.SelectionLevels.Last().Id) | |||
| { | |||
| _logger.LogError($"Applicant is in the last selection level"); | |||
| throw new EntityNotFoundException("Candidate came to the last selection level"); | |||
| // ovde sacuvati promene i return odraditi | |||
| // da ne bi pravilo novi proces | |||
| // exception treba ukloniti | |||
| } | |||
| var nextLevel = _context.SelectionLevels.AsEnumerable() | |||
| .SkipWhile(obj => obj.Id != sp.SelectionLevelId) | |||
| .Skip(1).First(); | |||
| SelectionProcess newProcess = new SelectionProcess | |||
| { | |||
| Name = model.Name, | |||
| SelectionLevelId = nextLevel.Id, | |||
| Status = "Čeka na zakazivanje", | |||
| ApplicantId = sp.ApplicantId, | |||
| //SchedulerId = model.SchedulerId | |||
| ApplicantId = sp.ApplicantId | |||
| }; | |||
| _context.SelectionProcesses.Add(newProcess); | |||
| _logger.LogInformation($"Create and add new selection process"); | |||
| @@ -78,23 +67,6 @@ namespace Diligent.WebAPI.Business.Services | |||
| return result; | |||
| } | |||
| public async Task<List<SelectionLevelInfoDto>> GetCountByLevels(List<string> statuses) | |||
| { | |||
| _logger.LogInformation("Start getting all Selection levels"); | |||
| var res = await _context.SelectionLevels.Include(n => n.SelectionProcesses).ToListAsync(); | |||
| _logger.LogInformation($"Received {res.Count} selection levels"); | |||
| _logger.LogInformation("Mapping levels with process counts to SelectionLevelInfo"); | |||
| var resMapped = res.Select(n => new SelectionLevelInfoDto | |||
| { | |||
| Level = n.Name, | |||
| CountAll = n.SelectionProcesses.Count, | |||
| CountDone = n.SelectionProcesses.Where(n => statuses.Contains(n.Status)).Count() | |||
| }).ToList(); | |||
| return resMapped; | |||
| } | |||
| public async Task UpdateSelectionProcessStatusAsync(int id, SelectionProcessUpdateStatusDto selectionProcessUpdateStatusDto) | |||
| { | |||
| _logger.LogInformation($"Start searching Ad with id = {id}"); | |||
| @@ -14,11 +14,7 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| { | |||
| _selectionProcessesService = selectionProcessesService; | |||
| } | |||
| //[Authorize] | |||
| //[HttpGet] | |||
| //public async Task<IActionResult> GetAll() => | |||
| // Ok(await _selectionProcessesService.GetAllAsync()); | |||
| [Authorize] | |||
| [HttpPost] | |||
| public async Task<IActionResult> FinishSelectionProcess([FromBody] SelectionProcessCreateDto model) => | |||
| @@ -39,19 +35,5 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| await _selectionProcessesService.InterviewerUpdate(model); | |||
| return Ok("Interviewer changed."); | |||
| } | |||
| //[HttpPost] | |||
| //public async Task<IActionResult> Create([FromBody] SelectionProcessCreateDto request) | |||
| //{ | |||
| // await _selectionProcessesService.CreateAsync(request); | |||
| // return StatusCode((int)HttpStatusCode.Created); | |||
| //} | |||
| //[Authorize] | |||
| //[HttpPut("{id}")] | |||
| //public async Task<IActionResult> Update([FromBody] SelectionProcessCreateDto request, [FromRoute] int id) | |||
| //{ | |||
| // await _selectionProcessesService.UpdateAsync(id, request); | |||
| // return Ok(); | |||
| //} | |||
| } | |||
| } | |||
| @@ -5,12 +5,12 @@ | |||
| [ApiController] | |||
| public class StatsController : ControllerBase | |||
| { | |||
| private readonly ISelectionProcessService _selectionProcessService; | |||
| private readonly ISelectionLevelService _selectionLevelsService; | |||
| private readonly IAdService _adService; | |||
| public StatsController(ISelectionProcessService selectionProcessService, IAdService adService) | |||
| public StatsController(ISelectionLevelService selectionLevelsService, IAdService adService) | |||
| { | |||
| _selectionProcessService = selectionProcessService; | |||
| _selectionLevelsService = selectionLevelsService; | |||
| _adService = adService; | |||
| } | |||
| @@ -20,7 +20,7 @@ | |||
| { | |||
| return Ok(new | |||
| { | |||
| Levels = await _selectionProcessService.GetCountByLevels(new List<string> { "Odrađen" }), | |||
| Levels = await _selectionLevelsService.GetCountByLevels(new List<string> { "Odrađen" }), | |||
| Ads = await _adService.GetAllWithCountAsync() | |||
| }); | |||
| } | |||
| @@ -0,0 +1,30 @@ | |||
| using Diligent.WebAPI.Contracts.DTOs.Applicant; | |||
| using Microsoft.AspNetCore.Http; | |||
| namespace Diligent.WebAPI.Tests.Controllers | |||
| { | |||
| public class ImportControllerTests | |||
| { | |||
| private readonly IFormFile file = Substitute.For<IFormFile>(); | |||
| private readonly IImportService _service = Substitute.For<IImportService>(); | |||
| private readonly IApplicantService _applicantService = Substitute.For<IApplicantService>(); | |||
| private readonly List<ApplicantImportDto> _applicants; | |||
| public ImportControllerTests() | |||
| { | |||
| _applicants = new List<ApplicantImportDto> | |||
| { | |||
| new ApplicantImportDto{Email = "dzenis@dilig.net"} | |||
| }; | |||
| } | |||
| [Fact] | |||
| public async Task Import_ShoudReutnr_200OK() | |||
| { | |||
| _service.Import(Arg.Any<IFormFile>()).Returns(_applicants); | |||
| ImportController controller = new ImportController(_service, _applicantService); | |||
| var result = await controller.Import(file); | |||
| (result as OkResult).StatusCode.Should().Be(200); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,59 @@ | |||
| using Diligent.WebAPI.Contracts.Models; | |||
| using NSubstitute.ReturnsExtensions; | |||
| namespace Diligent.WebAPI.Tests.Controllers | |||
| { | |||
| public class ScreeningTestControllerTests | |||
| { | |||
| private IScreeningTestService _service = Substitute.For<IScreeningTestService>(); | |||
| private readonly List<TestMicroserviceRequest> tests; | |||
| public ScreeningTestControllerTests() | |||
| { | |||
| tests = new List<TestMicroserviceRequest> | |||
| { | |||
| new TestMicroserviceRequest{ Id = 1, Name = "Intership .NET"}, | |||
| new TestMicroserviceRequest{ Id = 2, Name = "Junior .NET"}, | |||
| new TestMicroserviceRequest{ Id = 3, Name = "Senior .NET"} | |||
| }; | |||
| } | |||
| [Fact] | |||
| public async Task Get_ShouldReturn_200OKAndListOfTests() | |||
| { | |||
| var baseResult = new Contracts.Models.BaseResult<IEnumerable<TestMicroserviceRequest>> | |||
| { | |||
| DataObject = tests | |||
| }; | |||
| _service.GetScreening().Returns(baseResult); | |||
| ScreeningTestController controller = new(_service); | |||
| var result = await controller.Get(); | |||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||
| } | |||
| [Fact] | |||
| public async Task Post_ShouldReturnBadRequest_WhenErrorIsPresent() | |||
| { | |||
| _service.When(x => x.SendTest(Arg.Any<TestMicroserviceInviteRequest>())).ReturnsNull(); | |||
| ScreeningTestController controller = new(_service); | |||
| var result = await controller.Post(new TestMicroserviceInviteRequest()); | |||
| (result as BadRequestResult).StatusCode.Should().Be(400); | |||
| } | |||
| [Fact] | |||
| public async Task Post_ShouldReturn_200OK() | |||
| { | |||
| _service.SendTest(Arg.Any<TestMicroserviceInviteRequest>()).Returns(true); | |||
| ScreeningTestController controller = new(_service); | |||
| var result = await controller.Post(new TestMicroserviceInviteRequest()); | |||
| (result as OkResult).StatusCode.Should().Be(200); | |||
| } | |||
| } | |||
| } | |||
| @@ -44,5 +44,63 @@ namespace Diligent.WebAPI.Tests.Controllers | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.FinishSelectionProcess(new SelectionProcessCreateDto())); | |||
| } | |||
| [Fact] | |||
| public async Task UpdateStatus_ShouldReturn_200OK() | |||
| { | |||
| _service.StatusUpdate(Arg.Any<StatusChangeDTO>()); | |||
| SelectionProcessesController controller = new(_service); | |||
| var result = await controller.UpdateStatus(new StatusChangeDTO()); | |||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||
| } | |||
| [Fact] | |||
| public async Task UpdateStatus_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist() | |||
| { | |||
| _service.When(x => x.StatusUpdate(Arg.Any<StatusChangeDTO>())).Do(x => { throw new EntityNotFoundException(); }); | |||
| SelectionProcessesController controller = new(_service); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.UpdateStatus(new StatusChangeDTO())); | |||
| } | |||
| [Fact] | |||
| public async Task UpdateStatus_ShouldThrowEntityNotFooundException_WhenUserDoesNotExist() | |||
| { | |||
| _service.When(x => x.StatusUpdate(Arg.Any<StatusChangeDTO>())).Do(x => { throw new EntityNotFoundException(); }); | |||
| SelectionProcessesController controller = new(_service); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.UpdateStatus(new StatusChangeDTO())); | |||
| } | |||
| [Fact] | |||
| public async Task UpdateInterviewer_ShouldReturn_200OK() | |||
| { | |||
| _service.InterviewerUpdate(Arg.Any<InterviewerUpdateDTO>()); | |||
| SelectionProcessesController controller = new(_service); | |||
| var result = await controller.UpdateInterviewer(new InterviewerUpdateDTO()); | |||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||
| } | |||
| [Fact] | |||
| public async Task UpdateInterviewer_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist() | |||
| { | |||
| _service.When(x => x.InterviewerUpdate(Arg.Any<InterviewerUpdateDTO>())).Do(x => { throw new EntityNotFoundException(); }); | |||
| SelectionProcessesController controller = new(_service); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.UpdateInterviewer(new InterviewerUpdateDTO())); | |||
| } | |||
| [Fact] | |||
| public async Task UpdateInterviewer_ShouldThrowEntityNotFooundException_WhenUserDoesNotExist() | |||
| { | |||
| _service.When(x => x.InterviewerUpdate(Arg.Any<InterviewerUpdateDTO>())).Do(x => { throw new EntityNotFoundException(); }); | |||
| SelectionProcessesController controller = new(_service); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.UpdateInterviewer(new InterviewerUpdateDTO())); | |||
| } | |||
| } | |||
| } | |||
| @@ -111,5 +111,28 @@ namespace Diligent.WebAPI.Tests.Services | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.GetByIdEntity(1000)); | |||
| } | |||
| [Fact] | |||
| public async Task GetCountByLevels_ShouldReturnListOfLevels_Always() | |||
| { | |||
| var databaseContext = await Helpers<SelectionLevel>.GetDatabaseContext(_levels); | |||
| databaseContext.SelectionLevels.First().SelectionProcesses = new List<SelectionProcess> | |||
| { | |||
| new SelectionProcess{ Id = 1, Status = "Obrađen", Date = DateTime.Now}, | |||
| new SelectionProcess{ Id = 2, Status = "Zakazan", Date = DateTime.Now.AddMonths(-1)}, | |||
| new SelectionProcess{ Id = 3, Status = "Čeka na zakazivanje", Date = DateTime.Now}, | |||
| new SelectionProcess{ Id = 4, Status = "Čeka na zakazivanje", Date = DateTime.Now.AddMonths(-1)}, | |||
| }; | |||
| SelectionLevelService service = new(databaseContext, _mapper, _logger); | |||
| var statues = new List<string> { "Obrađen", "Zakazan" }; | |||
| var result = await service.GetCountByLevels(statues); | |||
| result.Should().HaveCount(4); | |||
| result.First().CountAll.Should().Be(4); | |||
| result.First().CountDone.Should().Be(2); | |||
| } | |||
| } | |||
| } | |||
| @@ -5,7 +5,10 @@ using Diligent.WebAPI.Contracts.DTOs.SelectionLevel; | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | |||
| using Diligent.WebAPI.Contracts.Exceptions; | |||
| using Diligent.WebAPI.Data.Entities; | |||
| using Microsoft.AspNetCore.Identity; | |||
| using Microsoft.Extensions.Logging; | |||
| using NSubstitute.ReturnsExtensions; | |||
| using System.Diagnostics; | |||
| namespace Diligent.WebAPI.Tests.Services | |||
| { | |||
| @@ -14,10 +17,19 @@ namespace Diligent.WebAPI.Tests.Services | |||
| private readonly IMapper _mapper; | |||
| private readonly List<SelectionProcess> _processes; | |||
| private readonly SelectionProcess _selectionProcess; | |||
| private readonly StatusChangeDTO _statusChangeDTO; | |||
| private readonly InterviewerUpdateDTO _interviewerUpdateDTO; | |||
| private readonly User _user; | |||
| private readonly User _userId2; | |||
| private readonly SelectionProcessUpdateStatusDto _selectionProcessUpdateStatusDto; | |||
| private ILogger<SelectionProcessService> _logger = Substitute.For<ILogger<SelectionProcessService>>(); | |||
| private readonly SelectionProcessCreateDto _selectionProcessCreateDto; | |||
| private readonly IUserStore<User> _mockStore = Substitute.For<IUserStore<User>>(); | |||
| private readonly UserManager<User> _userManager; | |||
| public SelectionProcessServiceTests() | |||
| { | |||
| _userManager = Substitute.For<UserManager<User>>(_mockStore, null, null, null, null, null, null, null, null); | |||
| _selectionProcessCreateDto = new SelectionProcessCreateDto | |||
| { | |||
| Id = 1, | |||
| @@ -29,6 +41,10 @@ namespace Diligent.WebAPI.Tests.Services | |||
| SelectionLevelId = 4, | |||
| Status = "Obrađen" | |||
| }; | |||
| _selectionProcessUpdateStatusDto = new SelectionProcessUpdateStatusDto | |||
| { | |||
| Status = "Ceka na zakazivanje" | |||
| }; | |||
| _selectionProcess = new SelectionProcess | |||
| { | |||
| Id = 1, | |||
| @@ -40,7 +56,52 @@ namespace Diligent.WebAPI.Tests.Services | |||
| SelectionLevelId = 4, | |||
| Status = "Obrađen" | |||
| }; | |||
| _statusChangeDTO = new StatusChangeDTO | |||
| { | |||
| ProcessId = 1, | |||
| Appointment = DateTime.Today, | |||
| NewStatus = "Zakazan", | |||
| SchedulerId = 1 | |||
| }; | |||
| _user = new User | |||
| { | |||
| Id = 1, | |||
| PasswordHash = "AQAAAAEAACcQAAAAEJnWVhD/qftzqJq5XOUD0BxEBEwhd7vS46HeDD+9cwEsqO9ev9xEORJVjmFMASUGJg==", | |||
| FirstName = "Dzenis", | |||
| LastName = "Dzenis", | |||
| UserName = "dzenis", | |||
| NormalizedUserName = "DZENIS", | |||
| Email = "dzenis@dilig.net", | |||
| NormalizedEmail = "DZENIS@DILIG.NET", | |||
| EmailConfirmed = false, | |||
| IsEnabled = true, | |||
| AccessFailedCount = 0, | |||
| SecurityStamp = "2D3XPK2P5MAKO377AWFU3T4ZFFYTSOJX", | |||
| ConcurrencyStamp = "2D3XPK2P5MAKO377AWFU3T4ZFFYTSOJX", | |||
| }; | |||
| _userId2 = new User | |||
| { | |||
| Id = 2, | |||
| PasswordHash = "AQAAAAEAACcQAAAAEJnWVhD/qftzqJq5XOUD0BxEBEwhd7vS46HeDD+9cwEsqO9ev9xEORJVjmFMASUGJg==", | |||
| FirstName = "Meris", | |||
| LastName = "Ahmatovic", | |||
| UserName = "merisa", | |||
| NormalizedUserName = "MERIS", | |||
| Email = "meris@dilig.net", | |||
| NormalizedEmail = "MERIS@DILIG.NET", | |||
| EmailConfirmed = false, | |||
| IsEnabled = true, | |||
| AccessFailedCount = 0, | |||
| SecurityStamp = "2D3XPK2P5MAKO377AWFU3T4ZFFYTSOJX", | |||
| ConcurrencyStamp = "2D3XPK2P5MAKO377AWFU3T4ZFFYTSOJX", | |||
| }; | |||
| _interviewerUpdateDTO = new InterviewerUpdateDTO | |||
| { | |||
| ProcessId = 1, | |||
| SchedulerId = 2 | |||
| }; | |||
| _processes = new List<SelectionProcess> | |||
| { | |||
| _selectionProcess | |||
| @@ -59,33 +120,13 @@ namespace Diligent.WebAPI.Tests.Services | |||
| public async Task GetAll_ShouldReturnListOfProcesses_Always() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(databaseContext, _mapper, _logger); | |||
| SelectionProcessService service = new(_userManager, databaseContext, _mapper, _logger); | |||
| 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, _logger); | |||
| // 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, _logger); | |||
| // await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.GetByIdAsync(1000)); | |||
| //} | |||
| [Fact] | |||
| public async Task FinishSelectionProcess_ShouldReturnTrueAndAddNewSelectionProcess_WhenProcessExists() | |||
| { | |||
| @@ -107,7 +148,7 @@ namespace Diligent.WebAPI.Tests.Services | |||
| }; | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(processes); | |||
| SelectionProcessService service = new(databaseContext, _mapper, _logger); | |||
| SelectionProcessService service = new(_userManager, databaseContext, _mapper, _logger); | |||
| var result = await service.FinishSelectionProcess(_selectionProcessCreateDto); | |||
| var newProcesses = await service.GetAllAsync(); | |||
| @@ -119,7 +160,7 @@ namespace Diligent.WebAPI.Tests.Services | |||
| public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(databaseContext, _mapper, _logger); | |||
| SelectionProcessService service = new(_userManager, databaseContext, _mapper, _logger); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.FinishSelectionProcess(new SelectionProcessCreateDto { Id = 1000 })); | |||
| } | |||
| @@ -128,9 +169,94 @@ namespace Diligent.WebAPI.Tests.Services | |||
| public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessIsInLastLevel() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(databaseContext, _mapper, _logger); | |||
| SelectionProcessService service = new(_userManager, databaseContext, _mapper, _logger); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.FinishSelectionProcess(new SelectionProcessCreateDto { Id = 1, SelectionLevelId = 4 })); | |||
| } | |||
| [Fact] | |||
| public async Task UpdateSelectionProcessStatusAsync_ShouldUpdateStatusOfProcess_WhenProcessExists() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(_userManager, databaseContext, _mapper, _logger); | |||
| await service.UpdateSelectionProcessStatusAsync(1, _selectionProcessUpdateStatusDto); | |||
| _selectionProcess.Status.Should().Be("Ceka na zakazivanje"); | |||
| } | |||
| [Fact] | |||
| public async Task UpdateSelectionProcessStatusAsync_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(_userManager,databaseContext, _mapper, _logger); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.UpdateSelectionProcessStatusAsync(1000,_selectionProcessUpdateStatusDto)); | |||
| } | |||
| [Fact] | |||
| public async Task StatusUpdate_ShouldUpdateStatusOfProcess_WhenProcessExists() | |||
| { | |||
| _userManager.FindByIdAsync(Arg.Any<string>()).Returns(_user); | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(_userManager, databaseContext, _mapper, _logger); | |||
| await service.StatusUpdate(_statusChangeDTO); | |||
| _selectionProcess.Status.Should().Be("Zakazan"); | |||
| _selectionProcess.Date.Should().Be(DateTime.Today); | |||
| _selectionProcess.SchedulerId.Should().Be(1); | |||
| } | |||
| [Fact] | |||
| public async Task StatusUpdate_ShouldThrowEntityNotFooundException_WhenUserDoesNotExist() | |||
| { | |||
| _userManager.FindByIdAsync(Arg.Any<string>()).ReturnsNull(); | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(_userManager, databaseContext, _mapper, _logger); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.StatusUpdate(_statusChangeDTO)); | |||
| } | |||
| [Fact] | |||
| public async Task StatusUpdate_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(_userManager,databaseContext, _mapper, _logger); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.StatusUpdate(new StatusChangeDTO { ProcessId = 1000 })); | |||
| } | |||
| [Fact] | |||
| public async Task InterviewerUpdate_ShouldUpdateStatusOfProcess_WhenProcessExists() | |||
| { | |||
| _userManager.FindByIdAsync(Arg.Any<string>()).Returns(_userId2); | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(_userManager, databaseContext, _mapper, _logger); | |||
| await service.InterviewerUpdate(_interviewerUpdateDTO); | |||
| _selectionProcess.SchedulerId.Should().Be(2); | |||
| } | |||
| [Fact] | |||
| public async Task InterviewerUpdate_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist() | |||
| { | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(_userManager,databaseContext, _mapper, _logger); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.InterviewerUpdate(new InterviewerUpdateDTO { ProcessId = 1000, SchedulerId = 2 })); | |||
| } | |||
| [Fact] | |||
| public async Task InterviewerUpdate_ShouldThrowEntityNotFooundException_WhenUserDoesnotExist() | |||
| { | |||
| _userManager.FindByIdAsync(Arg.Any<string>()).ReturnsNull(); | |||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | |||
| SelectionProcessService service = new(_userManager,databaseContext, _mapper, _logger); | |||
| await Assert.ThrowsAsync<InvalidOperationException>(async () => await service.FinishSelectionProcess(new SelectionProcessCreateDto { Id = 1, SelectionLevelId = 4 })); | |||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.InterviewerUpdate(_interviewerUpdateDTO)); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1 @@ | |||
| {} | |||