| /Diligent.WebAPI.Contracts/obj | /Diligent.WebAPI.Contracts/obj | ||||
| /Diligent.WebAPI.Tests/bin/Debug/net6.0 | /Diligent.WebAPI.Tests/bin/Debug/net6.0 | ||||
| /Diligent.WebAPI.Tests/obj/Debug/net6.0 | /Diligent.WebAPI.Tests/obj/Debug/net6.0 | ||||
| /Diligent.WebAPI.Tests/obj | |||||
| /Diligent.WebAPI.Tests/obj | |||||
| /Diligent.WebAPI.Tests/coverageresults |
| | | ||||
| using Diligent.WebAPI.Contracts.DTOs.SelectionLevel; | using Diligent.WebAPI.Contracts.DTOs.SelectionLevel; | ||||
| using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | ||||
| using Diligent.WebAPI.Contracts.DTOs.Stats; | |||||
| namespace Diligent.WebAPI.Business.Services.Interfaces | namespace Diligent.WebAPI.Business.Services.Interfaces | ||||
| { | { | ||||
| Task<SelectionLevelResposneDto> GetByIdAsync(int id); | Task<SelectionLevelResposneDto> GetByIdAsync(int id); | ||||
| Task<SelectionLevel> GetByIdEntity(int id); | Task<SelectionLevel> GetByIdEntity(int id); | ||||
| List<SelectionLevelResponseWithDataDto> GetFilteredLevelsAsync(SelectionProcessFilterDto filters); | List<SelectionLevelResponseWithDataDto> GetFilteredLevelsAsync(SelectionProcessFilterDto filters); | ||||
| Task<List<SelectionLevelInfoDto>> GetCountByLevels(List<string> statuses); | |||||
| } | } | ||||
| } | } |
| { | { | ||||
| Task<List<SelectionProcessResposneDto>> GetAllAsync(); | Task<List<SelectionProcessResposneDto>> GetAllAsync(); | ||||
| Task<bool> FinishSelectionProcess(SelectionProcessCreateDto model); | Task<bool> FinishSelectionProcess(SelectionProcessCreateDto model); | ||||
| Task<List<SelectionLevelInfoDto>> GetCountByLevels(List<string> statuses); | |||||
| Task UpdateSelectionProcessStatusAsync(int id, SelectionProcessUpdateStatusDto selectionProcessUpdateStatusDto); | Task UpdateSelectionProcessStatusAsync(int id, SelectionProcessUpdateStatusDto selectionProcessUpdateStatusDto); | ||||
| Task StatusUpdate(StatusChangeDTO model); | Task StatusUpdate(StatusChangeDTO model); | ||||
| Task InterviewerUpdate(InterviewerUpdateDTO model); | Task InterviewerUpdate(InterviewerUpdateDTO model); |
| namespace Diligent.WebAPI.Business.Services | |||||
| using Diligent.WebAPI.Contracts.DTOs.Stats; | |||||
| namespace Diligent.WebAPI.Business.Services | |||||
| { | { | ||||
| public class SelectionLevelService : ISelectionLevelService | public class SelectionLevelService : ISelectionLevelService | ||||
| { | { | ||||
| return result; | 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; | |||||
| } | |||||
| } | } | ||||
| } | } |
| _userManager = userManager; | _userManager = userManager; | ||||
| } | } | ||||
| public SelectionProcessService(DatabaseContext context, IMapper mapper, ILogger<SelectionProcessService> logger) | |||||
| { | |||||
| _context = context; | |||||
| _mapper = mapper; | |||||
| _logger = logger; | |||||
| } | |||||
| public async Task<List<SelectionProcessResposneDto>> GetAllAsync() | public async Task<List<SelectionProcessResposneDto>> GetAllAsync() | ||||
| { | { | ||||
| _logger.LogInformation("Start getting all Selection Processes"); | _logger.LogInformation("Start getting all Selection Processes"); | ||||
| sp.Status = "Odrađen"; | sp.Status = "Odrađen"; | ||||
| _logger.LogInformation($"Skipping throught levels to come to next level"); | _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"); | _logger.LogError($"Applicant is in the last selection level"); | ||||
| throw new EntityNotFoundException("Candidate came to 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 | SelectionProcess newProcess = new SelectionProcess | ||||
| { | { | ||||
| Name = model.Name, | Name = model.Name, | ||||
| SelectionLevelId = nextLevel.Id, | SelectionLevelId = nextLevel.Id, | ||||
| Status = "Čeka na zakazivanje", | Status = "Čeka na zakazivanje", | ||||
| ApplicantId = sp.ApplicantId, | |||||
| //SchedulerId = model.SchedulerId | |||||
| ApplicantId = sp.ApplicantId | |||||
| }; | }; | ||||
| _context.SelectionProcesses.Add(newProcess); | _context.SelectionProcesses.Add(newProcess); | ||||
| _logger.LogInformation($"Create and add new selection process"); | _logger.LogInformation($"Create and add new selection process"); | ||||
| return result; | 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) | public async Task UpdateSelectionProcessStatusAsync(int id, SelectionProcessUpdateStatusDto selectionProcessUpdateStatusDto) | ||||
| { | { | ||||
| _logger.LogInformation($"Start searching Ad with id = {id}"); | _logger.LogInformation($"Start searching Ad with id = {id}"); |
| { | { | ||||
| _selectionProcessesService = selectionProcessesService; | _selectionProcessesService = selectionProcessesService; | ||||
| } | } | ||||
| //[Authorize] | |||||
| //[HttpGet] | |||||
| //public async Task<IActionResult> GetAll() => | |||||
| // Ok(await _selectionProcessesService.GetAllAsync()); | |||||
| [Authorize] | [Authorize] | ||||
| [HttpPost] | [HttpPost] | ||||
| public async Task<IActionResult> FinishSelectionProcess([FromBody] SelectionProcessCreateDto model) => | public async Task<IActionResult> FinishSelectionProcess([FromBody] SelectionProcessCreateDto model) => | ||||
| await _selectionProcessesService.InterviewerUpdate(model); | await _selectionProcessesService.InterviewerUpdate(model); | ||||
| return Ok("Interviewer changed."); | 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(); | |||||
| //} | |||||
| } | } | ||||
| } | } |
| [ApiController] | [ApiController] | ||||
| public class StatsController : ControllerBase | public class StatsController : ControllerBase | ||||
| { | { | ||||
| private readonly ISelectionProcessService _selectionProcessService; | |||||
| private readonly ISelectionLevelService _selectionLevelsService; | |||||
| private readonly IAdService _adService; | private readonly IAdService _adService; | ||||
| public StatsController(ISelectionProcessService selectionProcessService, IAdService adService) | |||||
| public StatsController(ISelectionLevelService selectionLevelsService, IAdService adService) | |||||
| { | { | ||||
| _selectionProcessService = selectionProcessService; | |||||
| _selectionLevelsService = selectionLevelsService; | |||||
| _adService = adService; | _adService = adService; | ||||
| } | } | ||||
| { | { | ||||
| return Ok(new | 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() | Ads = await _adService.GetAllWithCountAsync() | ||||
| }); | }); | ||||
| } | } |
| 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); | |||||
| } | |||||
| } | |||||
| } |
| 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); | |||||
| } | |||||
| } | |||||
| } |
| await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.FinishSelectionProcess(new SelectionProcessCreateDto())); | 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())); | |||||
| } | |||||
| } | } | ||||
| } | } |
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.GetByIdEntity(1000)); | 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); | |||||
| } | |||||
| } | } | ||||
| } | } |
| using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | ||||
| using Diligent.WebAPI.Contracts.Exceptions; | using Diligent.WebAPI.Contracts.Exceptions; | ||||
| using Diligent.WebAPI.Data.Entities; | using Diligent.WebAPI.Data.Entities; | ||||
| using Microsoft.AspNetCore.Identity; | |||||
| using Microsoft.Extensions.Logging; | using Microsoft.Extensions.Logging; | ||||
| using NSubstitute.ReturnsExtensions; | |||||
| using System.Diagnostics; | |||||
| namespace Diligent.WebAPI.Tests.Services | namespace Diligent.WebAPI.Tests.Services | ||||
| { | { | ||||
| private readonly IMapper _mapper; | private readonly IMapper _mapper; | ||||
| private readonly List<SelectionProcess> _processes; | private readonly List<SelectionProcess> _processes; | ||||
| private readonly SelectionProcess _selectionProcess; | 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 ILogger<SelectionProcessService> _logger = Substitute.For<ILogger<SelectionProcessService>>(); | ||||
| private readonly SelectionProcessCreateDto _selectionProcessCreateDto; | private readonly SelectionProcessCreateDto _selectionProcessCreateDto; | ||||
| private readonly IUserStore<User> _mockStore = Substitute.For<IUserStore<User>>(); | |||||
| private readonly UserManager<User> _userManager; | |||||
| public SelectionProcessServiceTests() | public SelectionProcessServiceTests() | ||||
| { | { | ||||
| _userManager = Substitute.For<UserManager<User>>(_mockStore, null, null, null, null, null, null, null, null); | |||||
| _selectionProcessCreateDto = new SelectionProcessCreateDto | _selectionProcessCreateDto = new SelectionProcessCreateDto | ||||
| { | { | ||||
| Id = 1, | Id = 1, | ||||
| SelectionLevelId = 4, | SelectionLevelId = 4, | ||||
| Status = "Obrađen" | Status = "Obrađen" | ||||
| }; | }; | ||||
| _selectionProcessUpdateStatusDto = new SelectionProcessUpdateStatusDto | |||||
| { | |||||
| Status = "Ceka na zakazivanje" | |||||
| }; | |||||
| _selectionProcess = new SelectionProcess | _selectionProcess = new SelectionProcess | ||||
| { | { | ||||
| Id = 1, | Id = 1, | ||||
| SelectionLevelId = 4, | SelectionLevelId = 4, | ||||
| Status = "Obrađen" | 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> | _processes = new List<SelectionProcess> | ||||
| { | { | ||||
| _selectionProcess | _selectionProcess | ||||
| public async Task GetAll_ShouldReturnListOfProcesses_Always() | public async Task GetAll_ShouldReturnListOfProcesses_Always() | ||||
| { | { | ||||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | 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(); | var result = await service.GetAllAsync(); | ||||
| result.Should().HaveCount(1); | 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] | [Fact] | ||||
| public async Task FinishSelectionProcess_ShouldReturnTrueAndAddNewSelectionProcess_WhenProcessExists() | public async Task FinishSelectionProcess_ShouldReturnTrueAndAddNewSelectionProcess_WhenProcessExists() | ||||
| { | { | ||||
| }; | }; | ||||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(processes); | 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 result = await service.FinishSelectionProcess(_selectionProcessCreateDto); | ||||
| var newProcesses = await service.GetAllAsync(); | var newProcesses = await service.GetAllAsync(); | ||||
| public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist() | public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist() | ||||
| { | { | ||||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | 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 })); | await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.FinishSelectionProcess(new SelectionProcessCreateDto { Id = 1000 })); | ||||
| } | } | ||||
| public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessIsInLastLevel() | public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessIsInLastLevel() | ||||
| { | { | ||||
| var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes); | 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)); | |||||
| } | } | ||||
| } | } | ||||
| } | } |
| {} |