コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
 private void SendForStorage(AnalyzedSentence analyzedSentence)
 {
     _logger.LogInformation($"sending the following sentence for storage: {analyzedSentence.Sentence}");
     _pipeline.SendForStorage(analyzedSentence);
 }