public async Task StoreAsync(AnalyzedSentence analyzedSentence) { var source = new Source() { Url = analyzedSentence.Source }; var sourceId = await _databaseAccess.EnsureExistAsync(source); var keyword = new Keyword() { Text = analyzedSentence.Keyword }; var keywordId = await _databaseAccess.EnsureExistAsync(keyword); var sentence = new Sentence() { KeywordId = keywordId, SourceId = sourceId, Text = analyzedSentence.Sentence, Positive = analyzedSentence.Positive, SourceArticleHeader = analyzedSentence.ArticleHeader, SourceArticleUrl = analyzedSentence.ArticleUrl, Received = DateTime.Now }; var result = await _databaseAccess.SaveSentenceAsync(sentence); if (result.saved) { _pipeline.SendToBot(analyzedSentence); } }
public void SendForStorage(AnalyzedSentence analyzedSentence) { _logger.LogInformation($"sending analyzed sentence: {analyzedSentence.Sentence} for storage"); var properties = channel.CreateBasicProperties(); properties.Persistent = true; var body = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(analyzedSentence)); channel.BasicPublish("", "storage_queue", properties, body); }
private AnalyzedSentence CreateAnalyzedSentence(Article article, string sentence, bool positive, string foundKeyword) { var analyzedSentence = new AnalyzedSentence() { Source = article.Source, ArticleHeader = article.Header, ArticleUrl = article.ArticleUrl, Positive = positive, Keyword = foundKeyword, Sentence = sentence }; return(analyzedSentence); }
public async void StoreAsync_makes_sure_keyword_and_sources_exists_before_saving_sentence() { var mockedDatabaseAccess = new Mock <IDatabaseAccess>(); var mockedLogger = new Mock <ILogger <StoreAnalyzedSentenceService> >(); mockedDatabaseAccess.Setup(db => db.EnsureExistAsync(It.IsAny <Source>())).ReturnsAsync(0); mockedDatabaseAccess.Setup(db => db.EnsureExistAsync(It.IsAny <Keyword>())).ReturnsAsync(0); mockedDatabaseAccess.Setup(db => db.SaveSentenceAsync(It.IsAny <Sentence>())).ReturnsAsync((sentenceId: 0, saved: true)); var service = new StoreAnalyzedSentenceService(mockedDatabaseAccess.Object, mockedLogger.Object); var sentence = new AnalyzedSentence(); await service.StoreAsync(sentence); mockedDatabaseAccess.Verify(db => db.EnsureExistAsync(It.IsAny <Source>()), Times.Exactly(1)); mockedDatabaseAccess.Verify(db => db.EnsureExistAsync(It.IsAny <Keyword>()), Times.Exactly(1)); mockedDatabaseAccess.Verify(db => db.SaveSentenceAsync(It.IsAny <Sentence>()), Times.Exactly(1)); }
private void SendForStorage(AnalyzedSentence analyzedSentence) { _logger.LogInformation($"sending the following sentence for storage: {analyzedSentence.Sentence}"); _pipeline.SendForStorage(analyzedSentence); }