| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using AutoMapper;
- using Diligent.WebAPI.Business.MappingProfiles;
- using Diligent.WebAPI.Business.Services;
- using Diligent.WebAPI.Contracts.DTOs.Applicant;
- using Diligent.WebAPI.Contracts.DTOs.SelectionLevel;
- using Diligent.WebAPI.Contracts.Exceptions;
- using Diligent.WebAPI.Data.Entities;
-
- namespace Diligent.WebAPI.Tests.Services
- {
- public class SelectionLevelsServiceTests
- {
- private readonly IMapper _mapper;
- private readonly List<SelectionLevel> _levels;
- private readonly SelectionLevel _selectionLevel;
- public SelectionLevelsServiceTests()
- {
- _selectionLevel = new SelectionLevel
- {
- Id = 1,
- Name = "HR intervju",
- SelectionProcesses = new List<SelectionProcess>()
- };
-
- // configure mapper
- var configuration = new MapperConfiguration(cfg => cfg.AddProfiles(
- new List<Profile>
- {
- new SelectionLevelMappingProfile(),
- }));
- _mapper = new Mapper(configuration);
- }
-
- [Fact]
- public async Task GetAll_ShouldReturnListOfLevels_Always()
- {
- var databaseContext = await Helpers<SelectionLevel>.GetDatabaseContext(_levels);
- SelectionLevelService service = new(databaseContext, _mapper);
-
- var result = await service.GetAllAsync();
-
- result.Should().HaveCount(4);
- }
-
- [Fact]
- public async Task GetById_ShouldReturnLevel_WhenLevelExist()
- {
- var databaseContext = await Helpers<SelectionLevel>.GetDatabaseContext(_levels);
- SelectionLevelService service = new(databaseContext, _mapper);
-
- var result = await service.GetByIdAsync(1);
-
- result.Should().BeEquivalentTo(_mapper.Map<SelectionLevelResposneDto>(_selectionLevel));
- }
-
- [Fact]
- public async Task GetById_ShouldThrowEntityNotFooundException_WhenLevelDoesnotExist()
- {
- var databaseContext = await Helpers<SelectionLevel>.GetDatabaseContext(_levels);
- SelectionLevelService service = new(databaseContext, _mapper);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.GetByIdAsync(1000));
- }
- }
- }
|