| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using Diligent.WebAPI.Contracts.DTOs.SelectionLevel;
- using Diligent.WebAPI.Contracts.DTOs.SelectionProcess;
- using Diligent.WebAPI.Contracts.Exceptions;
-
- namespace Diligent.WebAPI.Tests.Controllers
- {
- public class SelectionLevelsControllerTests
- {
- private ISelectionLevelService _service = Substitute.For<ISelectionLevelService>();
- private readonly SelectionLevelResposneDto _selectionLevel;
- public SelectionLevelsControllerTests()
- {
- _selectionLevel = new SelectionLevelResposneDto
- {
- Id = 1,
- Name = "HR intervju"
- };
- }
-
- [Fact]
- public async Task GetById_ShouldReturn_200OK_WhenLevelExist()
- {
- _service.GetByIdAsync(Arg.Any<int>()).Returns(_selectionLevel);
- SelectionLevelsController controller = new(_service);
-
- var result = await controller.GetById(1);
-
- (result as OkObjectResult).StatusCode.Should().Be(200);
- }
-
- [Fact]
- public async Task GetById_ShouldThrowEntityNotFooundException_WhenLevelDoesnotExist()
- {
- _service.When(x => x.GetByIdAsync(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
- SelectionLevelsController controller = new(_service);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(() => controller.GetById(1000));
- }
-
- [Fact]
- public async Task GetAll_ShouldReturn_200OK_Always()
- {
- var levels = new List<SelectionLevelResponseWithDataDto>
- {
- new SelectionLevelResponseWithDataDto
- {
- Id = 1,
- Name = "HR intervju",
- SelectionProcesses = new List<SelectionProcessResposneDto>()
- }
- };
- _service.GetAllAsync().Returns(levels);
- SelectionLevelsController controller = new(_service);
-
- var result = await controller.GetAll();
-
- (result as OkObjectResult).StatusCode.Should().Be(200);
- }
- }
- }
|