|
|
|
|
|
|
|
|
|
|
|
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 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; |
|
|
|
|
|
|
|
|
|
|
|
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_WhenCalled() |
|
|
|
|
|
{ |
|
|
|
|
|
var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies); |
|
|
|
|
|
TechnologyService tehnologyService = new(_mapper, databaseContext); |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
var result = await tehnologyService.GetByIdAsync(1); |
|
|
|
|
|
|
|
|
|
|
|
result.Should().BeEquivalentTo(_mapper.Map<TechnologyResponseDto>(_technology)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task GetById_ShouldThrowEntityNotFoundException_WhenTechnologyDontExists() |
|
|
|
|
|
{ |
|
|
|
|
|
var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies); |
|
|
|
|
|
TechnologyService tehnologyService = new(_mapper, databaseContext); |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
var result = await tehnologyService.GetEntityByIdAsync(1); |
|
|
|
|
|
|
|
|
|
|
|
result.Should().BeEquivalentTo(_technology); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task GetEntityById_ShouldThrowEntityNotFoundException_WhenTechnologyDontExists() |
|
|
|
|
|
{ |
|
|
|
|
|
var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies); |
|
|
|
|
|
TechnologyService tehnologyService = new(_mapper, databaseContext); |
|
|
|
|
|
|
|
|
|
|
|
await Assert.ThrowsAsync<EntityNotFoundException>(async () => await tehnologyService.GetEntityByIdAsync(1000)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |