public void Given_A_CardTipSection_And_TipRelatedCardListTableWith_Should_Invoke_ExtractCardsFromTable(string url)
        {
            // Arrange
            var fixture = new Fixture {
                RepeatCount = 10
            };

            _tipRelatedCardList.ExtractCardsFromTable(Arg.Any <HtmlNode>()).Returns(fixture.Create <List <string> >());
            var htmlDocument   = new HtmlWeb().Load(url);
            var htmlTable      = new TipRelatedHtmlDocument(_config).GetTable(htmlDocument);
            var cardTipSection = new CardTipSection();

            // Act
            _sut.GetTipRelatedCards(cardTipSection, null, htmlTable);

            // Assert
            _tipRelatedCardList.Received(1).ExtractCardsFromTable(Arg.Any <HtmlNode>());
        }
        public void Given_A_CardTipSection_And_TipRelatedCardListTableWith_Should_Invoke_CardsByUrl(string url)
        {
            // Arrange
            var fixture = new Fixture {
                RepeatCount = 10
            };

            _semanticSearch.CardsByUrl(Arg.Any <string>()).Returns(fixture.Create <List <SemanticCard> >());
            var htmlDocument   = new HtmlWeb().Load(url);
            var htmlTable      = new TipRelatedHtmlDocument(_config).GetTable(htmlDocument);
            var cardTipSection = new CardTipSection();

            // Act
            _sut.GetTipRelatedCards(cardTipSection, url, htmlTable);

            // Assert
            _semanticSearch.Received(1).CardsByUrl(Arg.Any <string>());
        }
Exemplo n.º 3
0
        public void GetTipRelatedCards(CardTipSection section, string tipRelatedCardListUrl, HtmlNode tipRelatedCardListTable)
        {
            if (section == null)
            {
                throw new ArgumentNullException(nameof(section));
            }

            if (!string.IsNullOrEmpty(tipRelatedCardListUrl))
            {
                var cardsFromUrl = _semanticSearch.CardsByUrl(tipRelatedCardListUrl);
                section.Tips.AddRange(cardsFromUrl.Select(c => c.Name));
            }
            else if (tipRelatedCardListTable != null)
            {
                var cardsFromTable = _tipRelatedCardList.ExtractCardsFromTable(tipRelatedCardListTable);
                section.Tips.AddRange(cardsFromTable);
            }
        }
Exemplo n.º 4
0
        public void GetTipRelatedCards(CardTipSection section, UnexpandedArticle item)
        {
            if (section == null)
            {
                throw new ArgumentNullException(nameof(section));
            }

            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var tipWebPage = new HtmlWeb().Load(_config.WikiaDomainUrl + item.Url);

            //Get tip related card list url
            var cardListUrl = _tipRelatedHtmlDocument.GetUrl(tipWebPage);

            //get tips related card list table
            var cardListTable = _tipRelatedHtmlDocument.GetTable(tipWebPage);

            GetTipRelatedCards(section, cardListUrl, cardListTable);
        }
Exemplo n.º 5
0
        public async Task <ArticleTaskResult> ProcessItem(UnexpandedArticle item)
        {
            var response = new ArticleTaskResult {
                Article = item
            };

            var card = await _cardService.CardByName(item.Title);

            if (card != null)
            {
                var tipSections = new List <CardTipSection>();

                var articleCardTips = await _wikiArticle.Simple(item.Id);

                foreach (var cardTipSection in articleCardTips.Sections)
                {
                    var tipSection = new CardTipSection
                    {
                        Name = cardTipSection.Title,
                        Tips = SectionHelper.GetSectionContentList(cardTipSection)
                    };


                    if (cardTipSection.Title.Equals("List", StringComparison.OrdinalIgnoreCase) ||
                        cardTipSection.Title.Equals("Lists", StringComparison.OrdinalIgnoreCase))
                    {
                        tipSection.Name = tipSection.Tips.First();
                        tipSection.Tips.Clear();
                        _tipRelatedWebPage.GetTipRelatedCards(tipSection, item);
                    }

                    tipSections.Add(tipSection);
                }

                await _cardTipService.Update(card.Id, tipSections);
            }

            return(response);
        }