Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using AutoMapper;
  2. using Diligent.WebAPI.Business.MappingProfiles;
  3. using Diligent.WebAPI.Business.Services;
  4. using Diligent.WebAPI.Contracts.DTOs.Ad;
  5. using Diligent.WebAPI.Contracts.DTOs.Applicant;
  6. using Diligent.WebAPI.Contracts.Exceptions;
  7. using Diligent.WebAPI.Data.Entities;
  8. using Microsoft.Extensions.Logging;
  9. namespace Diligent.WebAPI.Tests.Services
  10. {
  11. public class ApplicantServiceTests
  12. {
  13. private readonly IMapper _mapper;
  14. private ILogger<ApplicantService> _logger = Substitute.For<ILogger<ApplicantService>>();
  15. private readonly List<Applicant> _applicants;
  16. private readonly List<Ad> _ads;
  17. public ApplicantServiceTests()
  18. {
  19. _applicants = MockData.GetListOfApplicants();
  20. _ads = MockData.GetListOfAds();
  21. // configure mapper
  22. var configuration = new MapperConfiguration(cfg => cfg.AddProfiles(
  23. new List<Profile>
  24. {
  25. new ApplicantMappingProfile(),
  26. new AdMappingProfile(),
  27. new SelectionProcessMappingProfile()
  28. }));
  29. _mapper = new Mapper(configuration);
  30. }
  31. [Fact]
  32. public async Task GetFilteredApplicants_ShouldReturnListOfApplicants_Always()
  33. {
  34. var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
  35. ApplicantService applicantService = new(databaseContext, _mapper, _logger);
  36. var filterDto = new ApplicantFilterDto();
  37. var result = await applicantService.GetFilteredApplicants(filterDto);
  38. Assert.Equal(_applicants.Count,result.Total);
  39. }
  40. [Fact]
  41. public async Task GetById_ShouldReturnApplicant_WhenApplicantExist()
  42. {
  43. var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
  44. ApplicantService applicantService = new(databaseContext, _mapper, _logger);
  45. var result = await applicantService.GetById(1);
  46. result.Should().BeEquivalentTo(_mapper.Map<ApplicantViewDto>(_applicants[0]));
  47. }
  48. [Fact]
  49. public async Task GetById_ShouldThrowEntityNotFooundException_WhenApplicantDontExist()
  50. {
  51. var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
  52. ApplicantService applicantService = new(databaseContext, _mapper, _logger);
  53. await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.GetById(1000));
  54. }
  55. //[Fact]
  56. //public async Task CreateApplicant_ShouldAddEntityIntoDatabase_Always()
  57. //{
  58. // var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
  59. // ApplicantService applicantService = new(databaseContext, _mapper, _logger);
  60. // ApplicantCreateDto applicantCreateDto = new()
  61. // {
  62. // ApplicationChannel = "Facebook",
  63. // BitBucketLink = null,
  64. // CV = "link",
  65. // Email = "some@mail.com",
  66. // Experience = 1,
  67. // FirstName = "Meris",
  68. // LastName = "Ahmatovic",
  69. // GithubLink = null,
  70. // LinkedlnLink = null,
  71. // PhoneNumber = "432424",
  72. // Position = ".NET Developer",
  73. // TypeOfEmployment = TypesOfEmployment.Intership.ToString()
  74. // };
  75. // await applicantService.CreateApplicant(applicantCreateDto);
  76. // var filterDto = new ApplicantFilterDto
  77. // {
  78. // CurrentPage = 1,
  79. // PageSize = 4
  80. // };
  81. // var result = await applicantService.GetFilteredApplicants(filterDto);
  82. // Assert.Equal(2, result.Total);
  83. //}
  84. [Fact]
  85. public async Task DeleteApplicant_ShouldDeleteApplicant_WhenApplicantExist()
  86. {
  87. var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
  88. ApplicantService applicantService = new(databaseContext, _mapper, _logger);
  89. await applicantService.DeleteApplicant(1);
  90. var filterDto = MockData.GetApplicantFilters();
  91. var applicants = await applicantService.GetFilteredApplicants(filterDto);
  92. Assert.Empty(applicants.Items);
  93. }
  94. [Fact]
  95. public async Task DeleteApplicant_ShouldThrowEntityNotFooundException_WhenApplicantDontExist()
  96. {
  97. var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
  98. ApplicantService applicantService = new(databaseContext, _mapper, _logger);
  99. await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.DeleteApplicant(1000));
  100. }
  101. //[Fact]
  102. //public async Task UpdateApplicant_ShouldUpdateApplicant_WhenApplicantExist()
  103. //{
  104. // var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
  105. // ApplicantService applicantService = new(databaseContext, _mapper, _logger);
  106. // ApplicantUpdateDto applicantUpdateDto = new()
  107. // {
  108. // ApplicationChannel = "Instagram",
  109. // BitBucketLink = null,
  110. // CV = "link",
  111. // Email = "some@mail.com",
  112. // Experience = 1,
  113. // FirstName = "Dzenis",
  114. // LastName = "Hadzifejzovic",
  115. // GithubLink = null,
  116. // LinkedlnLink = null,
  117. // PhoneNumber = "432424",
  118. // Position = "React Developer"
  119. // };
  120. // await applicantService.UpdateApplicant(1, applicantUpdateDto);
  121. // var applicant = await applicantService.GetById(1);
  122. // Assert.Equal(applicant.Position, applicantUpdateDto.Position);
  123. //}
  124. [Fact]
  125. public async Task GetAllAdsApplicants_ShouldReturnListOfAdApplicants_Always()
  126. {
  127. var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads);
  128. ApplicantService applicantService = new(databaseContext, _mapper, _logger);
  129. var filterDto = MockData.GetApplicantFilters();
  130. var result = await applicantService.GetAllAdsApplicants(filterDto);
  131. result.Should().BeEquivalentTo(_mapper.Map<List<AdApplicantsViewDto>>(_ads));
  132. }
  133. [Fact]
  134. public async Task GetApplicantWithSelectionProcessesById_ShouldReturnApplicant_WhenApplicantExists()
  135. {
  136. var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
  137. ApplicantService applicantService = new(databaseContext, _mapper, _logger);
  138. var result = await applicantService.GetApplicantWithSelectionProcessesById(1);
  139. var processes = result.SelectionProcesses;
  140. processes.Should().HaveCount(3);
  141. result.Should().BeEquivalentTo(_mapper.Map<ApplicantViewDto>(_applicants[0]));
  142. }
  143. }
  144. }