|
|
|
@@ -17,15 +17,18 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
private readonly IUserService _userService = Substitute.For<IUserService>(); |
|
|
|
private readonly IFileService _fileService = Substitute.For<IFileService>(); |
|
|
|
private readonly IAdService _adService = Substitute.For<IAdService>(); |
|
|
|
private readonly ITechnologyService _technologyService = Substitute.For<ITechnologyService>(); |
|
|
|
private readonly List<Applicant> _applicants; |
|
|
|
private readonly List<Ad> _ads; |
|
|
|
private readonly List<User> _users; |
|
|
|
private readonly List<Technology> _technologies; |
|
|
|
public ApplicantServiceTests() |
|
|
|
{ |
|
|
|
// mock data |
|
|
|
_applicants = MockData.GetListOfApplicants(); |
|
|
|
_ads = MockData.GetListOfAds(); |
|
|
|
_users = MockData.GetListOfUsers(); |
|
|
|
_technologies = MockData.GetListOfTechnologies(); |
|
|
|
|
|
|
|
// configure mapper |
|
|
|
var configuration = new MapperConfiguration(cfg => cfg.AddProfiles( |
|
|
|
@@ -33,7 +36,8 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
{ |
|
|
|
new ApplicantMappingProfile(), |
|
|
|
new AdMappingProfile(), |
|
|
|
new SelectionProcessMappingProfile() |
|
|
|
new SelectionProcessMappingProfile(), |
|
|
|
new TechnologyMappingProfile() |
|
|
|
})); |
|
|
|
_mapper = new Mapper(configuration); |
|
|
|
} |
|
|
|
@@ -43,7 +47,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
|
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
|
|
|
|
var filterDto = new ApplicantFilterDto |
|
|
|
{ |
|
|
|
@@ -61,7 +65,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
public async Task GetAllAdsApplicants_ShouldReturnAllApplicants_Always() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
|
|
|
|
var filterDto = MockData.GetApplicantFilters(); |
|
|
|
|
|
|
|
@@ -75,7 +79,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
{ |
|
|
|
var fileInBase64Format = "some string"; |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
_fileService.GetCV(Arg.Any<string>()).Returns(fileInBase64Format); |
|
|
|
|
|
|
|
var result = await applicantService.GetById(1); |
|
|
|
@@ -88,7 +92,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
public async Task GetById_ShouldThrowEntityNotFoundException_WhenApplicantDoesNotExist() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
|
|
|
|
await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.GetById(1000)); |
|
|
|
} |
|
|
|
@@ -97,7 +101,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
public async Task GetApplicantWithSelectionProcessesById_ShouldReturnApplicant_WhenApplicantExists() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
|
|
|
|
var result = await applicantService.GetApplicantWithSelectionProcessesById(1); |
|
|
|
var processes = result.SelectionProcesses; |
|
|
|
@@ -110,7 +114,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
public async Task GetApplicantWithSelectionProcessesById_ShouldThrowEntityNotFoundException_WhenApplicantDoesNotExist() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
|
|
|
|
await Assert.ThrowsAsync<EntityNotFoundException>(async () => await |
|
|
|
applicantService.GetApplicantWithSelectionProcessesById(1000)); |
|
|
|
@@ -120,7 +124,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
public async Task ApplyForAd_ShouldThrowEntityNotFooundException_WhenAdIsNotFound() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
ApplyForAdRequestDto applyForAdRequestDto = new() |
|
|
|
{ |
|
|
|
AdId = 1, |
|
|
|
@@ -147,7 +151,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
public async Task ApplyForAd_ApplicantShouldBeCreated_Always() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
ApplyForAdRequestDto applyForAdRequestDto = new() |
|
|
|
{ |
|
|
|
AdId = 1, |
|
|
|
@@ -165,6 +169,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
TechnologiesIds = new int[] { 1 }, |
|
|
|
}; |
|
|
|
_fileService.When(x => x.UploadCV(Arg.Any<string>(), Arg.Any<IFormFile>())).Do(x => { }); |
|
|
|
_technologyService.GetEntitiesAsync(Arg.Any<int[]>()).Returns(_technologies); |
|
|
|
_adService.GetByIdEntityAsync(Arg.Any<int>()).Returns(new Ad |
|
|
|
{ |
|
|
|
Id = 10, |
|
|
|
@@ -189,7 +194,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
public async Task DeleteApplicant_ShouldDeleteApplicant_WhenApplicantExist() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
|
|
|
|
await applicantService.DeleteApplicant(1); |
|
|
|
|
|
|
|
@@ -204,7 +209,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
public async Task DeleteApplicant_ShouldThrowEntityNotFooundException_WhenApplicantDoesNotExist() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
|
|
|
|
await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.DeleteApplicant(1000)); |
|
|
|
} |
|
|
|
@@ -213,7 +218,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
public async Task GetOptions_ShouldReturnAllOptions_Always() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
|
|
|
|
var res = await applicantService.GetOptions(); |
|
|
|
Assert.Equal(2, res.Count); |
|
|
|
@@ -223,7 +228,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
public async Task InitializeProcess_ShouldReturnError_WhenApplicantDoesNotExist() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
var res = await applicantService.InitializeProcess(new ApplicantProcessRequestDTO |
|
|
|
{ |
|
|
|
ApplicantId = 1000, |
|
|
|
@@ -238,7 +243,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
public async Task InitializeProcess_SelectionProcessShouldBeCreated_WhenApplicantExist() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
|
|
|
|
var res = await applicantService.InitializeProcess(new ApplicantProcessRequestDTO |
|
|
|
{ |
|
|
|
@@ -257,7 +262,7 @@ namespace Diligent.WebAPI.Tests.Services |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants); |
|
|
|
_userService.GetFirst().Returns(_users[0]); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService); |
|
|
|
|
|
|
|
var ad = new Ad |
|
|
|
{ |