public void FillSingleDocumentWithSubContent_WhenLinkFromMainDocumentIsInvalid_ThrowFileNotFoundException() { RssDocumentSingle testDocument = new RssDocumentSingle(); testDocument.RssDocumentContent = new List <RssDocumentItem>(); testDocument.Link = "InvalidLink"; Assert.That(() => _downloader.FillSingleDocumentWithSubContent(testDocument), Throws.TypeOf <FileNotFoundException>()); }
public void FillSingleDocumentWithSubContent_WhenParameterIsNotNull_FillMainDocumentWithSubContent() { RssDocumentSingle testDocument = new RssDocumentSingle(); testDocument.RssDocumentContent = new List <RssDocumentItem>(); testDocument.Link = "https://www.rmf24.pl/tylko-w-rmf24/feed"; _downloader.FillSingleDocumentWithSubContent(testDocument); var result = testDocument.RssDocumentContent.Count; Assert.That(result, Is.Not.Zero); }
private bool CheckIfNewConteIsAvailable(RssDocumentSingle rssDocument, string date) { bool result = false; if (!string.IsNullOrWhiteSpace(date)) { var checkDate = Convert.ToDateTime(date); if (rssDocument.LastFetched < checkDate) { return(true); } } return(result); }
public void AddNewContent(List <RssDocumentSingle> documentsWithNewContent) { var allDocuments = _rssDocumentCollection.AsQueryable().ToList(); foreach (var document in documentsWithNewContent) { var filter = $"{document.Id}"; RssDocumentSingle singleDocument = null; foreach (var item in document.RssDocumentContent) { singleDocument = _rssDocumentCollection.AsQueryable().Where(x => x.Id == document.Id)?.FirstOrDefault(); singleDocument.LastFetched = DateTime.UtcNow.AddHours(1); singleDocument.RssDocumentContent.Add(item); } if (singleDocument != null) { _rssDocumentCollection.ReplaceOne(x => x.Id == document.Id, singleDocument); } } }
public List <RssDocumentSingle> GetAllDocumentsWithoutSubContent() { List <RssDocumentSingle> allRssDocumentsWithoutSubContent = new List <RssDocumentSingle>(); Parallel.ForEach(_linksWithTitles, (link) => { var rssDocumentFromWebSite = XElement.Load(link.Key); RssDocumentSingle newWebSite = new RssDocumentSingle() { Title = link.Value, Link = link.Key, Flag = link.Key.Contains("podcast") ? "Podcast" : "Text", Description = rssDocumentFromWebSite.Descendants("description").FirstOrDefault()?.Value, Image = rssDocumentFromWebSite.Descendants("image").Descendants("url").FirstOrDefault()?.Value, LastUpdate = rssDocumentFromWebSite.Descendants("lastBuildDate").FirstOrDefault()?.Value, LastFetched = DateTime.UtcNow.AddHours(1), RssDocumentContent = new List <RssDocumentItem>() }; allRssDocumentsWithoutSubContent.Add(newWebSite); }); return(allRssDocumentsWithoutSubContent); }
public void FillSingleDocumentWithSubContent(RssDocumentSingle mainContent) { List <RssDocumentItem> subContentOfSingleRssDocument = new List <RssDocumentItem>(); var itemsInsideMainRssDocument = XElement.Load(mainContent.Link) .Descendants("item").ToList(); foreach (var item in itemsInsideMainRssDocument) { var rssDocumentContent = new RssDocumentItem() { Guid = item.Descendants("guid").FirstOrDefault()?.Value, Title = item.Descendants("title").FirstOrDefault()?.Value, Description = item.Descendants("description").FirstOrDefault()?.Value, Image = item.Descendants("enclosure").Attributes("url").FirstOrDefault()?.Value, Links = item.Descendants("link").FirstOrDefault()?.Value, DateOfPublication = item.Descendants("pubDate").FirstOrDefault()?.Value, Category = item.Descendants("category").FirstOrDefault()?.Value, }; subContentOfSingleRssDocument.Add(rssDocumentContent); } mainContent.RssDocumentContent = subContentOfSingleRssDocument; }
public void SaveOneRssDocumentToDatabase(RssDocumentSingle rssDocument) { _rssDocumentCollection.InsertOne(rssDocument); }
public void FillSingleDocumentWithSubContent_WhenParameterIsNull_ThrowNullReferenceException() { RssDocumentSingle testDocument = null; Assert.That(() => _downloader.FillSingleDocumentWithSubContent(testDocument), Throws.Exception.TypeOf <NullReferenceException>()); }