| await Assert.ThrowsAsync<EntityNotFoundException>(() => adsController.GetById(1000)); | await Assert.ThrowsAsync<EntityNotFoundException>(() => adsController.GetById(1000)); | ||||
| } | } | ||||
| [Fact] | |||||
| public async Task ArchiveActiveAd_ShouldReturn200OK_WhenAdExists() | |||||
| { | |||||
| _adService.ArchiveAdAsync(Arg.Any<int>()).Returns(Task.FromResult(1)); | |||||
| AdsController adsController = new(_adService); | |||||
| var result = await adsController.ArchiveActiveAd(1); | |||||
| var res = result as StatusCodeResult; | |||||
| Assert.Equal(res.StatusCode, 200); | |||||
| } | |||||
| [Fact] | |||||
| public async Task ArchiveActiveAd_ShouldThrowEntityNotFoundException_WhenAdDontExist() | |||||
| { | |||||
| _adService.When(x => x.ArchiveAdAsync(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); }); | |||||
| AdsController adsController = new(_adService); | |||||
| await Assert.ThrowsAsync<EntityNotFoundException>(() => adsController.ArchiveActiveAd(10)); | |||||
| } | |||||
| [Fact] | [Fact] | ||||
| public async Task GetAdDetailsById_ShouldReturn200OK_WhenAdExists() | public async Task GetAdDetailsById_ShouldReturn200OK_WhenAdExists() | ||||
| { | { |
| Assert.Equal(result.Count, 1); | Assert.Equal(result.Count, 1); | ||||
| } | } | ||||
| [Fact] | |||||
| public async Task GetAllWithCountAsync_ShouldReturnListOfAds_WhenCalled() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService, _logger); | |||||
| var result = await adService.GetAllWithCountAsync(); | |||||
| Assert.Equal(result.Count, 1); | |||||
| } | |||||
| [Fact] | |||||
| public async Task ArchiveAd_ShouldThrowEntityNotFoundException_WhenAdDontExist() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService, _logger); | |||||
| await Assert.ThrowsAsync<EntityNotFoundException>(async () => await adService.ArchiveAdAsync(99)); | |||||
| } | |||||
| [Fact] | |||||
| public async Task ArchiveAd_ShouldChangeExpiryDate_WhenAdExist() | |||||
| { | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService, _logger); | |||||
| await adService.ArchiveAdAsync(2); | |||||
| Assert.Equal(_ads[1].ExpiredAt.Date, DateTime.Now.Date); | |||||
| } | |||||
| [Fact] | |||||
| public async Task ImportAd_ShouldAddAdInDatabase_WhenCalled() | |||||
| { | |||||
| AdCreateDto adCreateDto = new AdCreateDto | |||||
| { | |||||
| Title = "Vue Developer", | |||||
| MinimumExperience = 0, | |||||
| CreatedAt = DateTime.Now, | |||||
| ExpiredAt = DateTime.Now.AddDays(30), | |||||
| KeyResponsibilities = "KR|KR", | |||||
| Requirements = "R|R|R", | |||||
| Offer = "O|O", | |||||
| WorkHour = "FullTime", | |||||
| EmploymentType = "Intership", | |||||
| TechnologiesIds = new List<int> { 3 } | |||||
| }; | |||||
| var databaseContext = await Helpers<Ad>.GetDatabaseContext(_ads); | |||||
| AdService adService = new(databaseContext, _mapper, _technologyService, _logger); | |||||
| var ad = await adService.ImportAsync(adCreateDto); | |||||
| var ads = await adService.GetAllAsync(); | |||||
| Assert.Equal(ads.Count, 2); | |||||
| } | |||||
| [Fact] | [Fact] | ||||
| public async Task CreateAd_ShouldAddAdIntoDatabase_WhenCalled() | public async Task CreateAd_ShouldAddAdIntoDatabase_WhenCalled() | ||||
| { | { |
| }, 1)); | }, 1)); | ||||
| } | } | ||||
| //[Fact] | |||||
| //public async Task UpdatePattern_ShouldUpdatePattern_WhenConditionsAreFullfiled() | |||||
| //{ | |||||
| // _selectionLevelService.GetByIdEntity(Arg.Any<int>()).Returns(new SelectionLevel | |||||
| // { | |||||
| // Id = 1122, | |||||
| // Name = "Test 1", | |||||
| // SelectionProcesses = new List<SelectionProcess>() | |||||
| // }); | |||||
| // var databaseContext = await Helpers<Pattern>.GetDatabaseContext(_patterns); | |||||
| // PatternService patternService = new(databaseContext, _mapper, _selectionLevelService, _logger, _emailService, _selectionProcessService); | |||||
| // var updatePatternDto = new PatternUpdateDto | |||||
| // { | |||||
| // CreatedAt = DateTime.Now, | |||||
| // Message = "Message", | |||||
| // SelectionLevelId = 1122, | |||||
| // Title = "Zakazan termin" | |||||
| // }; | |||||
| // await patternService.UpdateAsync(updatePatternDto, 1); | |||||
| // var result = await patternService.GetAllAsync(); | |||||
| // Assert.Equal(1, result.Count); | |||||
| //} | |||||
| [Fact] | |||||
| public async Task UpdatePattern_ShouldUpdatePattern_WhenConditionsAreFullfiled() | |||||
| { | |||||
| _selectionLevelService.GetByIdEntity(Arg.Any<int>()).Returns(new SelectionLevel | |||||
| { | |||||
| Id = 1, | |||||
| Name = "Test 1", | |||||
| SelectionProcesses = new List<SelectionProcess>() | |||||
| }); | |||||
| var databaseContext = await Helpers<Pattern>.GetDatabaseContext(_patterns); | |||||
| PatternService patternService = new(databaseContext, _mapper, _selectionLevelService, _logger, _emailService, _selectionProcessService); | |||||
| var updatePatternDto = new PatternUpdateDto | |||||
| { | |||||
| CreatedAt = DateTime.Now, | |||||
| Message = "Message", | |||||
| SelectionLevelId = 1122, | |||||
| Title = "Zakazan termin" | |||||
| }; | |||||
| await patternService.UpdateAsync(updatePatternDto, 1); | |||||
| var result = await patternService.GetAllAsync(); | |||||
| Assert.Equal(1, result.Count); | |||||
| } | |||||
| [Fact] | [Fact] | ||||
| public async Task DeletePattern_ShouldThrowEntityNotFoundException_WhenPatternDoesNotExist() | public async Task DeletePattern_ShouldThrowEntityNotFoundException_WhenPatternDoesNotExist() |