您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SelectionProcessesControllerTests.cs 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Diligent.WebAPI.Contracts.DTOs.SelectionProcess;
  2. using Diligent.WebAPI.Contracts.Exceptions;
  3. namespace Diligent.WebAPI.Tests.Controllers
  4. {
  5. public class SelectionProcessesControllerTests
  6. {
  7. private ISelectionProcessService _service = Substitute.For<ISelectionProcessService>();
  8. private readonly SelectionProcessResposneDto _selectionProcess;
  9. public SelectionProcessesControllerTests()
  10. {
  11. _selectionProcess = new SelectionProcessResposneDto
  12. {
  13. Id = 1,
  14. Name = "HR intervju"
  15. };
  16. }
  17. [Fact]
  18. public async Task FinishSelectionProcess_ShouldReturn_True_WhenProcessExists()
  19. {
  20. _service.FinishSelectionProcess(Arg.Any<SelectionProcessCreateDto>()).Returns(true);
  21. SelectionProcessesController controller = new(_service);
  22. var result = await controller.FinishSelectionProcess(new SelectionProcessCreateDto());
  23. (result as OkObjectResult).StatusCode.Should().Be(200);
  24. }
  25. [Fact]
  26. public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist()
  27. {
  28. _service.When(x => x.FinishSelectionProcess(Arg.Any<SelectionProcessCreateDto>())).Do(x => { throw new EntityNotFoundException(); });
  29. SelectionProcessesController controller = new(_service);
  30. await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.FinishSelectionProcess(new SelectionProcessCreateDto()));
  31. }
  32. [Fact]
  33. public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessWasInLastLevel()
  34. {
  35. _service.When(x => x.FinishSelectionProcess(Arg.Any<SelectionProcessCreateDto>())).Do(x => { throw new EntityNotFoundException(); });
  36. SelectionProcessesController controller = new(_service);
  37. await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.FinishSelectionProcess(new SelectionProcessCreateDto()));
  38. }
  39. [Fact]
  40. public async Task UpdateStatus_ShouldReturn_200OK()
  41. {
  42. _service.StatusUpdate(Arg.Any<StatusChangeDTO>());
  43. SelectionProcessesController controller = new(_service);
  44. var result = await controller.UpdateStatus(new StatusChangeDTO());
  45. (result as OkObjectResult).StatusCode.Should().Be(200);
  46. }
  47. [Fact]
  48. public async Task UpdateStatus_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist()
  49. {
  50. _service.When(x => x.StatusUpdate(Arg.Any<StatusChangeDTO>())).Do(x => { throw new EntityNotFoundException(); });
  51. SelectionProcessesController controller = new(_service);
  52. await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.UpdateStatus(new StatusChangeDTO()));
  53. }
  54. [Fact]
  55. public async Task UpdateStatus_ShouldThrowEntityNotFooundException_WhenUserDoesNotExist()
  56. {
  57. _service.When(x => x.StatusUpdate(Arg.Any<StatusChangeDTO>())).Do(x => { throw new EntityNotFoundException(); });
  58. SelectionProcessesController controller = new(_service);
  59. await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.UpdateStatus(new StatusChangeDTO()));
  60. }
  61. [Fact]
  62. public async Task UpdateInterviewer_ShouldReturn_200OK()
  63. {
  64. _service.InterviewerUpdate(Arg.Any<InterviewerUpdateDTO>());
  65. SelectionProcessesController controller = new(_service);
  66. var result = await controller.UpdateInterviewer(new InterviewerUpdateDTO());
  67. (result as OkObjectResult).StatusCode.Should().Be(200);
  68. }
  69. [Fact]
  70. public async Task UpdateInterviewer_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist()
  71. {
  72. _service.When(x => x.InterviewerUpdate(Arg.Any<InterviewerUpdateDTO>())).Do(x => { throw new EntityNotFoundException(); });
  73. SelectionProcessesController controller = new(_service);
  74. await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.UpdateInterviewer(new InterviewerUpdateDTO()));
  75. }
  76. [Fact]
  77. public async Task UpdateInterviewer_ShouldThrowEntityNotFooundException_WhenUserDoesNotExist()
  78. {
  79. _service.When(x => x.InterviewerUpdate(Arg.Any<InterviewerUpdateDTO>())).Do(x => { throw new EntityNotFoundException(); });
  80. SelectionProcessesController controller = new(_service);
  81. await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.UpdateInterviewer(new InterviewerUpdateDTO()));
  82. }
  83. }
  84. }