public async void should_add_scrapped_articles_into_db() { var scrappedArticles = new ArticleBuilder().Build(10); ArticlesResponseViewModel scrappedArticlesResponse = new() { Articles = scrappedArticles }; List <ArticleDb> articleInDb = new(); List <ArticleDb> insertedArticles = null; Action <List <ArticleDb> > insertRange = (list) => { insertedArticles = list; }; List <ArticleDb> expectedResult = scrappedArticles.Map(); _pagesScrapperService.Setup(n => n.ScrapAll()).ReturnsAsync(scrappedArticlesResponse); _articlesRepository.Setup(n => n.Get(null, null, "")).Returns(articleInDb); _articlesRepository.Setup(n => n.InsertRange(It.IsAny <List <ArticleDb> >())).Callback(insertRange); _mapper.Setup(n => n.Map <List <ArticleDb> >(It.IsAny <List <Article> >())).Returns(scrappedArticles.Map()); await _sut.Scrap(); insertedArticles.Should().BeEquivalentTo(expectedResult); }
public async void should_not_add_articles_to_db_when_articles_are_already_in_db() { var scrappedArticles = new ArticleBuilder().Build(10); ArticlesResponseViewModel scrappedArticlesResponse = new() { Articles = scrappedArticles }; List <ArticleDb> articlesInDb = scrappedArticles.Map(); List <Article> articlesToAdd = null; Action <object> mapArticlesToAdd = (list) => { articlesToAdd = list as List <Article>; }; List <ArticleDb> expectedResult = new(); _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); }
public async void should_return_summary_message() { int articlesCount = 5; string summaryMessage = string.Format(ApiResponses.ArticlesAddedAfterScrapping, articlesCount); List <string> expectedResult = new() { summaryMessage }; var scrappedArticles = new ArticleBuilder().Build(articlesCount); ArticlesResponseViewModel scrappedArticlesResponse = new() { Articles = scrappedArticles }; List <ArticleDb> articleInDb = new(); _pagesScrapperService.Setup(n => n.ScrapAll()).ReturnsAsync(scrappedArticlesResponse); _articlesRepository.Setup(n => n.Get(null, null, "")).Returns(articleInDb); _mapper.Setup(n => n.Map <List <ArticleDb> >(It.IsAny <List <Article> >())).Returns(scrappedArticles.Map()); var result = await _sut.Scrap(); result.Should().BeEquivalentTo(expectedResult); }