| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- 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 IFileService _fileService = Substitute.For<IFileService>();
- private readonly ApplicantViewDto _applicant;
- private readonly List<Contracts.DTOs.Ad.AdApplicantsViewDto> _adApplicants;
- 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 = ""}
- }
- };
-
- _adApplicants = new List<Contracts.DTOs.Ad.AdApplicantsViewDto>
- {
- new Contracts.DTOs.Ad.AdApplicantsViewDto
- {
- Applicants = new List<AdApplicantViewDto>{ new AdApplicantViewDto {
- ApplicantId = 1,
- CV = "link",
- DateOfApplication = DateTime.Now,
- Experience = 3,
- FirstName = "Dzenis",
- LastName = "Hadzifdejzovic",
- TechnologyApplicants = new List<Contracts.DTOs.Technology.TechnologyViewDto>()}
- },
- Id = 1,
- Title = "some title"
- }
- };
- }
-
- [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, _fileService);
-
- var result = await applicantsController.GetFilteredApplicants(filterDto);
-
- (result as OkObjectResult).StatusCode.Should().Be(200);
- }
-
- [Fact]
- public async Task GetById_ShouldThrowEntityNotFoundException_WhenApplicantDoesNotExist()
- {
- _applicantService.When(x => x.GetById(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
- ApplicantsController applicantsController = new(_applicantService, _fileService);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.GetById(1000));
- }
-
- [Fact]
- public async Task GetById_ShouldReturn_200OK_WhenApplicantExist()
- {
- _applicantService.GetById(Arg.Any<int>()).Returns(_applicant);
- ApplicantsController applicantsController = new(_applicantService, _fileService);
-
- var result = await applicantsController.GetById(1);
-
- (result as OkObjectResult).StatusCode.Should().Be(200);
- }
-
- [Fact]
- public async Task GetAllAdsApplicants_ShouldReturn_200OK_Always()
- {
- _applicantService.GetAllAdsApplicants(Arg.Any<ApplicantFilterDto>()).Returns(_adApplicants);
- ApplicantsController applicantsController = new(_applicantService, _fileService);
-
- var result = await applicantsController.GetAllAdsApplicants(new ApplicantFilterDto { });
-
- (result as OkObjectResult).StatusCode.Should().Be(200);
- }
-
-
- [Fact]
- public async Task DeleteApplicant_ShouldThrowEntityNotFoundException_WhenApplicantDoesNotExist()
- {
- _applicantService.When(x => x.DeleteApplicant(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
- ApplicantsController applicantsController = new(_applicantService, _fileService);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.DeleteApplicant(1000));
- }
-
-
- [Fact]
- public async Task DeleteApplicant_ShouldReturn_200OK_WhenApplicantExist()
- {
- _applicantService.When(x => x.DeleteApplicant(Arg.Any<int>())).Do(x => { });
- ApplicantsController applicantsController = new(_applicantService, _fileService);
-
- var result = await applicantsController.DeleteApplicant(1000);
-
- (result as StatusCodeResult).StatusCode.Should().Be(200);
- }
-
-
- [Fact]
- public async Task GetProcesses_ShouldReturn_200OK_WhenApplicantExists()
- {
- _applicantService.GetApplicantWithSelectionProcessesById(Arg.Any<int>()).Returns(_applicant);
- ApplicantsController applicantsController = new(_applicantService,_fileService);
-
- var result = await applicantsController.GetProcesses(1);
-
- (result as OkObjectResult).StatusCode.Should().Be(200);
- }
-
- [Fact]
- public async Task GetProcesses_ShouldThrowEntityNotFoundException_WhenApplicantDoesnotExist()
- {
- _applicantService.When(x => x.GetApplicantWithSelectionProcessesById(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
- ApplicantsController applicantsController = new(_applicantService, _fileService);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.GetProcesses(1000));
- }
-
- [Fact]
- public async Task GetOptions_ShouldReturn_200OK_Always()
- {
- _applicantService.GetOptions().Returns(new List<ApplicantOptionsDTO>());
- ApplicantsController applicantsController = new(_applicantService, _fileService);
-
- var result = await applicantsController.GetOptions();
-
- (result as OkObjectResult).StatusCode.Should().Be(200);
- }
-
- [Fact]
- public async Task InitSelecetion_ShouldReturnError_WhenApplicantDoesNotExist()
- {
- _applicantService.InitializeProcess(Arg.Any<ApplicantProcessRequestDTO>()).Returns(new ServiceResponseDTO<object>());
- ApplicantsController applicantsController = new(_applicantService, _fileService);
-
- var result = await applicantsController.InitSelection(Arg.Any<ApplicantProcessRequestDTO>());
-
- (result as OkObjectResult).StatusCode.Should().Be(200);
- }
-
- [Fact]
- public async Task ApplyForAd_ShouldThrowEntityNotFoundException_WhenAdDoesNotExist()
- {
- _applicantService.When(x => x.ApplyForAd(Arg.Any<ApplyForAdRequestDto>())).Do(x => { throw new EntityNotFoundException(); });
- ApplicantsController applicantsController = new(_applicantService, _fileService);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.ApplyForAd(new ApplyForAdRequestDto()));
- }
-
- [Fact]
- public async Task ApplyForAd_ShouldReturn_200OK_WhenAdExist()
- {
- _applicantService.When(x => x.ApplyForAd(Arg.Any<ApplyForAdRequestDto>())).Do(x => { });
- ApplicantsController applicantsController = new(_applicantService, _fileService);
-
- var result = await applicantsController.ApplyForAd(new ApplyForAdRequestDto());
-
- (result as StatusCodeResult).StatusCode.Should().Be(200);
- }
-
- [Fact]
- public async Task GetApplicantCV_ShouldReturn_200OK_Always()
- {
- _fileService.GetCV(Arg.Any<string>()).Returns("some string");
- ApplicantsController applicantsController = new(_applicantService, _fileService);
-
- var result = await applicantsController.GetApplicantCV("some string");
-
- (result as OkObjectResult).StatusCode.Should().Be(200);
- }
- }
- }
|