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 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Diligent.WebAPI.Contracts.DTOs.Applicant;
  2. using Diligent.WebAPI.Contracts.DTOs.SelectionProcess;
  3. using Diligent.WebAPI.Contracts.Exceptions;
  4. using NSubstitute;
  5. namespace Diligent.WebAPI.Tests.Controllers
  6. {
  7. public class ApplicantsControllerTests
  8. {
  9. private IApplicantService _applicantService = Substitute.For<IApplicantService>();
  10. private readonly ApplicantViewDto _applicant;
  11. public ApplicantsControllerTests()
  12. {
  13. _applicant = new ApplicantViewDto
  14. {
  15. ApplicantId = 1,
  16. ApplicationChannel = "Instagram",
  17. BitBucketLink = null,
  18. CV = "link",
  19. DateOfApplication = DateTime.Now,
  20. Email = "some@mail.com",
  21. Experience = 1,
  22. FirstName = "Dzenis",
  23. LastName = "Hadzifejzovic",
  24. GithubLink = null,
  25. LinkedlnLink = null,
  26. PhoneNumber = "432424",
  27. Position = ".NET Developer",
  28. SelectionProcesses = new List<SelectionProcessResposneWithoutApplicantDto>
  29. {
  30. new SelectionProcessResposneWithoutApplicantDto{ Status = ""},
  31. new SelectionProcessResposneWithoutApplicantDto{ Status = ""},
  32. new SelectionProcessResposneWithoutApplicantDto{ Status = ""}
  33. }
  34. };
  35. }
  36. [Fact]
  37. public async Task GetById_ShouldReturn_200OK_WhenApplicantExist()
  38. {
  39. _applicantService.GetById(Arg.Any<int>()).Returns(_applicant);
  40. ApplicantsController applicantsController = new(_applicantService);
  41. var result = await applicantsController.GetById(1);
  42. (result as OkObjectResult).StatusCode.Should().Be(200);
  43. }
  44. [Fact]
  45. public async Task GetProcesses_ShouldReturn_200OK_WhenApplicantExists()
  46. {
  47. _applicantService.GetApplicantWithSelectionProcessesById(Arg.Any<int>()).Returns(_applicant);
  48. ApplicantsController applicantsController = new(_applicantService);
  49. var result = await applicantsController.GetProcesses(1);
  50. (result as OkObjectResult).StatusCode.Should().Be(200);
  51. }
  52. [Fact]
  53. public async Task GetById_ShouldThrowEntityNotFooundException_WhenApplicantDontExist()
  54. {
  55. _applicantService.When(x => x.GetById(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
  56. ApplicantsController applicantsController = new(_applicantService);
  57. await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.GetById(1000));
  58. }
  59. [Fact]
  60. public async Task GetProcesses_ShouldThrowEntityNotFooundException_WhenApplicantDoesnotExist()
  61. {
  62. _applicantService.When(x => x.GetApplicantWithSelectionProcessesById(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
  63. ApplicantsController applicantsController = new(_applicantService);
  64. await Assert.ThrowsAsync<EntityNotFoundException>(() => applicantsController.GetProcesses(1000));
  65. }
  66. [Fact]
  67. public async Task GetAll_ShouldReturn_200OK_Always()
  68. {
  69. var applicants = new List<ApplicantViewDto>
  70. {
  71. _applicant
  72. };
  73. _applicantService.GetAll().Returns(applicants);
  74. ApplicantsController applicantsController = new(_applicantService);
  75. var result = await applicantsController.GetAll();
  76. (result as OkObjectResult).StatusCode.Should().Be(200);
  77. }
  78. }
  79. }