| { | { | ||||
| public static class AdExtensions | public static class AdExtensions | ||||
| { | { | ||||
| public static IQueryable<Ad> FilterByExperience(this IQueryable<Ad> query, int minExperience, int maxExperience) => | |||||
| minExperience >= maxExperience ? query.Where(x => x.MinimumExperience >= minExperience && x.MinimumExperience <= maxExperience) | |||||
| : query.Where(x => x.MinimumExperience >= minExperience && x.MinimumExperience <= maxExperience); | |||||
| public static IQueryable<Ad> FilterByWorkType(this IQueryable<Ad> query, string workHour) => | |||||
| workHour.ToLower() == "parttime" ? query.Where(x => x.WorkHour == WorkHours.PartTime) : query.Where(x => x.WorkHour == WorkHours.FullTime); | |||||
| public static IQueryable<Ad> FilterByEmploymentType(this IQueryable<Ad> query, string employmentType) => | |||||
| employmentType.ToLower() == "intership" ? query.Where(x => x.EmploymentType == EmploymentTypes.Intership) : query.Where(x => x.EmploymentType == EmploymentTypes.Work); | |||||
| public static List<Ad> Filter(this List<Ad> query, AdFilterDto filters) => | |||||
| query.FilterByExperience(filters.MinExperience, filters.MaxExperience).FilterByWorkType(filters.WorkHour).FilterByEmploymentType(filters.EmploymentType).ToList().FilterByTechnologies(filters.Technologies); | |||||
| public static List<Ad> FilterByExperience(this List<Ad> query, int minExperience, int maxExperience) => | |||||
| minExperience >= maxExperience ? query.Where(x => x.MinimumExperience >= minExperience && x.MinimumExperience <= maxExperience).ToList() | |||||
| : query.Where(x => x.MinimumExperience >= minExperience && x.MinimumExperience <= maxExperience).ToList(); | |||||
| public static List<Ad> FilterByWorkType(this List<Ad> query, string workHour) => | |||||
| workHour.ToLower() == "parttime" ? query.Where(x => x.WorkHour == WorkHours.PartTime).ToList() : query.Where(x => x.WorkHour == WorkHours.FullTime).ToList(); | |||||
| public static List<Ad> FilterByEmploymentType(this List<Ad> query, string employmentType) => | |||||
| employmentType.ToLower() == "intership" ? query.Where(x => x.EmploymentType == EmploymentTypes.Intership).ToList() : query.Where(x => x.EmploymentType == EmploymentTypes.Work).ToList(); | |||||
| public static List<Ad> FilterByTechnologies(this List<Ad> query, string[] technologies) | public static List<Ad> FilterByTechnologies(this List<Ad> query, string[] technologies) | ||||
| { | { | ||||
| if (technologies.Length == 0) | |||||
| if (technologies == null || technologies.Length == 0) | |||||
| { | { | ||||
| return query; | return query; | ||||
| } | } | ||||
| List<Ad> filteredAds = new List<Ad>(); | List<Ad> filteredAds = new List<Ad>(); | ||||
| for (int i = 0; i < query.Count(); i++) | for (int i = 0; i < query.Count(); i++) | ||||
| { | { |
| public async Task<List<AdResponseDto>> GetFilteredAdsAsync(AdFilterDto filters) | public async Task<List<AdResponseDto>> GetFilteredAdsAsync(AdFilterDto filters) | ||||
| { | { | ||||
| var filteredAds = await _context.Ads.Include(x => x.Technologies) | |||||
| .FilterByExperience(filters.MinExperience, filters.MaxExperience) | |||||
| .FilterByWorkType(filters.WorkHour) | |||||
| .FilterByEmploymentType(filters.EmploymentType) | |||||
| .ToListAsync(); | |||||
| var filteredAds = await _context.Ads.Include(x => x.Technologies).ToListAsync(); | |||||
| filteredAds = filteredAds.FilterByTechnologies(filters.Technologies); | |||||
| return _mapper.Map<List<AdResponseDto>>(filteredAds); | |||||
| return _mapper.Map<List<AdResponseDto>>(filteredAds.Filter(filters)); | |||||
| } | } | ||||
| public async Task CreateAsync(AdCreateDto adCreateDto) | public async Task CreateAsync(AdCreateDto adCreateDto) |
| public DateTime ExpiredAt { get; set; } | public DateTime ExpiredAt { get; set; } | ||||
| public string MainLiabilities { get; set; } | |||||
| public string KeyResponsibilities { get; set; } | |||||
| public string Conditions { get; set; } | |||||
| public string Requirements { get; set; } | |||||
| public string Offer { get; set; } | public string Offer { get; set; } | ||||
| public string WorkHour { get; set; } | |||||
| public string EmploymentType { get; set; } | |||||
| } | } | ||||
| } | } |
| public int TechnologyId { get; set; } | public int TechnologyId { get; set; } | ||||
| public string Name { get; set; } | public string Name { get; set; } | ||||
| public TechnologyTypes TechnologyType { get; set; } | public TechnologyTypes TechnologyType { get; set; } | ||||
| public List<TechnologyApplicant> TechnologyApplicants { get; set; } | |||||
| public List<TechnologyApplicant> TechnologyApplicants { get; set; } = new(); | |||||
| public List<Ad> Ads { get; set; } = new(); | public List<Ad> Ads { get; set; } = new(); | ||||
| } | } |
| } | } | ||||
| [HttpDelete("{id}")] | [HttpDelete("{id}")] | ||||
| public async Task<IActionResult> DeleteInsurer([FromRoute]int id) | |||||
| public async Task<IActionResult> DeleteAd([FromRoute]int id) | |||||
| { | { | ||||
| await _adService.DeleteAsync(id); | await _adService.DeleteAsync(id); | ||||
| return NoContent(); | return NoContent(); |
| { | { | ||||
| "ConnectionStrings": { | "ConnectionStrings": { | ||||
| "WebApi": "Server=192.168.88.105;Database=HRCenter;User Id=hrcentar;Password=" | |||||
| "WebApi": "Server=192.168.88.105;Database=HRCenter;User Id=hrcentar;Password=administrator#2021;" | |||||
| }, | }, | ||||
| "Authorization": { | "Authorization": { | ||||
| "JwtExpiredTime": "5", | "JwtExpiredTime": "5", |
| { | { | ||||
| "ConnectionStrings": { | "ConnectionStrings": { | ||||
| "WebApi": "Server=192.168.88.105;Database=HRCenter;User Id=hrcentar;Password=" | |||||
| "WebApi": "Server=192.168.88.105;Database=HRCenter;User Id=hrcentar;Password=administrator#2021;" | |||||
| }, | }, | ||||
| "Authorization": { | "Authorization": { | ||||
| "JwtExpiredTime": "5", | "JwtExpiredTime": "5", |
| using Diligent.WebAPI.Contracts.DTOs.Ad; | |||||
| 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.Controllers | |||||
| { | |||||
| public class AdsControllerTests | |||||
| { | |||||
| private IAdService _adService = Substitute.For<IAdService>(); | |||||
| private List<AdResponseDto> _ads = new List<AdResponseDto>(); | |||||
| private AdResponseDto _ad; | |||||
| public AdsControllerTests() | |||||
| { | |||||
| _ad = new AdResponseDto | |||||
| { | |||||
| Id = 1, | |||||
| Title = "React Developer", | |||||
| MinimumExperience = 0, | |||||
| CreatedAt = DateTime.UtcNow, | |||||
| ExpiredAt = DateTime.UtcNow.AddDays(30), | |||||
| KeyResponsibilities = "KR|KR", | |||||
| Requirements = "R|R|R", | |||||
| Offer = "O|O", | |||||
| WorkHour = nameof(WorkHours.FullTime), | |||||
| EmploymentType = nameof(EmploymentTypes.Intership) | |||||
| }; | |||||
| _ads.Add(_ad); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetAll_ShouldReturn200OK_WhenCalled() | |||||
| { | |||||
| _adService.GetAllAsync().Returns(_ads); | |||||
| AdsController adsController = new(_adService); | |||||
| var result = await adsController.GetAll(); | |||||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetById_ShouldReturn200OK_WhenAdExists() | |||||
| { | |||||
| _adService.GetByIdAsync(Arg.Any<int>()).Returns(_ad); | |||||
| AdsController adsController = new(_adService); | |||||
| var result = await adsController.GetById(1); | |||||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetById_ShouldThrowEntityNotFoundException_WhenAdDontExist() | |||||
| { | |||||
| _adService.When(x => x.GetByIdAsync(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); }); | |||||
| AdsController adsController = new(_adService); | |||||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => adsController.GetById(1000)); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetAdDetailsById_ShouldReturn200OK_WhenAdExists() | |||||
| { | |||||
| _adService.GetAdDetailsByIdAsync(Arg.Any<int>()).Returns(new AdDetailsResponseDto | |||||
| { | |||||
| Id = 1, | |||||
| Title = "React Developer", | |||||
| MinimumExperience = 0, | |||||
| CreatedAt = DateTime.UtcNow, | |||||
| ExpiredAt = DateTime.UtcNow.AddDays(30), | |||||
| KeyResponsibilities = "KR|KR", | |||||
| Requirements = "R|R|R", | |||||
| Offer = "O|O" | |||||
| }); | |||||
| AdsController adsController = new(_adService); | |||||
| var result = await adsController.GetAdDetailsById(1); | |||||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetAdDetailsById_ShouldThrowEntityNotFoundException_WhenAdDontExist() | |||||
| { | |||||
| _adService.When(x => x.GetAdDetailsByIdAsync(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); }); | |||||
| AdsController adsController = new(_adService); | |||||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => adsController.GetAdDetailsById(1000)); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetArchiveAds_ShouldReturn200OK_WhenCalled() | |||||
| { | |||||
| _adService.GetArchiveAds().Returns(_ads); | |||||
| AdsController adsController = new(_adService); | |||||
| var result = await adsController.GetArchiveAds(); | |||||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetFilteredAds_ShouldReturn200OK_WhenCalled() | |||||
| { | |||||
| var filters = new AdFilterDto | |||||
| { | |||||
| MinExperience = 0, | |||||
| MaxExperience = 10, | |||||
| EmploymentType = "Work", | |||||
| WorkHour = "FullTime", | |||||
| Technologies = new string[] { ".NET" } | |||||
| }; | |||||
| _adService.GetFilteredAdsAsync(filters).Returns(_ads); | |||||
| AdsController adsController = new(_adService); | |||||
| var result = await adsController.GetFilteredAds(filters); | |||||
| (result as OkObjectResult).StatusCode.Should().Be(200); | |||||
| } | |||||
| [Fact] | |||||
| public async Task CreateAd_ShouldReturn201Created_WhenAdCreated() | |||||
| { | |||||
| var adCreateDto = new AdCreateDto | |||||
| { | |||||
| Title = "React Developer", | |||||
| MinimumExperience = 0, | |||||
| CreatedAt = DateTime.UtcNow, | |||||
| ExpiredAt = DateTime.UtcNow.AddDays(30), | |||||
| KeyResponsibilities = "KR|KR", | |||||
| Requirements = "R|R|R", | |||||
| Offer = "O|O" | |||||
| }; | |||||
| _adService.CreateAsync(adCreateDto); | |||||
| AdsController adsController = new(_adService); | |||||
| var result = await adsController.Create(adCreateDto); | |||||
| (result as StatusCodeResult).StatusCode.Should().Be(201); | |||||
| } | |||||
| [Fact] | |||||
| public async Task UpdateAd_ShouldReturn200OK_WhenAdUpdated() | |||||
| { | |||||
| var adUpdateDto = new AdUpdateDto | |||||
| { | |||||
| Title = "React Developer", | |||||
| MinimumExperience = 0, | |||||
| CreatedAt = DateTime.UtcNow, | |||||
| ExpiredAt = DateTime.UtcNow.AddDays(30), | |||||
| KeyResponsibilities = "KR|KR", | |||||
| Requirements = "R|R|R", | |||||
| Offer = "O|O" | |||||
| }; | |||||
| _adService.UpdateAsync(1, adUpdateDto); | |||||
| AdsController adsController = new(_adService); | |||||
| var result = await adsController.Update(adUpdateDto, 1); | |||||
| (result as StatusCodeResult).StatusCode.Should().Be(200); | |||||
| } | |||||
| [Fact] | |||||
| public async Task UpdateAd_ShouldThrowEntityNotFoundException_WhenAdDontExist() | |||||
| { | |||||
| var adUpdateDto = new AdUpdateDto | |||||
| { | |||||
| Title = "React Developer", | |||||
| MinimumExperience = 0, | |||||
| CreatedAt = DateTime.UtcNow, | |||||
| ExpiredAt = DateTime.UtcNow.AddDays(30), | |||||
| KeyResponsibilities = "KR|KR", | |||||
| Requirements = "R|R|R", | |||||
| Offer = "O|O" | |||||
| }; | |||||
| _adService.When(x => x.UpdateAsync(Arg.Any<int>(), adUpdateDto)).Do(x => { throw new EntityNotFoundException(); }); | |||||
| AdsController adsController = new(_adService); | |||||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => adsController.Update(adUpdateDto, 1000)); | |||||
| } | |||||
| [Fact] | |||||
| public async Task DeleteAd_ShouldReturn204NoContent_WhenAdDeleted() | |||||
| { | |||||
| _adService.DeleteAsync(1); | |||||
| AdsController adsController = new(_adService); | |||||
| var result = await adsController.DeleteAd(1); | |||||
| (result as StatusCodeResult).StatusCode.Should().Be(204); | |||||
| } | |||||
| [Fact] | |||||
| public async Task DeleteAd_ShouldThrowEntityNotFoundException_WhenAdDontExist() | |||||
| { | |||||
| _adService.When(x => x.DeleteAsync(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); }); | |||||
| AdsController adsController = new(_adService); | |||||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => adsController.DeleteAd(1000)); | |||||
| } | |||||
| } | |||||
| } |
| using AutoMapper; | |||||
| using Diligent.WebAPI.Business.MappingProfiles; | |||||
| using Diligent.WebAPI.Business.Services; | |||||
| using Diligent.WebAPI.Contracts.DTOs.Ad; | |||||
| 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 AdServiceTests | |||||
| { | |||||
| private readonly IMapper _mapper; | |||||
| private readonly List<Ad> _ads = new List<Ad>(); | |||||
| private readonly Ad _ad; | |||||
| private ITechnologyService _technologyService = Substitute.For<ITechnologyService>(); | |||||
| private readonly List<Technology> _technologies = new List<Technology>(); | |||||
| public AdServiceTests() | |||||
| { | |||||
| var configuration = new MapperConfiguration(cfg => cfg.AddProfiles( | |||||
| new List<Profile> | |||||
| { | |||||
| new AdMappingProfile(), | |||||
| new TechnologyMappingProfile() | |||||
| })); | |||||
| _mapper = new Mapper(configuration); | |||||
| _ad = new Ad | |||||
| { | |||||
| Id = 1, | |||||
| Title = "React Developer", | |||||
| MinimumExperience = 0, | |||||
| CreatedAt = DateTime.UtcNow, | |||||
| ExpiredAt = DateTime.UtcNow.AddDays(30), | |||||
| KeyResponsibilities = "KR|KR", | |||||
| Requirements = "R|R|R", | |||||
| Offer = "O|O", | |||||
| WorkHour = WorkHours.FullTime, | |||||
| EmploymentType = EmploymentTypes.Intership, | |||||
| Technologies = new List<Technology> | |||||
| { | |||||
| new Technology { TechnologyId = 1, Name = "React", TechnologyType = TechnologyTypes.Backend} | |||||
| } | |||||
| }; | |||||
| _ads.Add(_ad); | |||||
| _ads.Add(new Ad | |||||
| { | |||||
| Id = 2, | |||||
| Title = ".NET Developer", | |||||
| MinimumExperience = 0, | |||||
| CreatedAt = DateTime.UtcNow.AddDays(-2), | |||||
| ExpiredAt = DateTime.UtcNow.AddDays(-1), | |||||
| KeyResponsibilities = "KR|KR", | |||||
| Requirements = "R|R|R", | |||||
| Offer = "O|O", | |||||
| WorkHour = WorkHours.FullTime, | |||||
| EmploymentType = EmploymentTypes.Intership, | |||||
| Technologies = new List<Technology> | |||||
| { | |||||
| new Technology { TechnologyId = 2, Name = ".NET", TechnologyType = TechnologyTypes.Frontend} | |||||
| } | |||||
| }); | |||||
| _technologies.Add(new Technology | |||||
| { | |||||
| TechnologyId = 1, | |||||
| Name = ".NET" | |||||
| }); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetAll_ShouldReturnListOfAds_WhenCalled() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| var result = await adService.GetAllAsync(); | |||||
| //result.Should().BeEquivalentTo(_mapper.Map<List<AdResponseDto>>(_ads)); | |||||
| Assert.Equal(result.Count, 1); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetById_ShouldReturnAd_WhenAdExists() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| var result = await adService.GetByIdAsync(1); | |||||
| result.Should().BeEquivalentTo(_mapper.Map<AdResponseDto>(_ad)); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetById_ShouldThrowEntityNotFoundException_WhenAdDontExists() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await adService.GetByIdAsync(1000)); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetAdDetailsById_ShouldReturnAd_WhenAdExists() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| var result = await adService.GetAdDetailsByIdAsync(1); | |||||
| result.Should().BeEquivalentTo(_mapper.Map<AdDetailsResponseDto>(_ad)); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetAdDetailsById_ShouldThrowEntityNotFoundException_WhenAdDontExists() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await adService.GetAdDetailsByIdAsync(1000)); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetArchiveAds_ShouldReturnListOfAds_WhenCalled() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| var result = await adService.GetArchiveAds(); | |||||
| //result.Should().BeEquivalentTo(_mapper.Map<List<AdResponseDto>>(_ads)); | |||||
| Assert.Equal(result.Count, 1); | |||||
| } | |||||
| [Fact] | |||||
| public async Task GetFilteredAds_ShouldReturnListOfAds_WhenCalled() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| var result = await adService.GetFilteredAdsAsync(new AdFilterDto | |||||
| { | |||||
| MinExperience = 0, | |||||
| MaxExperience = 10, | |||||
| EmploymentType = "Intership", | |||||
| WorkHour = "FullTime", | |||||
| Technologies = new string[] | |||||
| { | |||||
| ".NET" | |||||
| } | |||||
| }); | |||||
| Assert.Equal(result.Count, 1); | |||||
| } | |||||
| [Fact] | |||||
| public async Task CreateAd_ShouldAddAdIntoDatabase_WhenCalled() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| _technologyService.GetEntityByIdAsync(Arg.Any<int>()).Returns(new Technology | |||||
| { | |||||
| TechnologyId = 3, | |||||
| Name = "Vue" | |||||
| }); | |||||
| AdCreateDto adCreateDto = new AdCreateDto | |||||
| { | |||||
| Title = "Vue Developer", | |||||
| MinimumExperience = 0, | |||||
| CreatedAt = DateTime.UtcNow, | |||||
| ExpiredAt = DateTime.UtcNow.AddDays(30), | |||||
| KeyResponsibilities = "KR|KR", | |||||
| Requirements = "R|R|R", | |||||
| Offer = "O|O", | |||||
| WorkHour = "FullTime", | |||||
| EmploymentType = "Intership", | |||||
| TechnologiesIds = new List<int> { 3 } | |||||
| }; | |||||
| await adService.CreateAsync(adCreateDto); | |||||
| var ads = await adService.GetAllAsync(); | |||||
| Assert.Equal(2, ads.Count); | |||||
| } | |||||
| [Fact] | |||||
| public async Task UpdateAd_ShouldUpdateAd_WhenAdExists() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| var updateForAd = new AdUpdateDto | |||||
| { | |||||
| Title = "Vue Developer", | |||||
| MinimumExperience = 0, | |||||
| CreatedAt = DateTime.UtcNow, | |||||
| ExpiredAt = DateTime.UtcNow.AddDays(30), | |||||
| KeyResponsibilities = "KR|KR", | |||||
| Requirements = "R|R|R", | |||||
| Offer = "O|O", | |||||
| WorkHour = "FullTime", | |||||
| EmploymentType = "Intership", | |||||
| }; | |||||
| await adService.UpdateAsync(1, updateForAd); | |||||
| var ads = await adService.GetAllAsync(); | |||||
| Assert.Equal(ads[0].Title, "Vue Developer"); | |||||
| } | |||||
| [Fact] | |||||
| public async Task UpdateAd_ShouldThrowEntityNotFoundException_WhenAdDontExists() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await adService.UpdateAsync(1000, new AdUpdateDto | |||||
| { | |||||
| Title = "Vue Developer", | |||||
| MinimumExperience = 0, | |||||
| CreatedAt = DateTime.UtcNow, | |||||
| ExpiredAt = DateTime.UtcNow.AddDays(30), | |||||
| KeyResponsibilities = "KR|KR", | |||||
| Requirements = "R|R|R", | |||||
| Offer = "O|O", | |||||
| WorkHour = "FullTime", | |||||
| EmploymentType = "Intership", | |||||
| })); | |||||
| } | |||||
| [Fact] | |||||
| public async Task DeleteAd_ShouldDeleteAdFromDatabase_WhenAdExists() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| await adService.DeleteAsync(1); | |||||
| var ads = await adService.GetAllAsync(); | |||||
| Assert.Equal(0, ads.Count); | |||||
| } | |||||
| [Fact] | |||||
| public async Task DeleteAd_ShouldThrowEntityNotFoundException_WhenAdDontExists() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService); | |||||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await adService.DeleteAsync(1000)); | |||||
| } | |||||
| } | |||||
| } |