public async Task GetHotContent()
        {
            var hotContentResponse = await _sportsRuApiService.GetHotContentAsync().ConfigureAwait(false);

            Assert.True(hotContentResponse.IsSuccess, hotContentResponse.ErrorMessage);
            Assert.NotNull(hotContentResponse.Content.News);
            Assert.NotEmpty(hotContentResponse.Content.News);
            WritePrettyJson(hotContentResponse.Content);
        }
Пример #2
0
        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();
            }
        }