|
|
|
@@ -0,0 +1,154 @@ |
|
|
|
using AutoMapper; |
|
|
|
using Diligent.WebAPI.Business.MappingProfiles; |
|
|
|
using Diligent.WebAPI.Business.Services; |
|
|
|
using Diligent.WebAPI.Contracts.DTOs.Applicant; |
|
|
|
using Diligent.WebAPI.Contracts.Exceptions; |
|
|
|
using Diligent.WebAPI.Data.Entities; |
|
|
|
|
|
|
|
namespace Diligent.WebAPI.Tests.Services |
|
|
|
{ |
|
|
|
public class ApplicantServiceTests |
|
|
|
{ |
|
|
|
private readonly IMapper _mapper; |
|
|
|
private readonly List<Applicant> _applicants; |
|
|
|
private readonly Applicant _applicant; |
|
|
|
public ApplicantServiceTests() |
|
|
|
{ |
|
|
|
_applicant = new Applicant |
|
|
|
{ |
|
|
|
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" |
|
|
|
}; |
|
|
|
_applicants = new List<Applicant> |
|
|
|
{ |
|
|
|
_applicant |
|
|
|
}; |
|
|
|
|
|
|
|
// configure mapper |
|
|
|
var configuration = new MapperConfiguration(cfg => cfg.AddProfiles( |
|
|
|
new List<Profile> |
|
|
|
{ |
|
|
|
new ApplicantMappingProfile() |
|
|
|
})); |
|
|
|
_mapper = new Mapper(configuration); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task GetAll_ShouldReturnListOfApplicants_Always() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper); |
|
|
|
|
|
|
|
var result = await applicantService.GetAll(); |
|
|
|
|
|
|
|
result.Should().BeEquivalentTo(_mapper.Map<List<ApplicantViewDto>>(_applicants)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task GetById_ShouldReturnApplicant_WhenApplicantExist() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper); |
|
|
|
|
|
|
|
var result = await applicantService.GetById(1); |
|
|
|
|
|
|
|
result.Should().BeEquivalentTo(_mapper.Map<ApplicantViewDto>(_applicant)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task GetById_ShouldThrowEntityNotFooundException_WhenApplicantDontExist() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper); |
|
|
|
|
|
|
|
await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.GetById(1000)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task CreateApplicant_ShouldAddEntityIntoDatabase_Always() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper); |
|
|
|
|
|
|
|
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" |
|
|
|
}; |
|
|
|
|
|
|
|
await applicantService.CreateApplicant(applicantCreateDto); |
|
|
|
|
|
|
|
var applicants = await applicantService.GetAll(); |
|
|
|
|
|
|
|
Assert.Equal(2, applicants.Count); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task DeleteApplicant_ShouldDeleteApplicant_WhenApplicantExist() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper); |
|
|
|
|
|
|
|
await applicantService.DeleteApplicant(1); |
|
|
|
var applicants = await applicantService.GetAll(); |
|
|
|
|
|
|
|
Assert.Empty(applicants); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task DeleteApplicant_ShouldThrowEntityNotFooundException_WhenApplicantDontExist() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper); |
|
|
|
|
|
|
|
await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.DeleteApplicant(1000)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task UpdateApplicant_ShouldUpdateApplicant_WhenApplicantExist() |
|
|
|
{ |
|
|
|
var databaseContext = await Helpers.GetDatabaseContext(_applicants); |
|
|
|
ApplicantService applicantService = new(databaseContext, _mapper); |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |