You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ApplicantsControllerTests.cs 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using Diligent.WebAPI.Contracts.DTOs;
  2. using Diligent.WebAPI.Contracts.DTOs.Applicant;
  3. using Diligent.WebAPI.Contracts.DTOs.SelectionProcess;
  4. using Diligent.WebAPI.Contracts.Exceptions;
  5. using NSubstitute;
  6. namespace Diligent.WebAPI.Tests.Controllers
  7. {
  8. public class ApplicantsControllerTests
  9. {
  10. private readonly IApplicantService _applicantService = Substitute.For<IApplicantService>();
  11. private readonly IFileService _fileService = Substitute.For<IFileService>();
  12. private readonly ApplicantViewDto _applicant;
  13. private readonly List<Contracts.DTOs.Ad.AdApplicantsViewDto> _adApplicants;
  14. public ApplicantsControllerTests()
  15. {
  16. _applicant = new ApplicantViewDto
  17. {
  18. ApplicantId = 1,
  19. ApplicationChannel = "Instagram",
  20. BitBucketLink = null,
  21. CV = "link",
  22. DateOfApplication = DateTime.Now,
  23. Email = "some@mail.com",
  24. Experience = 1,
  25. FirstName = "Dzenis",
  26. LastName = "Hadzifejzovic",
  27. GithubLink = null,
  28. LinkedlnLink = null,
  29. PhoneNumber = "432424",
  30. Position = ".NET Developer",
  31. SelectionProcesses = new List<SelectionProcessResposneWithoutApplicantDto>
  32. {
  33. new SelectionProcessResposneWithoutApplicantDto{ Status = ""},
  34. new SelectionProcessResposneWithoutApplicantDto{ Status = ""},
  35. new SelectionProcessResposneWithoutApplicantDto{ Status = ""}
  36. }
  37. };
  38. _adApplicants = new List<Contracts.DTOs.Ad.AdApplicantsViewDto>
  39. {
  40. new Contracts.DTOs.Ad.AdApplicantsViewDto
  41. {
  42. Applicants = new List<AdApplicantViewDto>{ new AdApplicantViewDto {
  43. ApplicantId = 1,
  44. CV = "link",
  45. DateOfApplication = DateTime.Now,
  46. Experience = 3,
  47. FirstName = "Dzenis",
  48. LastName = "Hadzifdejzovic",
  49. TechnologyApplicants = new List<Contracts.DTOs.Technology.TechnologyViewDto>()}
  50. },
  51. Id = 1,
  52. Title = "some title"
  53. }
  54. };
  55. }
  56. [Fact]
  57. public async Task GetFilteredApplicants_ShouldReturn_200OK_Always()
  58. {
  59. var applicants = new List<ApplicantViewDto>
  60. {
  61. _applicant
  62. };
  63. var filterDto = new ApplicantFilterDto
  64. {
  65. CurrentPage = 1,
  66. PageSize = 4
  67. };
  68. _applicantService.GetFilteredApplicants(filterDto).Returns(new QueryResultDto<ApplicantViewDto>
  69. {
  70. Items = applicants,
  71. Total = applicants.Count
  72. });
  73. ApplicantsController applicantsController = new(_applicantService, _fileService);
  74. var result = await applicantsController.GetFilteredApplicants(filterDto);
  75. (result as OkObjectResult).StatusCode.Should().Be(200);
  76. }
  77. [Fact]
  78. public async Task GetById_ShouldThrowEntityNotFoundException_WhenApplicantDoesNotExist()
  79. {
  80. _applicantService.When(x => x.GetById(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
  81. ApplicantsController applicantsController = new(_applicantService, _fileService);
  82. await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.GetById(1000));
  83. }
  84. [Fact]
  85. public async Task GetById_ShouldReturn_200OK_WhenApplicantExist()
  86. {
  87. _applicantService.GetById(Arg.Any<int>()).Returns(_applicant);
  88. ApplicantsController applicantsController = new(_applicantService, _fileService);
  89. var result = await applicantsController.GetById(1);
  90. (result as OkObjectResult).StatusCode.Should().Be(200);
  91. }
  92. [Fact]
  93. public async Task GetAllAdsApplicants_ShouldReturn_200OK_Always()
  94. {
  95. _applicantService.GetAllAdsApplicants(Arg.Any<ApplicantFilterDto>()).Returns(_adApplicants);
  96. ApplicantsController applicantsController = new(_applicantService, _fileService);
  97. var result = await applicantsController.GetAllAdsApplicants(new ApplicantFilterDto { });
  98. (result as OkObjectResult).StatusCode.Should().Be(200);
  99. }
  100. [Fact]
  101. public async Task DeleteApplicant_ShouldThrowEntityNotFoundException_WhenApplicantDoesNotExist()
  102. {
  103. _applicantService.When(x => x.DeleteApplicant(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
  104. ApplicantsController applicantsController = new(_applicantService, _fileService);
  105. await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.DeleteApplicant(1000));
  106. }
  107. [Fact]
  108. public async Task DeleteApplicant_ShouldReturn_200OK_WhenApplicantExist()
  109. {
  110. _applicantService.When(x => x.DeleteApplicant(Arg.Any<int>())).Do(x => { });
  111. ApplicantsController applicantsController = new(_applicantService, _fileService);
  112. var result = await applicantsController.DeleteApplicant(1000);
  113. (result as StatusCodeResult).StatusCode.Should().Be(200);
  114. }
  115. [Fact]
  116. public async Task GetProcesses_ShouldReturn_200OK_WhenApplicantExists()
  117. {
  118. _applicantService.GetApplicantWithSelectionProcessesById(Arg.Any<int>()).Returns(_applicant);
  119. ApplicantsController applicantsController = new(_applicantService,_fileService);
  120. var result = await applicantsController.GetProcesses(1);
  121. (result as OkObjectResult).StatusCode.Should().Be(200);
  122. }
  123. [Fact]
  124. public async Task GetProcesses_ShouldThrowEntityNotFoundException_WhenApplicantDoesnotExist()
  125. {
  126. _applicantService.When(x => x.GetApplicantWithSelectionProcessesById(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
  127. ApplicantsController applicantsController = new(_applicantService, _fileService);
  128. await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.GetProcesses(1000));
  129. }
  130. [Fact]
  131. public async Task GetOptions_ShouldReturn_200OK_Always()
  132. {
  133. _applicantService.GetOptions().Returns(new List<ApplicantOptionsDTO>());
  134. ApplicantsController applicantsController = new(_applicantService, _fileService);
  135. var result = await applicantsController.GetOptions();
  136. (result as OkObjectResult).StatusCode.Should().Be(200);
  137. }
  138. [Fact]
  139. public async Task InitSelecetion_ShouldReturnError_WhenApplicantDoesNotExist()
  140. {
  141. _applicantService.InitializeProcess(Arg.Any<ApplicantProcessRequestDTO>()).Returns(new ServiceResponseDTO<object>());
  142. ApplicantsController applicantsController = new(_applicantService, _fileService);
  143. var result = await applicantsController.InitSelection(Arg.Any<ApplicantProcessRequestDTO>());
  144. (result as OkObjectResult).StatusCode.Should().Be(200);
  145. }
  146. [Fact]
  147. public async Task ApplyForAd_ShouldThrowEntityNotFoundException_WhenAdDoesNotExist()
  148. {
  149. _applicantService.When(x => x.ApplyForAd(Arg.Any<ApplyForAdRequestDto>())).Do(x => { throw new EntityNotFoundException(); });
  150. ApplicantsController applicantsController = new(_applicantService, _fileService);
  151. await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.ApplyForAd(new ApplyForAdRequestDto()));
  152. }
  153. [Fact]
  154. public async Task ApplyForAd_ShouldReturn_200OK_WhenAdExist()
  155. {
  156. _applicantService.When(x => x.ApplyForAd(Arg.Any<ApplyForAdRequestDto>())).Do(x => { });
  157. ApplicantsController applicantsController = new(_applicantService, _fileService);
  158. var result = await applicantsController.ApplyForAd(new ApplyForAdRequestDto());
  159. (result as StatusCodeResult).StatusCode.Should().Be(200);
  160. }
  161. [Fact]
  162. public async Task GetApplicantCV_ShouldReturn_200OK_Always()
  163. {
  164. _fileService.GetCV(Arg.Any<string>()).Returns("some string");
  165. ApplicantsController applicantsController = new(_applicantService, _fileService);
  166. var result = await applicantsController.GetApplicantCV("some string");
  167. (result as OkObjectResult).StatusCode.Should().Be(200);
  168. }
  169. }
  170. }