| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using Diligent.WebAPI.Contracts.DTOs;
- using Diligent.WebAPI.Contracts.DTOs.Applicant;
- using Diligent.WebAPI.Contracts.DTOs.SelectionProcess;
- using Diligent.WebAPI.Contracts.Exceptions;
- using NSubstitute;
-
- namespace Diligent.WebAPI.Tests.Controllers
- {
- public class ApplicantsControllerTests
- {
- private readonly IApplicantService _applicantService = Substitute.For<IApplicantService>();
- private readonly ApplicantViewDto _applicant;
- public ApplicantsControllerTests()
- {
- _applicant = new ApplicantViewDto
- {
- ApplicantId = 1,
- ApplicationChannel = "Instagram",
- BitBucketLink = null,
- CV = "link",
- DateOfApplication = DateTime.Now,
- Email = "some@mail.com",
- Experience = 1,
- FirstName = "Dzenis",
- LastName = "Hadzifejzovic",
- GithubLink = null,
- LinkedlnLink = null,
- PhoneNumber = "432424",
- Position = ".NET Developer",
- SelectionProcesses = new List<SelectionProcessResposneWithoutApplicantDto>
- {
- new SelectionProcessResposneWithoutApplicantDto{ Status = ""},
- new SelectionProcessResposneWithoutApplicantDto{ Status = ""},
- new SelectionProcessResposneWithoutApplicantDto{ Status = ""}
- }
- };
- }
-
- [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 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 GetById_ShouldReturn_200OK_WhenApplicantExist()
- {
- _applicantService.GetById(Arg.Any<int>()).Returns(_applicant);
- ApplicantsController applicantsController = new(_applicantService);
-
- var result = await applicantsController.GetById(1);
-
- (result as OkObjectResult).StatusCode.Should().Be(200);
- }
-
- [Fact]
- public async Task GetById_ShouldThrowEntityNotFooundException_WhenApplicantDontExist()
- {
- _applicantService.When(x => x.GetById(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
- ApplicantsController applicantsController = new(_applicantService);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.GetById(1000));
- }
-
- [Fact]
- public async Task GetFilteredApplicants_ShouldReturn_200OK_Always()
- {
- var applicants = new List<ApplicantViewDto>
- {
- _applicant
- };
-
- var filterDto = new ApplicantFilterDto
- {
- CurrentPage = 1,
- PageSize = 4
- };
-
- _applicantService.GetFilteredApplicants(filterDto).Returns(new QueryResultDto<ApplicantViewDto>
- {
- Items = applicants,
- Total = applicants.Count
- });
-
- ApplicantsController applicantsController = new(_applicantService);
-
- var result = await applicantsController.GetFilteredApplicants(filterDto);
-
- (result as OkObjectResult).StatusCode.Should().Be(200);
- }
- }
- }
|