| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using AutoMapper;
- using Diligent.WebAPI.Business.MappingProfiles;
- using Diligent.WebAPI.Business.Services;
- using Diligent.WebAPI.Contracts.DTOs.Technology;
- using Diligent.WebAPI.Contracts.Exceptions;
- using Diligent.WebAPI.Data.Entities;
- using Microsoft.Extensions.Logging;
-
- namespace Diligent.WebAPI.Tests.Services
- {
- public class TechnologyServiceTests
- {
- private readonly IMapper _mapper;
- private readonly List<Technology> _technologies = new();
- private readonly Technology _technology;
- private readonly ILogger<TechnologyService> _logger = Substitute.For<ILogger<TechnologyService>>();
-
- public TechnologyServiceTests()
- {
- var configuration = new MapperConfiguration(cfg => cfg.AddProfiles(
- new List<Profile>
- {
- new TechnologyMappingProfile()
- }));
- _mapper = new Mapper(configuration);
-
- _technology = new Technology
- {
- TechnologyId = 1,
- Name = ".NET",
- TechnologyType = TechnologyTypes.Backend
- };
-
- _technologies.Add(_technology);
- }
-
- [Fact]
- public async Task GetAll_ShouldReturnListOfTechnologies_Always()
- {
- var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies);
- TechnologyService tehnologyService = new(_mapper, databaseContext, _logger);
-
- var result = await tehnologyService.GetAllAsync();
-
- Assert.Equal(result.Count, 1);
- }
-
- [Fact]
- public async Task GetById_ShouldReturnTechnology_WhenTechnologyExists()
- {
- var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies);
- TechnologyService tehnologyService = new(_mapper, databaseContext, _logger);
-
- var result = await tehnologyService.GetByIdAsync(1);
-
- result.Should().BeEquivalentTo(_mapper.Map<TechnologyResponseDto>(_technology));
- }
-
- [Fact]
- public async Task GetById_ShouldThrowEntityNotFoundException_WhenTechnologyDoesNotExists()
- {
- var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies);
- TechnologyService tehnologyService = new(_mapper, databaseContext, _logger);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(async () => await tehnologyService.GetByIdAsync(1000));
- }
-
- [Fact]
- public async Task GetEntityById_ShouldReturnTechnology_WhenTechnologyExists()
- {
- var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies);
- TechnologyService tehnologyService = new(_mapper, databaseContext, _logger);
-
- var result = await tehnologyService.GetEntityByIdAsync(1);
-
- result.Should().BeEquivalentTo(_technology);
- }
-
- [Fact]
- public async Task GetEntityById_ShouldThrowEntityNotFoundException_WhenTechnologyDoesNotExists()
- {
- var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies);
- TechnologyService tehnologyService = new(_mapper, databaseContext, _logger);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(async () => await tehnologyService.GetEntityByIdAsync(1000));
- }
-
- [Fact]
- public async Task GetEntitiesAsync_ShouldReturnListOfTechnologies_Always()
- {
- var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies);
- TechnologyService tehnologyService = new(_mapper, databaseContext, _logger);
-
- var result = await tehnologyService.GetEntitiesAsync(new int[] {1});
-
- Assert.Single(result);
- }
-
- }
- }
|