Explorar el Código

Merge branch 'feature/unit_tests_applicants_completed' of Neca/HRCenter into BE_dev

pull/152/head
safet.purkovic hace 3 años
padre
commit
756a965d75

+ 2
- 1
Diligent.WebAPI.Business/Extensions/ApplicantExtensions.cs Ver fichero

@@ -1,4 +1,5 @@
using static Diligent.WebAPI.Data.Entities.Applicant;
using System.Diagnostics.CodeAnalysis;
using static Diligent.WebAPI.Data.Entities.Applicant;

namespace Diligent.WebAPI.Business.Extensions
{

+ 3
- 1
Diligent.WebAPI.Business/Extensions/PaginationExtension.cs Ver fichero

@@ -1,4 +1,6 @@
namespace Diligent.WebAPI.Business.Extensions
using System.Diagnostics.CodeAnalysis;

namespace Diligent.WebAPI.Business.Extensions
{
[ExcludeFromCodeCoverage]
public static class PaginationExtension

+ 2
- 0
Diligent.WebAPI.Business/MappingProfiles/AdMappingProfile.cs Ver fichero

@@ -1,4 +1,6 @@

using System.Diagnostics.CodeAnalysis;

namespace Diligent.WebAPI.Business.MappingProfiles
{
public class AdMappingProfile : Profile

+ 7
- 2
Diligent.WebAPI.Business/Services/ApplicantService.cs Ver fichero

@@ -10,9 +10,10 @@ namespace Diligent.WebAPI.Business.Services
private readonly IUserService _userService;
private readonly IFileService _fileService;
private readonly IAdService _adService;
private readonly ITechnologyService _technologyService;

public ApplicantService(DatabaseContext context, IMapper mapper, ILogger<ApplicantService> logger,
IUserService userService,IFileService fileService,IAdService adService)
IUserService userService,IFileService fileService,IAdService adService,ITechnologyService technologyService)
{
_context = context;
_mapper = mapper;
@@ -20,6 +21,7 @@ namespace Diligent.WebAPI.Business.Services
_userService = userService;
_fileService = fileService;
_adService = adService;
_technologyService = technologyService;
}
public async Task<QueryResultDto<ApplicantViewDto>> GetFilteredApplicants(ApplicantFilterDto applicantFilterDto)
{
@@ -121,7 +123,9 @@ namespace Diligent.WebAPI.Business.Services

_logger.LogInformation($"Got {adsApplicants.Count} ads");

_logger.LogInformation("Mapping received Ads to AdApplicantsViewDto");
var result = _mapper.Map<List<AdApplicantsViewDto>>(adsApplicants);
_logger.LogInformation($"Ads mapped successfully");
return result;
}

@@ -145,7 +149,8 @@ namespace Diligent.WebAPI.Business.Services
}

_logger.LogInformation($"Find sent technologies from FE in database");
var technologies = await _context.Technologies.Where(x => request.TechnologiesIds.Contains(x.TechnologyId)).ToListAsync();
//var technologies = await _context.Technologies.Where(x => request.TechnologiesIds.Contains(x.TechnologyId)).ToListAsync();
var technologies = await _technologyService.GetEntitiesAsync(request.TechnologiesIds);

_logger.LogInformation($"Create applicant instance with sent data");
Applicant applicant = new()

+ 3
- 1
Diligent.WebAPI.Business/Services/InsuranceCompaniesService.cs Ver fichero

@@ -1,4 +1,6 @@
namespace Diligent.WebAPI.Business.Services
using System.Diagnostics.CodeAnalysis;

namespace Diligent.WebAPI.Business.Services
{
[ExcludeFromCodeCoverage]
public class InsuranceCompaniesService : IInsuranceCompaniesService

+ 3
- 1
Diligent.WebAPI.Business/Services/InsurancePoliciesService.cs Ver fichero

@@ -1,4 +1,6 @@
namespace Diligent.WebAPI.Business.Services
using System.Diagnostics.CodeAnalysis;

namespace Diligent.WebAPI.Business.Services
{
[ExcludeFromCodeCoverage]
public class InsurancePoliciesService : IInsurancePoliciesService

+ 3
- 1
Diligent.WebAPI.Business/Services/InsurersService.cs Ver fichero

@@ -1,4 +1,6 @@
namespace Diligent.WebAPI.Business.Services
using System.Diagnostics.CodeAnalysis;

namespace Diligent.WebAPI.Business.Services
{
[ExcludeFromCodeCoverage]
public class InsurersService : IInsurersService

+ 1
- 0
Diligent.WebAPI.Business/Services/Interfaces/ITechnologyService.cs Ver fichero

@@ -6,5 +6,6 @@ namespace Diligent.WebAPI.Business.Services.Interfaces
Task<List<TechnologyResponseDto>> GetAllAsync();
Task<TechnologyResponseDto> GetByIdAsync(int id);
Task<Technology> GetEntityByIdAsync(int id);
Task<List<Technology>> GetEntitiesAsync(int [] technologiesIds);
}
}

+ 0
- 5
Diligent.WebAPI.Business/Services/PatternService.cs Ver fichero

@@ -1,9 +1,4 @@
using Diligent.WebAPI.Contracts.DTOs.Pattern;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Business.Services
{

+ 15
- 1
Diligent.WebAPI.Business/Services/TechnologyService.cs Ver fichero

@@ -15,7 +15,13 @@

public async Task<List<TechnologyResponseDto>> GetAllAsync()
{
return _mapper.Map<List<TechnologyResponseDto>>(await _context.Technologies.ToListAsync());
_logger.LogInformation("Start getting all technologies");
var technologies = await _context.Technologies.ToListAsync();
_logger.LogInformation($"Received {technologies.Count} technologies from database");
_logger.LogInformation("Mapping received technologies to TechnologyResponseDto");
var technologiesDto = _mapper.Map<List<TechnologyResponseDto>>(technologies);
_logger.LogInformation($"Technologies mapped successfully");
return technologiesDto;
}

public async Task<TechnologyResponseDto> GetByIdAsync(int id)
@@ -48,5 +54,13 @@
_logger.LogInformation($"Technology with id = {id} found successfully");
return technology;
}

public async Task<List<Technology>> GetEntitiesAsync(int[] technologiesIds)
{
_logger.LogInformation("Start getting all technologies");
var technologies = await _context.Technologies.Where(x => technologiesIds.Contains(x.TechnologyId)).ToListAsync();
_logger.LogInformation($"Received {technologies.Count} technologies from database");
return technologies;
}
}
}

+ 3
- 1
Diligent.WebAPI.Business/Services/WebhookDefinitionService.cs Ver fichero

@@ -1,4 +1,6 @@
namespace Diligent.WebAPI.Business.Services
using System.Diagnostics.CodeAnalysis;

namespace Diligent.WebAPI.Business.Services
{
[ExcludeFromCodeCoverage]
public class WebhookDefinitionService : IWebhookDefinitionService

+ 3
- 1
Diligent.WebAPI.Business/Services/WebhookPublisherService.cs Ver fichero

@@ -1,4 +1,6 @@
namespace Diligent.WebAPI.Business.Services
using System.Diagnostics.CodeAnalysis;

namespace Diligent.WebAPI.Business.Services
{
[ExcludeFromCodeCoverage]
public class WebhookPublisherService : IWebhookPublisherService

+ 3
- 1
Diligent.WebAPI.Business/Services/WebhookSubscriptionService.cs Ver fichero

@@ -1,4 +1,6 @@
namespace Diligent.WebAPI.Business.Services
using System.Diagnostics.CodeAnalysis;

namespace Diligent.WebAPI.Business.Services
{
[ExcludeFromCodeCoverage]
public class WebhookSubscriptionService : IWebhookSubscriptionService

+ 3
- 1
Diligent.WebAPI.Host/Extensions/BusinessConfigurationExtension.cs Ver fichero

@@ -1,4 +1,6 @@
namespace Diligent.WebAPI.Host.Extensions
using System.Diagnostics.CodeAnalysis;

namespace Diligent.WebAPI.Host.Extensions
{
[ExcludeFromCodeCoverage]
public static class BusinessConfigurationExtension

+ 1
- 1
Diligent.WebAPI.Tests/Controllers/ApplicantsControllerTests.cs Ver fichero

@@ -205,7 +205,7 @@ namespace Diligent.WebAPI.Tests.Controllers
_fileService.GetCV(Arg.Any<string>()).Returns("some string");
ApplicantsController applicantsController = new(_applicantService, _fileService);

var result = await applicantsController.GetOptions();
var result = await applicantsController.GetApplicantCV("some string");

(result as OkObjectResult).StatusCode.Should().Be(200);
}

+ 20
- 15
Diligent.WebAPI.Tests/Services/ApplicantServiceTests.cs Ver fichero

@@ -17,15 +17,18 @@ namespace Diligent.WebAPI.Tests.Services
private readonly IUserService _userService = Substitute.For<IUserService>();
private readonly IFileService _fileService = Substitute.For<IFileService>();
private readonly IAdService _adService = Substitute.For<IAdService>();
private readonly ITechnologyService _technologyService = Substitute.For<ITechnologyService>();
private readonly List<Applicant> _applicants;
private readonly List<Ad> _ads;
private readonly List<User> _users;
private readonly List<Technology> _technologies;
public ApplicantServiceTests()
{
// mock data
_applicants = MockData.GetListOfApplicants();
_ads = MockData.GetListOfAds();
_users = MockData.GetListOfUsers();
_technologies = MockData.GetListOfTechnologies();

// configure mapper
var configuration = new MapperConfiguration(cfg => cfg.AddProfiles(
@@ -33,7 +36,8 @@ namespace Diligent.WebAPI.Tests.Services
{
new ApplicantMappingProfile(),
new AdMappingProfile(),
new SelectionProcessMappingProfile()
new SelectionProcessMappingProfile(),
new TechnologyMappingProfile()
}));
_mapper = new Mapper(configuration);
}
@@ -43,7 +47,7 @@ namespace Diligent.WebAPI.Tests.Services
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);

ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);

var filterDto = new ApplicantFilterDto
{
@@ -61,7 +65,7 @@ namespace Diligent.WebAPI.Tests.Services
public async Task GetAllAdsApplicants_ShouldReturnAllApplicants_Always()
{
var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);

var filterDto = MockData.GetApplicantFilters();

@@ -75,7 +79,7 @@ namespace Diligent.WebAPI.Tests.Services
{
var fileInBase64Format = "some string";
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);
_fileService.GetCV(Arg.Any<string>()).Returns(fileInBase64Format);

var result = await applicantService.GetById(1);
@@ -88,7 +92,7 @@ namespace Diligent.WebAPI.Tests.Services
public async Task GetById_ShouldThrowEntityNotFoundException_WhenApplicantDoesNotExist()
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);

await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.GetById(1000));
}
@@ -97,7 +101,7 @@ namespace Diligent.WebAPI.Tests.Services
public async Task GetApplicantWithSelectionProcessesById_ShouldReturnApplicant_WhenApplicantExists()
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);

var result = await applicantService.GetApplicantWithSelectionProcessesById(1);
var processes = result.SelectionProcesses;
@@ -110,7 +114,7 @@ namespace Diligent.WebAPI.Tests.Services
public async Task GetApplicantWithSelectionProcessesById_ShouldThrowEntityNotFoundException_WhenApplicantDoesNotExist()
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);

await Assert.ThrowsAsync<EntityNotFoundException>(async () => await
applicantService.GetApplicantWithSelectionProcessesById(1000));
@@ -120,7 +124,7 @@ namespace Diligent.WebAPI.Tests.Services
public async Task ApplyForAd_ShouldThrowEntityNotFooundException_WhenAdIsNotFound()
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);
ApplyForAdRequestDto applyForAdRequestDto = new()
{
AdId = 1,
@@ -147,7 +151,7 @@ namespace Diligent.WebAPI.Tests.Services
public async Task ApplyForAd_ApplicantShouldBeCreated_Always()
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);
ApplyForAdRequestDto applyForAdRequestDto = new()
{
AdId = 1,
@@ -165,6 +169,7 @@ namespace Diligent.WebAPI.Tests.Services
TechnologiesIds = new int[] { 1 },
};
_fileService.When(x => x.UploadCV(Arg.Any<string>(), Arg.Any<IFormFile>())).Do(x => { });
_technologyService.GetEntitiesAsync(Arg.Any<int[]>()).Returns(_technologies);
_adService.GetByIdEntityAsync(Arg.Any<int>()).Returns(new Ad
{
Id = 10,
@@ -189,7 +194,7 @@ namespace Diligent.WebAPI.Tests.Services
public async Task DeleteApplicant_ShouldDeleteApplicant_WhenApplicantExist()
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);

await applicantService.DeleteApplicant(1);

@@ -204,7 +209,7 @@ namespace Diligent.WebAPI.Tests.Services
public async Task DeleteApplicant_ShouldThrowEntityNotFooundException_WhenApplicantDoesNotExist()
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);

await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.DeleteApplicant(1000));
}
@@ -213,7 +218,7 @@ namespace Diligent.WebAPI.Tests.Services
public async Task GetOptions_ShouldReturnAllOptions_Always()
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);

var res = await applicantService.GetOptions();
Assert.Equal(2, res.Count);
@@ -223,7 +228,7 @@ namespace Diligent.WebAPI.Tests.Services
public async Task InitializeProcess_ShouldReturnError_WhenApplicantDoesNotExist()
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);
var res = await applicantService.InitializeProcess(new ApplicantProcessRequestDTO
{
ApplicantId = 1000,
@@ -238,7 +243,7 @@ namespace Diligent.WebAPI.Tests.Services
public async Task InitializeProcess_SelectionProcessShouldBeCreated_WhenApplicantExist()
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);
var res = await applicantService.InitializeProcess(new ApplicantProcessRequestDTO
{
@@ -257,7 +262,7 @@ namespace Diligent.WebAPI.Tests.Services
{
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
_userService.GetFirst().Returns(_users[0]);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService);
ApplicantService applicantService = new(databaseContext, _mapper, _logger, _userService, _fileService, _adService, _technologyService);

var ad = new Ad
{

+ 12
- 6
Diligent.WebAPI.Tests/Services/TechnologyServiceTests.cs Ver fichero

@@ -1,16 +1,10 @@
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
{
@@ -90,5 +84,17 @@ namespace Diligent.WebAPI.Tests.Services

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);
}

}
}

Cargando…
Cancelar
Guardar