Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ApplicantsControllerTests.cs 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 IApplicantService _applicantService = Substitute.For<IApplicantService>();
  11. private readonly ApplicantViewDto _applicant;
  12. public ApplicantsControllerTests()
  13. {
  14. _applicant = new ApplicantViewDto
  15. {
  16. ApplicantId = 1,
  17. ApplicationChannel = "Instagram",
  18. BitBucketLink = null,
  19. CV = "link",
  20. DateOfApplication = DateTime.Now,
  21. Email = "some@mail.com",
  22. Experience = 1,
  23. FirstName = "Dzenis",
  24. LastName = "Hadzifejzovic",
  25. GithubLink = null,
  26. LinkedlnLink = null,
  27. PhoneNumber = "432424",
  28. Position = ".NET Developer",
  29. SelectionProcesses = new List<SelectionProcessResposneWithoutApplicantDto>
  30. {
  31. new SelectionProcessResposneWithoutApplicantDto{ Status = ""},
  32. new SelectionProcessResposneWithoutApplicantDto{ Status = ""},
  33. new SelectionProcessResposneWithoutApplicantDto{ Status = ""}
  34. }
  35. };
  36. }
  37. [Fact]
  38. public async Task GetProcesses_ShouldReturn_200OK_WhenApplicantExists()
  39. {
  40. _applicantService.GetApplicantWithSelectionProcessesById(Arg.Any<int>()).Returns(_applicant);
  41. ApplicantsController applicantsController = new(_applicantService);
  42. var result = await applicantsController.GetProcesses(1);
  43. (result as OkObjectResult).StatusCode.Should().Be(200);
  44. }
  45. [Fact]
  46. public async Task GetProcesses_ShouldThrowEntityNotFooundException_WhenApplicantDoesnotExist()
  47. {
  48. _applicantService.When(x => x.GetApplicantWithSelectionProcessesById(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
  49. ApplicantsController applicantsController = new(_applicantService);
  50. await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.GetProcesses(1000));
  51. }
  52. [Fact]
  53. public async Task GetById_ShouldReturn_200OK_WhenApplicantExist()
  54. {
  55. _applicantService.GetById(Arg.Any<int>()).Returns(_applicant);
  56. ApplicantsController applicantsController = new(_applicantService);
  57. var result = await applicantsController.GetById(1);
  58. (result as OkObjectResult).StatusCode.Should().Be(200);
  59. }
  60. [Fact]
  61. public async Task GetById_ShouldThrowEntityNotFooundException_WhenApplicantDontExist()
  62. {
  63. _applicantService.When(x => x.GetById(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
  64. ApplicantsController applicantsController = new(_applicantService);
  65. await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.GetById(1000));
  66. }
  67. [Fact]
  68. public async Task GetFilteredApplicants_ShouldReturn_200OK_Always()
  69. {
  70. var applicants = new List<ApplicantViewDto>
  71. {
  72. _applicant
  73. };
  74. var filterDto = new ApplicantFilterDto
  75. {
  76. CurrentPage = 1,
  77. PageSize = 4
  78. };
  79. _applicantService.GetFilteredApplicants(filterDto).Returns(new QueryResultDto<ApplicantViewDto>
  80. {
  81. Items = applicants,
  82. Total = applicants.Count
  83. });
  84. ApplicantsController applicantsController = new(_applicantService);
  85. var result = await applicantsController.GetFilteredApplicants(filterDto);
  86. (result as OkObjectResult).StatusCode.Should().Be(200);
  87. }
  88. }
  89. }