Beispiel #1
0
        public async void should_add_only_new_articles()
        {
            int scrappedArticlesCount = 5;
            int articlesInDbCount     = 2;

            var scrappedArticles = new ArticleBuilder().Build(scrappedArticlesCount);
            ArticlesResponseViewModel scrappedArticlesResponse = new()
            {
                Articles = scrappedArticles
            };

            List <ArticleDb> articlesInDb = scrappedArticles.Take(articlesInDbCount).ToList().Map();

            List <Article>  articlesToAdd    = null;
            Action <object> mapArticlesToAdd = (list) => { articlesToAdd = list as List <Article>; };

            List <Article> expectedResult = scrappedArticles.TakeLast(3).ToList();

            _pagesScrapperService.Setup(n => n.ScrapAll()).ReturnsAsync(scrappedArticlesResponse);
            _articlesRepository.Setup(n => n.Get(null, null, "")).Returns(articlesInDb);
            _mapper.Setup(n => n.Map <List <ArticleDb> >(It.IsAny <List <Article> >())).Callback(mapArticlesToAdd);

            await _sut.Scrap();

            articlesToAdd.Should().BeEquivalentTo(expectedResult);
        }