/// <summary> /// Saves the article /// </summary> /// <param name="article">Article container</param> /// <returns>Operation result</returns> public bool SaveArticle(ArticleContainer article) { _articleStorage[article.Guid] = article; _urlToGuidMap[article.Header.Link] = article.Guid; return true; }
/// <summary> /// Parses article from given Url /// </summary> /// <param name="article">Article container. Url is stored inside </param> /// <returns>Success indication flag</returns> public abstract bool ParseArticle(ArticleContainer article);
public void Init() { //Arrange var rssSourcesMock = new Mock<IRssSourcesProvider>(); rssSourcesMock.Setup(sourcesProvider => sourcesProvider.GetRssSources(It.IsAny<RssSources>())) .Returns(() => new RssSources { Sources = new List<RssSource> {_rssSource} }); _logo = File.ReadAllBytes("..\\..\\TestData\\logo.png"); _enclosure = File.ReadAllBytes("..\\..\\TestData\\enclosure.jpg"); _rssSource.Logo = _logo; _header1 = new NewsHeader { Guid = new Guid("10D93F92-B3E3-41F7-9E72-03A88883F6AD"), Description = "07/01 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...", HasEnclosure = true, HasLogo = true, Link = "http://lenta.ru/loren_ipsum_1", PublishDate = new DateTime(2015, 07, 01), Title = "Lorem ipsum 1", Source = "Lenta.ru", Enclosure = _enclosure }; _header2 = new NewsHeader { Guid = new Guid("51B06028-F579-40EE-860B-A74A498A9987"), Description = "07/02 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...", HasEnclosure = false, HasLogo = true, Link = "http://lenta.ru/loren_ipsum_2", PublishDate = new DateTime(2015, 07, 02), Title = "Lorem ipsum 2", Source = "Lenta.ru" }; var newsProviderMock = new Mock<INewsProvider>(); newsProviderMock.Setup(newsProvider => newsProvider.GetNews(It.IsAny<RssSources>(), 1, true)).Returns( new NewsHeaders { TotalArticlesCount = 2, Headers = new List<NewsHeader> {_header1, _header2} }); _article1 = new ArticleContainer { Guid = _header1.Guid, Header = _header1, RssSource = _rssSource, Body = new BodyContainer { HasPicture = true, Body = @"01.07.2015 12:00 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." } }; _article2 = new ArticleContainer { Guid = _header2.Guid, Header = _header2, RssSource = _rssSource, Body = new BodyContainer { HasPicture = false, Body = @"02.07.2015 12:00 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." } }; var contentStorageMock = new Mock<IContentStorage>(); contentStorageMock.Setup(contentStorage => contentStorage.SaveArticle(It.IsAny<ArticleContainer>())) .Returns(true); contentStorageMock.Setup(contentStorage => contentStorage.GetArticleByUrl("http://lenta.ru/loren_ipsum_1")) .Returns(() => { var task = new Task<ArticleContainer>(() => _article1); task.Start(); return task; }); contentStorageMock.Setup(contentStorage => contentStorage.GetArticleByUrl("http://lenta.ru/loren_ipsum_2")) .Returns(() => { var task = new Task<ArticleContainer>(() => _article2); task.Start(); return task; }); contentStorageMock.Setup(contentStorage => contentStorage.GetArticleByGuid(It.IsAny<Guid>())) .Returns((Guid guid) => { ArticleContainer article = null; if (guid == _header1.Guid) article = _article1; else if (guid == _header2.Guid) article = _article2; var task = new Task<ArticleContainer>(() => article); task.Start(); return task; }); contentStorageMock.Setup(contentStorage => contentStorage.GetArticlesBySource(It.IsAny<RssSource>())) .Returns(() => new List<ArticleContainer> {_article1, _article2}); var parserProviderMock = new Mock<IParserProvider>(); parserProviderMock.Setup(parserProvider => parserProvider.GetArticleBody(It.IsAny<Guid>())) .Returns((Guid guid) => { ArticleContainer article = null; if (guid == _header1.Guid) article = _article1; else if (guid == _header2.Guid) article = _article2; return article; }); _controller = new SourcesController(rssSourcesMock.Object, newsProviderMock.Object, contentStorageMock.Object, parserProviderMock.Object); }