public void Given_A_CardTipSection_And_TipRelatedCardListTableWith_Should_Not_Invoke_ExtractCardsFromTable(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
            _tipRelatedCardList.DidNotReceive().ExtractCardsFromTable(Arg.Any <HtmlNode>());
        }
Esempio n. 2
0
        public void Given_A_Valid_Url_And_ITargetBlock_Should_Execute_CardsByUrl()
        {
            // Arrange
            var url = "https://www.google.co.uk/";

            _semanticSearch.CardsByUrl(Arg.Any <string>()).Returns(new List <SemanticCard>());

            // Act
            _sut.Producer(url, new BufferBlock <SemanticCard[]>());

            // Assert
            _semanticSearch.Received(1).CardsByUrl(Arg.Any <string>());
        }
        public void Producer(string url, ITargetBlock <SemanticCard[]> targetBlock)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentException(nameof(url));
            }

            if (targetBlock == null)
            {
                throw new ArgumentException(nameof(targetBlock));
            }

            var cards = _semanticSearch.CardsByUrl(url);

            targetBlock.Post(cards.ToArray());
            targetBlock.Complete();
        }
        public void GetTipRelatedCards(CardSection section, string tipRelatedCardListUrl, HtmlNode tipRelatedCardListTable)
        {
            if (section == null)
            {
                throw new ArgumentNullException(nameof(section));
            }

            if (!string.IsNullOrEmpty(tipRelatedCardListUrl))
            {
                var cardsFromUrl = _semanticSearch.CardsByUrl(tipRelatedCardListUrl);
                section.ContentList.AddRange(cardsFromUrl.Select(c => c.Name));
            }
            else if (tipRelatedCardListTable != null)
            {
                var cardsFromTable = _tipRelatedCardList.ExtractCardsFromTable(tipRelatedCardListTable);
                section.ContentList.AddRange(cardsFromTable);
            }
        }