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

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