public async Task Create_Returns_ValidViewResult_WhenModelStateInvalid() { // Arrange JobPosting tempjob = new JobPosting { Title = "Full Stack Developer", Company = "Walmart", Description = "Yolo Lyfe", NumberOfViews = 1 }; tempjob = CreateJobPostingAsync(tempjob); Mock <IJobPostingRepository> mockRepoJob = new Mock <IJobPostingRepository>(); mockRepoJob.Setup(repo => repo.Create(tempjob)) .ReturnsAsync(tempjob); mockRepoJob.Setup(repo => repo.Put(tempjob.Id, tempjob)) .ReturnsAsync(tempjob); KeyPhrasesWrapperDTO temKeyPharse = GetNLTKKeyPhrases(tempjob.Description); tempjob.KeyPhrases = new List <KeyPhrase>(); foreach (KeyPhraseDTO item in temKeyPharse.rank_list) { tempjob.KeyPhrases.Add(new KeyPhrase { Affinty = item.Affinty, Text = item.Text }); } SummaryDTO tempValDTO = GetNLTKSummary(tempjob.Description); tempjob.Summary = tempValDTO.SummaryText; Mock <IKeyPharseRepository> mockRepoKeyPharse = new Mock <IKeyPharseRepository>(); Mock <INLTKService> mockNLTKService = new Mock <INLTKService>(); mockNLTKService.Setup(service => service.GetNLTKKeyPhrases(tempjob.Description)) .ReturnsAsync(temKeyPharse); mockNLTKService.Setup(service => service.GetNLTKSummary(tempjob.Description)) .ReturnsAsync(tempValDTO); JobPostingsController controller = new JobPostingsController(mockRepoJob.Object, mockNLTKService.Object, mockRepoKeyPharse.Object); controller.ModelState.AddModelError("Salary", "no Salary found"); // Act IActionResult result = await controller.Create(tempjob); // Assert ViewResult viewResult = Assert.IsType <ViewResult>(result); JobPosting model = Assert.IsAssignableFrom <JobPosting>( viewResult.ViewData.Model); }
public async Task Create_Returns_RedirectToActionResult_WhenModelStateValid() { // Arrange JobPosting tempjob = new JobPosting { Title = "Full Stack Developer", Company = "Walmart", Description = "Yolo Lyfe", NumberOfViews = 1 }; tempjob = CreateJobPostingAsync(tempjob); Mock <IJobPostingRepository> mockRepoJob = new Mock <IJobPostingRepository>(); mockRepoJob.Setup(repo => repo.Create(tempjob)) .ReturnsAsync(tempjob); mockRepoJob.Setup(repo => repo.Put(tempjob.Id, tempjob)) .ReturnsAsync(tempjob); KeyPhrasesWrapperDTO temKeyPharse = GetNLTKKeyPhrases(tempjob.Description); tempjob.KeyPhrases = new List <KeyPhrase>(); foreach (KeyPhraseDTO item in temKeyPharse.rank_list) { tempjob.KeyPhrases.Add(new KeyPhrase { Affinty = item.Affinty, Text = item.Text }); } SummaryDTO tempValDTO = GetNLTKSummary(tempjob.Description); tempjob.Summary = tempValDTO.SummaryText; Mock <IKeyPharseRepository> mockRepoKeyPharse = new Mock <IKeyPharseRepository>(); Mock <INLTKService> mockNLTKService = new Mock <INLTKService>(); mockNLTKService.Setup(service => service.GetNLTKKeyPhrases(tempjob.Description)) .ReturnsAsync(temKeyPharse); mockNLTKService.Setup(service => service.GetNLTKSummary(tempjob.Description)) .ReturnsAsync(tempValDTO); JobPostingsController controller = new JobPostingsController(mockRepoJob.Object, mockNLTKService.Object, mockRepoKeyPharse.Object); // Act IActionResult result = await controller.Create(tempjob); // Assert RedirectToActionResult redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectToActionResult.ControllerName); Assert.Equal("Index", redirectToActionResult.ActionName); }
public async Task <SummaryDTO> GetSummaryForACertainInterval(int interval) { IQueryable <Income> tincomes; IQueryable <Expense> texpenses; IQueryable <Loan> tloans; IQueryable <Debt> tdebts; double inc = 0, exp = 0, ln = 0, dt = 0; SummaryDTO summaryDTO; DateTime current = DateTime.Now; tincomes = incomes.Where(e => (e.LastModificationTime.Value - current).TotalDays <= interval); texpenses = expenses.Where(e => (e.LastModificationTime.Value - current).TotalDays <= interval); tloans = loans.Where(e => (e.LastModificationTime.Value - current).TotalDays <= interval); tdebts = debts.Where(e => (e.LastModificationTime.Value - current).TotalDays <= interval); inc = tincomes.Sum(e => e.Amount); exp = texpenses.Sum(e => e.Amount); ln = tloans.Sum(e => e.Amount); dt = tdebts.Sum(e => e.Amount); summaryDTO = new SummaryDTO(); summaryDTO.Income = inc; summaryDTO.Expense = exp; summaryDTO.Loan = ln; summaryDTO.Debt = dt; summaryDTO.Balance = (inc - exp - dt); return(summaryDTO); }
public async Task FindBySessionIdAsync_given_existing_id_returns_dto() { var dto = new SummaryDTO(); var repository = new Mock <ISummaryRepository>(); repository.Setup(s => s.FindBySessionIdAsync(42)).ReturnsAsync(dto); var controller = new SummaryController(repository.Object); var get = await controller.FindBySessionIdAsync(42); Assert.Equal(dto, get.Value); }
public async Task <IActionResult> AddSum(SummaryDTO model) { var summary = new SummaryDTO() { Bilance = model.Bilance, FromDate = model.FromDate, ToDate = model.ToDate, UserId = model.UserId }; await _summaryDAL.AddSum(summary); return(Ok(summary)); }
public async Task RunAtTimeOf(DateTime now) { var config = _ctx.JobGettingConfig.FirstOrDefault(); if (config == null) { return; } _logger.LogInformation("SummaryGeneratorJob Starts... "); string connectionString = Secrets.GetDBConnectionString(_configuration); using (MySqlConnection connection = new MySqlConnection(connectionString)) { // Create the Command and Parameter objects. MySqlCommand command = new MySqlCommand(@" SELECT Id, Description FROM `jobtransparency`.`JobPostings` WHERE Description = '' ", connection); command.CommandTimeout = config.SQLCommandTimeOut; try { connection.Open(); var reader = await command.ExecuteReaderAsync(); while (reader.Read()) { var Id = (int)reader[0]; var Description = (string)reader[1]; Description = new string(Description.Where(c => !char.IsPunctuation(c)).ToArray()); SummaryDTO nltkSummary = await _nltkService.ExtractSummary(Description); var Job = await _jobPostingRepository.GetById(Id); Job.Summary = nltkSummary.SummaryText; await _jobPostingRepository.Put(Job.Id, Job); } reader.Close(); } catch (Exception ex) { _logger.LogInformation(ex, "SummaryGeneratorJob Ends... "); } } _logger.LogInformation("SummaryGeneratorJob Ends... "); }
public async Task <SummaryDTO> AddSum(SummaryDTO model) { using (_ctx) { var summary = new SummaryDTO() { UserId = model.UserId, FromDate = model.FromDate, ToDate = model.ToDate, Bilance = model.Bilance, }; _ctx.Summary.Add(summary); _ctx.SaveChanges(); return(summary); } }
public async Task NextItem_given_completed_session_returns_badrequest() { var cache = new MemoryCache(new MemoryCacheOptions()); var sessionRepo = new Mock <ISessionRepository>(); var summaryRepo = new Mock <ISummaryRepository>(); var token = CreateUserState(cache, 42, "ABC1234"); var mockSession = new SessionDTO { Items = new List <ItemDTO> { new ItemDTO { Rounds = new List <RoundDTO> { new RoundDTO(), new RoundDTO() } } } }; var mockSummary = new SummaryDTO { ItemEstimates = new List <ItemEstimateDTO> { new ItemEstimateDTO(), new ItemEstimateDTO() } }; sessionRepo.Setup(s => s.FindByKeyAsync(It.IsAny <string>())) .ReturnsAsync(mockSession); summaryRepo.Setup(s => s.BuildSummary(mockSession)). ReturnsAsync(mockSummary); var controller = new SessionController(sessionRepo.Object, cache, summaryRepo.Object); var result = await controller.NextItem(token, "ABC1234"); Assert.IsType <BadRequestResult>(result.Result); }
public async Task <IActionResult> GetSummary(string session) { SummaryDTO result = new SummaryDTO(); result.Vehicle = _entryService.GetVehicle(int.Parse(session)); result.DateTime = _entryService.GetDateTime(int.Parse(session)); List <string> services = new List <string>(); var data = _serviceRepository.Get(); var ids = _entryService.GetServiceNeeds(int.Parse(session)); foreach (var id in ids) { services.Add(data.Find(el => el.ServiceId == id).Name); } result.Services = services; return(Ok(result)); }
public SummaryController(ISummaryDAL summaryDAL, SummaryDTO summaryDTO) { _summaryDAL = summaryDAL; _summaryDTO = summaryDTO; }
public async Task RunAtTimeOfAsync(DateTime now) { var config = _ctx.JobGettingConfig.FirstOrDefault(); if (config == null) { return; } var tags = _ctx.PositionName.ToList(); foreach (var tag in tags) { HttpClient client = new HttpClient(); var stuff = await client.GetAsync($"https://remoteok.io/api?tags=" + tag.Name); if (stuff.IsSuccessStatusCode) { var contentString = await stuff.Content.ReadAsStringAsync(); try { var okRemoteData = OkRemoteData.FromJson(contentString); foreach (var okRemoteJob in okRemoteData) { if (string.IsNullOrEmpty(okRemoteJob.Position)) { continue; } if (!_ctx.JobPostings.Any(x => x.Title == okRemoteJob.Position && x.Description == okRemoteJob.Description)) { var Description = new string(okRemoteJob.Description.Where(c => !char.IsPunctuation(c)).ToArray()); SummaryDTO nltkSummary = await _nltkService.ExtractSummary(Description); KeyPhrasesWrapperDTO wrapper = await _nltkService.ExtractKeyPhrases(Description); var newJobPosting = new JobPosting() { Title = okRemoteJob.Position, Description = okRemoteJob.Description, URL = okRemoteJob.Url.OriginalString, Company = okRemoteJob.Company, Location = okRemoteJob.Location, PostDate = okRemoteJob.Date.ToString(), Salary = "", JobSource = "RemoteOk", CompanyLogoUrl = okRemoteJob.CompanyLogo, Summary = nltkSummary.SummaryText }; await _ctx.AddAsync(newJobPosting); await _ctx.SaveChangesAsync(); _logger.LogInformation("List<KeyPhrase> ListKeyPhrase"); foreach (KeyPhraseDTO KeyPhrase in wrapper.rank_list) { if (KeyPhrase.Affinty > config.MinAffintyScore) { _ctx.KeyPhrase.Add(new KeyPhrase { Affinty = KeyPhrase.Affinty, Text = KeyPhrase.Text, JobPostingId = newJobPosting.Id }); } _logger.LogInformation($"item.Affinty {KeyPhrase.Affinty}"); _logger.LogInformation($"item.Text {KeyPhrase.Text}"); } await _ctx.SaveChangesAsync(); foreach (var item in okRemoteJob.Tags) { if (_ctx.Tags.Any(x => x.Text.Trim() == item.Trim())) { var tagFromDB = _ctx.Tags.Where(x => x.Text.Trim() == item.Trim()).FirstOrDefault(); newJobPosting.Tags.Add(tagFromDB); } else { newJobPosting.Tags.Add(new Models.Entity.Tag() { Text = item.Trim() }); } } await _ctx.SaveChangesAsync(); } } } catch (Exception ex) { _logger.LogError(ex, "Failed to deserialize"); } } Thread.Sleep(config.OkRemoteTimeBetweenTags); } }
public async Task RunAtTimeOfAsync(DateTime now) { var config = _ctx.JobGettingConfig.FirstOrDefault(); if (config == null) { return; } HttpClient client = new HttpClient(); var httpResult = await client.GetAsync("https://remotive.io/api/remote-jobs"); if (httpResult.IsSuccessStatusCode) { var contentString = await httpResult.Content.ReadAsStringAsync(); try { var remotiveIO = RemotiveIoData.FromJson(contentString); foreach (var okRemoteJob in remotiveIO.Jobs) { if (string.IsNullOrEmpty(okRemoteJob.Title)) { continue; } if (!_ctx.JobPostings.Any(x => x.Title == okRemoteJob.Title && x.Description == okRemoteJob.Description)) { var Description = new string(okRemoteJob.Description.Where(c => !char.IsPunctuation(c)).ToArray()); SummaryDTO nltkSummary = await _nltkService.ExtractSummary(Description); KeyPhrasesWrapperDTO wrapper = await _nltkService.ExtractKeyPhrases(Description); var newJobPosting = new JobPosting() { Title = okRemoteJob.Title, Description = okRemoteJob.Description, URL = okRemoteJob.Url.OriginalString, Company = okRemoteJob.CompanyName, Location = okRemoteJob.CandidateRequiredLocation, PostDate = okRemoteJob.PublicationDate.ToString(), Salary = okRemoteJob.Salary, JobSource = "RemotiveIo", CompanyLogoUrl = okRemoteJob.CompanyLogoUrl == null ? "" : okRemoteJob.CompanyLogoUrl.OriginalString, Summary = nltkSummary.SummaryText }; await _ctx.AddAsync(newJobPosting); await _ctx.SaveChangesAsync(); _logger.LogInformation("List<KeyPhrase> ListKeyPhrase"); foreach (KeyPhraseDTO KeyPhrase in wrapper.rank_list) { if (KeyPhrase.Affinty > config.MinAffintyScore) { _ctx.KeyPhrase.Add(new KeyPhrase { Affinty = KeyPhrase.Affinty, Text = KeyPhrase.Text, JobPostingId = newJobPosting.Id }); } _logger.LogInformation($"item.Affinty {KeyPhrase.Affinty}"); _logger.LogInformation($"item.Text {KeyPhrase.Text}"); } await _ctx.SaveChangesAsync(); if (_ctx.Tags.Any(x => x.Text.Trim() == okRemoteJob.Category)) { var tagFromDb = _ctx.Tags .FirstOrDefault(x => x.Text.Trim() == okRemoteJob.Category.Trim()); newJobPosting.Tags.Add(tagFromDb); } else { newJobPosting.Tags.Add(new Models.Entity.Tag() { Text = okRemoteJob.Category.Trim() }); } await _ctx.SaveChangesAsync(); } } } catch (Exception ex) { _logger.Log(LogLevel.Error, "Error Occured int RemotiveIoDataJob", ex); } } else { _logger.Log(LogLevel.Error, "httpResult.IsSuccessStatusCode was false"); } }