| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- using AutoMapper;
- using Diligent.WebAPI.Business.MappingProfiles;
- using Diligent.WebAPI.Business.Services;
- using Diligent.WebAPI.Contracts.DTOs.Ad;
- using Diligent.WebAPI.Contracts.DTOs.Applicant;
- using Diligent.WebAPI.Contracts.Exceptions;
- using Diligent.WebAPI.Data.Entities;
- using Microsoft.Extensions.Logging;
-
- namespace Diligent.WebAPI.Tests.Services
- {
- public class ApplicantServiceTests
- {
- private readonly IMapper _mapper;
- private ILogger<ApplicantService> _logger = Substitute.For<ILogger<ApplicantService>>();
- private readonly List<Applicant> _applicants;
- private readonly List<Ad> _ads;
- public ApplicantServiceTests()
- {
- _applicants = MockData.GetListOfApplicants();
-
- _ads = MockData.GetListOfAds();
-
- // configure mapper
- var configuration = new MapperConfiguration(cfg => cfg.AddProfiles(
- new List<Profile>
- {
- new ApplicantMappingProfile(),
- new AdMappingProfile(),
- new SelectionProcessMappingProfile()
- }));
- _mapper = new Mapper(configuration);
- }
-
- [Fact]
- public async Task GetFilteredApplicants_ShouldReturnListOfApplicants_Always()
- {
- var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
-
- ApplicantService applicantService = new(databaseContext, _mapper, _logger);
-
- var filterDto = new ApplicantFilterDto();
-
- var result = await applicantService.GetFilteredApplicants(filterDto);
-
- Assert.Equal(_applicants.Count,result.Total);
- }
-
- [Fact]
- public async Task GetById_ShouldReturnApplicant_WhenApplicantExist()
- {
- var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
- ApplicantService applicantService = new(databaseContext, _mapper, _logger);
-
- var result = await applicantService.GetById(1);
-
- result.Should().BeEquivalentTo(_mapper.Map<ApplicantViewDto>(_applicants[0]));
- }
-
- [Fact]
- public async Task GetById_ShouldThrowEntityNotFooundException_WhenApplicantDontExist()
- {
- var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
- ApplicantService applicantService = new(databaseContext, _mapper, _logger);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.GetById(1000));
- }
-
- //[Fact]
- //public async Task CreateApplicant_ShouldAddEntityIntoDatabase_Always()
- //{
- // var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
- // ApplicantService applicantService = new(databaseContext, _mapper, _logger);
-
- // ApplicantCreateDto applicantCreateDto = new()
- // {
- // ApplicationChannel = "Facebook",
- // BitBucketLink = null,
- // CV = "link",
- // Email = "some@mail.com",
- // Experience = 1,
- // FirstName = "Meris",
- // LastName = "Ahmatovic",
- // GithubLink = null,
- // LinkedlnLink = null,
- // PhoneNumber = "432424",
- // Position = ".NET Developer",
- // TypeOfEmployment = TypesOfEmployment.Intership.ToString()
- // };
-
- // await applicantService.CreateApplicant(applicantCreateDto);
-
- // var filterDto = new ApplicantFilterDto
- // {
- // CurrentPage = 1,
- // PageSize = 4
- // };
-
- // var result = await applicantService.GetFilteredApplicants(filterDto);
-
- // Assert.Equal(2, result.Total);
- //}
-
- [Fact]
- public async Task DeleteApplicant_ShouldDeleteApplicant_WhenApplicantExist()
- {
- var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
- ApplicantService applicantService = new(databaseContext, _mapper, _logger);
-
- await applicantService.DeleteApplicant(1);
-
- var filterDto = MockData.GetApplicantFilters();
-
- var applicants = await applicantService.GetFilteredApplicants(filterDto);
-
- Assert.Empty(applicants.Items);
- }
-
- [Fact]
- public async Task DeleteApplicant_ShouldThrowEntityNotFooundException_WhenApplicantDontExist()
- {
- var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
- ApplicantService applicantService = new(databaseContext, _mapper, _logger);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.DeleteApplicant(1000));
- }
-
- //[Fact]
- //public async Task UpdateApplicant_ShouldUpdateApplicant_WhenApplicantExist()
- //{
- // var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
- // ApplicantService applicantService = new(databaseContext, _mapper, _logger);
-
- // ApplicantUpdateDto applicantUpdateDto = new()
- // {
- // ApplicationChannel = "Instagram",
- // BitBucketLink = null,
- // CV = "link",
- // Email = "some@mail.com",
- // Experience = 1,
- // FirstName = "Dzenis",
- // LastName = "Hadzifejzovic",
- // GithubLink = null,
- // LinkedlnLink = null,
- // PhoneNumber = "432424",
- // Position = "React Developer"
- // };
-
- // await applicantService.UpdateApplicant(1, applicantUpdateDto);
- // var applicant = await applicantService.GetById(1);
-
- // Assert.Equal(applicant.Position, applicantUpdateDto.Position);
- //}
-
- [Fact]
- public async Task GetAllAdsApplicants_ShouldReturnListOfAdApplicants_Always()
- {
- var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads);
- ApplicantService applicantService = new(databaseContext, _mapper, _logger);
-
- var filterDto = MockData.GetApplicantFilters();
-
- var result = await applicantService.GetAllAdsApplicants(filterDto);
-
- result.Should().BeEquivalentTo(_mapper.Map<List<AdApplicantsViewDto>>(_ads));
- }
-
- [Fact]
- public async Task GetApplicantWithSelectionProcessesById_ShouldReturnApplicant_WhenApplicantExists()
- {
- var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
- ApplicantService applicantService = new(databaseContext, _mapper, _logger);
-
- var result = await applicantService.GetApplicantWithSelectionProcessesById(1);
- var processes = result.SelectionProcesses;
-
- processes.Should().HaveCount(3);
- result.Should().BeEquivalentTo(_mapper.Map<ApplicantViewDto>(_applicants[0]));
- }
-
-
- }
- }
|