using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; using Diligent.WebAPI.Contracts.Exceptions; namespace Diligent.WebAPI.Tests.Controllers { public class SelectionProcessesControllerTests { private ISelectionProcessService _service = Substitute.For(); 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()).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())).Do(x => { throw new EntityNotFoundException(); }); SelectionProcessesController controller = new(_service); await Assert.ThrowsAsync(() => controller.FinishSelectionProcess(new SelectionProcessCreateDto())); } [Fact] public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessWasInLastLevel() { _service.When(x => x.FinishSelectionProcess(Arg.Any())).Do(x => { throw new EntityNotFoundException(); }); SelectionProcessesController controller = new(_service); await Assert.ThrowsAsync(() => controller.FinishSelectionProcess(new SelectionProcessCreateDto())); } [Fact] public async Task UpdateStatus_ShouldReturn_200OK() { _service.StatusUpdate(Arg.Any()); 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())).Do(x => { throw new EntityNotFoundException(); }); SelectionProcessesController controller = new(_service); await Assert.ThrowsAsync(() => controller.UpdateStatus(new StatusChangeDTO())); } [Fact] public async Task UpdateStatus_ShouldThrowEntityNotFooundException_WhenUserDoesNotExist() { _service.When(x => x.StatusUpdate(Arg.Any())).Do(x => { throw new EntityNotFoundException(); }); SelectionProcessesController controller = new(_service); await Assert.ThrowsAsync(() => controller.UpdateStatus(new StatusChangeDTO())); } [Fact] public async Task UpdateInterviewer_ShouldReturn_200OK() { _service.InterviewerUpdate(Arg.Any()); 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())).Do(x => { throw new EntityNotFoundException(); }); SelectionProcessesController controller = new(_service); await Assert.ThrowsAsync(() => controller.UpdateInterviewer(new InterviewerUpdateDTO())); } [Fact] public async Task UpdateInterviewer_ShouldThrowEntityNotFooundException_WhenUserDoesNotExist() { _service.When(x => x.InterviewerUpdate(Arg.Any())).Do(x => { throw new EntityNotFoundException(); }); SelectionProcessesController controller = new(_service); await Assert.ThrowsAsync(() => controller.UpdateInterviewer(new InterviewerUpdateDTO())); } } }