public async Task SyncNewsAsync() { var newsResponse = await _sportsRuApiService.GetNewsAsync(NewsType.HomePage, NewsPriority.Main, NewsContentOrigin.Mixed, 100).ConfigureAwait(false); var hotContent = await _sportsRuApiService.GetHotContentAsync().ConfigureAwait(false); IEnumerable <int> hotNewsIds = null; if (hotContent.IsSuccess) { hotNewsIds = hotContent.Content.News; } if (newsResponse.IsSuccess) { foreach (var newsArticle in newsResponse.Content) { if (newsArticle.BodyIsEmpty || newsArticle.ContentOption?.Name == "special" || !SportsRuHelper.IsInternalUrl(newsArticle.DesktopUrl)) //usually this is not a news article but some promotion { continue; } string idString = newsArticle.Id.ToString(CultureInfo.InvariantCulture); var existingArticle = _sportsContext.NewsArticles.FirstOrDefault(x => x.ExternalId == idString); if (existingArticle == null) { var newArticle = new NewsArticle() { ExternalId = idString }; Map(newsArticle, newArticle, hotNewsIds); _sportsContext.NewsArticles.Add(newArticle); } else { Map(newsArticle, existingArticle, hotNewsIds); _sportsContext.NewsArticles.Update(existingArticle); } } _sportsContext.SaveChanges(); } }
public void InternalUrl_Invalid() { var internalUrl = new Uri("https://www.google.com/"); Assert.False(SportsRuHelper.IsInternalUrl(internalUrl)); }
public void InternalUrl_Valid() { var internalUrl = new Uri("https://www.sports.ru/football/1085421239.html"); Assert.True(SportsRuHelper.IsInternalUrl(internalUrl)); }