| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using AutoMapper;
- using Castle.Core.Logging;
- 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;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- 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));
- }
- }
- }
|